Skip to content

Commit

Permalink
Topic/click (#471)
Browse files Browse the repository at this point in the history
* refactored Mouse Button to click without coordinates.

* refactored Mouse Button to click without coordinates.
  • Loading branch information
Snooz82 authored Nov 1, 2020
1 parent 7a01445 commit a0bde4a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 44 deletions.
62 changes: 24 additions & 38 deletions Browser/keywords/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import json
from datetime import timedelta
from pathlib import Path
from time import sleep
from typing import Any, Dict, Optional

from robotlibcore import keyword # type: ignore
Expand Down Expand Up @@ -271,7 +272,7 @@ def hover(
- Scroll the element into view if needed.
- Use `Mouse Move` to hover over the center of the element, or the specified ``position``.
``selector`` Selector element to click.
``selector`` Selector element to hover.
See the `Finding elements` section for details about the selectors.
``position_x`` & ``position_y`` A point to hover relative to the top-left corner of element bounding box.
Expand Down Expand Up @@ -543,54 +544,39 @@ def mouse_button(
clickCount: int = 1,
delay: int = 0,
):
"""Click, hold a mouse button down or release it.
"""Clicks, presses or releases a mouse button.
Moving the mouse between holding down and releasing it for example is possible with `Mouse Move`.
``action`` Determines if it is a mouseclick, holding down a key or releasing it.
``x`` and ``y`` Coordinates for a click only. Defaults to None.
**Required** if action is a click.
``x`` and ``y`` Coordinates to move before.
``button`` Defaults to ``left`` if invalid.
``button`` Defaults to ``left``.
``clickCount`` Determine how often shall be clicked. Defaults to 1.
``clickCount`` Deterine how often shall be clicked. Defaults to 1.
``delay`` Delay in ms between the mousedown and mouseup event.
Can only be set if the action is click.
``delay`` Delay in ms between the mousedown and mouseup event. Can only be set if the action is click.
Moving the mouse between holding down and releasing it, is possible with `Mouse Move`.
"""
with self.playwright.grpc_channel() as stub:
body: MouseOptionsDict = {}
if delay and action is not MouseButtonAction.click:
raise ValueError("Delay is only valid on 'click' action.")
if x and y:
self.mouse_move(x, y)
else:
logger.info(
"No coordinates where set. Action appears at current position."
)
if action == MouseButtonAction.click:
body = {}
if x and y:
body["x"] = float(x)
body["y"] = float(y)
else:
raise ValueError(
f"`Mouse Button Click` requires that x and y are set! x: {x}, y: {y}"
)
body["options"] = {
"button": button.name,
"clickCount": clickCount,
"delay": delay,
}
for i in range(clickCount):
self.mouse_button(MouseButtonAction.down, button=button)
sleep(delay / 1000)
self.mouse_button(MouseButtonAction.up, button=button)
return
else:
if x and y:
self.mouse_move(x, y)
else:
logger.info(
f"No coordinates where set. Action will appear at current position. x: {x}, y {y}"
)
body = {
"options": {
"button": button.name,
"clickCount": clickCount,
"delay": delay,
}
}

if delay:
raise ValueError("Delay is only valid on 'click' action.")
body = {"options": {"button": button.name, "clickCount": clickCount}}
response = stub.MouseButton(
Request().MouseButtonOptions(action=action.name, json=json.dumps(body))
)
Expand Down
5 changes: 0 additions & 5 deletions atest/test/01_Browser_Management/device_descriptors.robot
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,3 @@ Descriptor Properly sets context settings
New Page
Get Viewport Size ALL == { "width": 360 , "height": 640 }
Verify Browser Type chromium

*** Keywords ***
Verify Browser Type
[Arguments] ${expectedType}
Get Browser Catalog validate value[0]['type'] == $expectedType
8 changes: 8 additions & 0 deletions atest/test/01_Browser_Management/playwright_state.robot
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,11 @@ Closing Page/Contex/Browser Multiple Times With All Should Not Cause Errors
Close Context ALL ALL
Close Browser ALL
Close Browser ALL

New Context with defaultBrowserType ff
New Context defaultBrowserType=firefox
Verify Browser Type firefox

New Context with defaultBrowserType chromium
New Context defaultBrowserType=chromium
Verify Browser Type chromium
18 changes: 17 additions & 1 deletion atest/test/02_Content_Keywords/solve_draggame.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@ Resource imports.resource
Test Setup New Page ${DRAGGAME_URL}

*** Test Cases ***
Move obstacle away and make a goal
Move obstacle to goal and make a goal
Get text h2 == Put the circle in the goal
Drag And Drop css=.obstacle css=.goal
Drag And Drop css=.circle css=.goal
Get text h2 == GOAL!!

Move Obstacle away and drag and Drop
Hover "Obstacle"
Mouse Button down
Mouse Move Relative To "Obstacle" 500
Mouse Button up
Drag And Drop "Circle" "Goal"

Test
[Setup] New Page
FOR ${i} IN RANGE 20
Go To ${SHELLGAME_URL}
Mouse Move Relative To id=indicator -100
Mouse Button click
Get Text h1 == CORRECT :D
END
4 changes: 4 additions & 0 deletions atest/test/keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ Submit Credentials
Welcome Page Should Be Open
Get Url == ${WELCOME_URL}
Get Title == Welcome Page

Verify Browser Type
[Arguments] ${expectedType}
Get Browser Catalog validate value[0]['type'] == $expectedType
1 change: 1 addition & 0 deletions atest/test/variables.resource
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ${VALID_PASSWORD} mode
${ROOT_URL} http://${SERVER}
${LOGIN_URL} ${ROOT_URL}/dist/#/
${DRAGGAME_URL} ${ROOT_URL}/dist/#/draggame
${SHELLGAME_URL} ${ROOT_URL}/shell_game.html
${FORM_URL} ${ROOT_URL}/prefilled_email_form.html
${DIALOGS_URL} ${ROOT_URL}/dialogs.html
${ELEMENT_STATE_URL} ${ROOT_URL}/enabled_disabled_fields_form.html
Expand Down

0 comments on commit a0bde4a

Please sign in to comment.