Skip to content

Commit 0feeef6

Browse files
authored
Add missing click keywords (#64)
* Fix missing webkit wait for fading * Add skip verify after click * Add missing click link * Fix missing click link button and image keywords * Fix error missing default params * Update playwright to 0.152.0 * Fix parsing error
1 parent c5c8058 commit 0feeef6

File tree

10 files changed

+107
-18
lines changed

10 files changed

+107
-18
lines changed

Examples/form-handler/click-element.robot

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ ${DEFAULT_BROWSER} chrome
88

99

1010
*** Test Cases ***
11+
Click link
12+
Open browser to test page http://127.0.0.1:7272/basic-html-elements.html
13+
Click Link id=goto-login-page
14+
15+
Click Button
16+
Open browser to test page http://127.0.0.1:7272/basic-html-elements.html
17+
Click Button id=get_ajax
18+
19+
Click Image
20+
Open browser to test page http://127.0.0.1:7272/basic-html-elements.html
21+
Click Image id=gate
22+
1123
Click element at coordiator
1224
Open browser to test page http://127.0.0.1:7272/login-form-example.html
1325
Run Async Keywords
1426
... Wait For New Window Open AND
1527
... Click Element At Coordinate css=button[type="submit"] 1 1
1628

17-
1829
*** Keywords ***
1930
Open browser to test page
2031
[Arguments] ${url}

Examples/form-handler/form-submit.robot

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Test Teardown Close All Browser
44
Suite Teardown Close Puppeteer
55

66
*** Variables ***
7-
${DEFAULT_BROWSER} chrome
7+
${DEFAULT_BROWSER} webkit
88

99

1010
*** Test Cases ***
@@ -28,7 +28,18 @@ Submit register form
2828
Select From List By Value id=inputState 5
2929
Input Text id=inputZip 1234
3030
Click Element css=button[type="submit"]
31-
31+
32+
Webkit demo skip wait after click
33+
[Tags] Ignore
34+
Open browser to test page https://www.w3schools.com/html/html_forms.asp
35+
Wait Until Element Is Visible id=fname
36+
Input Text id=fname 123
37+
Input Text id=lname 321
38+
Run Async Keywords
39+
... Wait For New Window Open AND
40+
... Click Element xpath=(//input[@value="Submit"])[1] ${True}
41+
Switch Window NEW
42+
Wait Until Page Contains Submitted Form Data
3243

3344
*** Keywords ***
3445
Open browser to test page

PuppeteerLibrary/ikeywords/ielement_async.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ async def find_elements(self, locator: str):
1515
# Action
1616
##############################
1717
@abstractmethod
18-
async def click_element(self, locator: str):
18+
async def click_element(self, locator: str, noWaitAfter: str='False'):
19+
pass
20+
21+
@abstractmethod
22+
async def click_link(self, locator: str):
23+
pass
24+
25+
@abstractmethod
26+
async def click_button(self, locator: str):
27+
pass
28+
29+
@abstractmethod
30+
async def click_image(self, locator: str):
1931
pass
2032

2133
@abstractmethod

PuppeteerLibrary/keywords/element.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import NamedTuple, Optional
21
from PuppeteerLibrary.base.robotlibcore import keyword
32
from PuppeteerLibrary.base.librarycomponent import LibraryComponent
43
from PuppeteerLibrary.ikeywords.ielement_async import iElementAsync
@@ -16,14 +15,21 @@ def get_async_keyword_group(self) -> iElementAsync:
1615
# Action
1716
##############################
1817
@keyword
19-
def click_element(self, locator):
18+
def click_element(self, locator, noWaitAfter='False'):
2019
"""Clicks element identified by ``locator``.
2120
21+
The ``noWaitAfter`` argument specifies skip wait for animation after click.
22+
Only support for webkit and safari (Puppeteer)
23+
2224
Example:
2325
24-
| `Click Element` | id:register |
26+
| `Click Element` | id:register | |
27+
| `Click Element` | id:register | ${True} |
2528
"""
26-
self.loop.run_until_complete(self.get_async_keyword_group().click_element(locator))
29+
self.loop.run_until_complete(self.get_async_keyword_group().click_element(
30+
locator=locator,
31+
noWaitAfter=noWaitAfter
32+
))
2733

2834
@keyword
2935
def click_link(self, locator):

PuppeteerLibrary/playwright/async_keywords/playwright_element.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from PuppeteerLibrary.utils.coverter import str2bool
12
from robot.libraries.BuiltIn import BuiltIn
23
from PuppeteerLibrary.ikeywords.ielement_async import iElementAsync
34

@@ -16,15 +17,37 @@ async def find_elements(self, locator: str):
1617
##############################
1718
# Click
1819
##############################
19-
async def click_element(self, locator: str):
20-
return await self.library_ctx.get_current_page().click_with_selenium_locator(locator)
20+
async def click_element(self, locator: str, noWaitAfter: str='False'):
21+
noWaitAfter = str2bool(noWaitAfter)
22+
element = await self.library_ctx.get_current_page().querySelector_with_selenium_locator(locator)
23+
await element.click(
24+
noWaitAfter=noWaitAfter
25+
)
26+
27+
async def click_link(self, locator: str):
28+
await self._click_with_specific_tag(locator,'a')
29+
30+
async def click_button(self, locator: str):
31+
await self._click_with_specific_tag(locator,'button')
32+
33+
async def click_image(self, locator: str):
34+
await self._click_with_specific_tag(locator,'img')
35+
36+
async def _click_with_specific_tag(self, locator: str, expect_tag_name: str):
37+
elements = await self.library_ctx.get_current_page().querySelectorAll_with_selenium_locator(locator)
38+
for element in elements:
39+
tag_name = await (await element.getProperty('tagName')).jsonValue()
40+
if tag_name.lower() == expect_tag_name:
41+
return await element.click()
42+
raise Exception('Can\'t find the specific '+ expect_tag_name +' element for '+locator)
2143

2244
async def click_element_at_coordinate(self, locator: str, xoffset: str, yoffset: str):
2345
element = await self.library_ctx.get_current_page().querySelector_with_selenium_locator(locator)
24-
await element.click(position={
25-
'x': int(xoffset),
26-
'y': int(yoffset)
27-
})
46+
await element.click(
47+
position={
48+
'x': int(xoffset),
49+
'y': int(yoffset)
50+
})
2851

2952
async def upload_file(self, locator: str, file_path: str):
3053
element = await self.library_ctx.get_current_page().querySelector_with_selenium_locator(locator)

PuppeteerLibrary/playwright/async_keywords/playwright_waiting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async def validate_is_enabled():
117117
async def wait_until_element_finished_animating(self, locator, timeout=None):
118118
prev_rect_tmp = { 'value': None }
119119
async def check_finished_animating():
120+
await self.wait_until_element_is_visible(locator)
120121
element = await self.library_ctx.get_current_page().querySelector_with_selenium_locator(locator)
121122
if prev_rect_tmp['value'] is None:
122123
prev_rect_tmp['value'] = await element.boundingBox()

PuppeteerLibrary/puppeteer/async_keywords/puppeteer_element.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from PuppeteerLibrary.utils.coverter import str2bool
12
from typing import Optional
23
from robot.libraries.BuiltIn import BuiltIn
34
from PuppeteerLibrary.ikeywords.ielement_async import iElementAsync
@@ -17,8 +18,26 @@ async def find_elements(self, locator: str):
1718
##############################
1819
# Click
1920
##############################
20-
async def click_element(self, locator: str):
21-
return await self.library_ctx.get_current_page().click_with_selenium_locator(locator)
21+
async def click_element(self, locator: str, noWaitAfter: str='False'):
22+
element = await self.library_ctx.get_current_page().querySelector_with_selenium_locator(locator)
23+
await element.click()
24+
25+
async def click_link(self, locator: str):
26+
await self._click_with_specific_tag(locator,'a')
27+
28+
async def click_button(self, locator: str):
29+
await self._click_with_specific_tag(locator,'button')
30+
31+
async def click_image(self, locator: str):
32+
await self._click_with_specific_tag(locator,'img')
33+
34+
async def _click_with_specific_tag(self, locator: str, expect_tag_name: str):
35+
elements = await self.library_ctx.get_current_page().querySelectorAll_with_selenium_locator(locator)
36+
for element in elements:
37+
tag_name = await (await element.getProperty('tagName')).jsonValue()
38+
if tag_name.lower() == expect_tag_name:
39+
return await element.click()
40+
raise Exception('Can\'t find the specific '+ expect_tag_name +' element for '+locator)
2241

2342
async def click_element_at_coordinate(self, locator: str, xoffset: str, yoffset: str):
2443
element = await self.library_ctx.get_current_page().querySelector_with_selenium_locator(locator)

PuppeteerLibrary/utils/coverter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def str2bool(v):
2+
if v == True:
3+
return True
4+
elif v == False:
5+
return False
6+
return v.lower() in ("yes", "true", "1")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
versioneer>=0.18
22
robotframework>=3.2.1
3-
playwright==0.151.0
3+
playwright==0.152.0
44
# pyppeteer>=0.2.2
55
git+https://github.com/qahive/pyppeteer.git@dev2
66
robotframework-libdoc2json>=0.4

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
platforms='any',
4040
install_requires=[
4141
'robotframework>=3.2.1',
42-
'playwright>=0.151.0',
42+
'playwright>=0.152.0',
4343
'pyppeteer>=0.2.2',
4444
],
4545
# python_requires='>3.5',

0 commit comments

Comments
 (0)