Skip to content

Commit 6f9bb93

Browse files
Support playwright 1.21 (#163)
* Bump playwright from 1.17.2 to 1.21.0 Bumps [playwright](https://github.com/Microsoft/playwright-python) from 1.17.2 to 1.21.0. - [Release notes](https://github.com/Microsoft/playwright-python/releases) - [Commits](microsoft/playwright-python@v1.17.2...v1.21.0) --- updated-dependencies: - dependency-name: playwright dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update lib version * Fix lib version * Test clean up * Fix webkit * Fix support ptchrome * Clean up * Clean up error msg Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Atthaboon Sanurt <atthaboon.s@qahive.com>
1 parent 11eb627 commit 6f9bb93

File tree

8 files changed

+64
-55
lines changed

8 files changed

+64
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ Examples/traces/
3232
Examples/state-admin.json
3333
Examples/test-report/
3434
test-report/
35+
puppeteer-screenshot-.*.png
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,60 @@
11
*** Settings ***
2-
Library PuppeteerLibrary
3-
Test Setup Open browser to test page
4-
Test Teardown Close All Browser
2+
Library PuppeteerLibrary
3+
Test Setup Open browser to test page
4+
Test Teardown Close All Browser
55
Suite Teardown Close Puppeteer
66

77
*** Variables ***
88
${DEFAULT_BROWSER} chrome
99
${HOME_PAGE_URL} http://127.0.0.1:7272/basic-html-elements.html
1010

11-
1211
*** Test Cases ***
1312
Count elements
1413
${No of h2} = Get Element Count css=h2
1514
Should Be Equal As Numbers 14 ${No of h2}
16-
15+
1716
Count non existing element
1817
Set Timeout 1s
1918
${No of h2} = Get Element Count css=Hnotexisting
2019
Should Be Equal As Numbers 0 ${No of h2}
2120

2221
Get element attribute
23-
${type value} = Get Element Attribute id=alert_confirm type
22+
${type value} = Get Element Attribute id=alert_confirm type
2423
Should Be Equal As Strings button ${type value}
2524

2625
Element proprty is enable
2726
Element Should Be Enabled id:prop-enable
2827

2928
Element property is disable
3029
Element Should Be Disabled id:prop-disable
31-
Run Keyword And Expect Error REGEXP:Element 'id:prop-enable' is enabled Element Should Be Disabled id:prop-enable
32-
30+
Run Keyword And Expect Error REGEXP:.*'id:prop-enable' is enabled.* Element Should Be Disabled id:prop-enable
31+
3332
Element is visible and not visible
3433
[Tags] Ignore_firefox
3534
#TODO Need to recheck why firefox unstable
3635
Element Should Be Visible id:prop-visible
3736
Element Should Not Be Visible id:prop-hide
38-
Run Keyword And Expect Error REGEXP:Element 'id:prop-hide' is not be visible Element Should Be Visible id:prop-hide
37+
Run Keyword And Expect Error REGEXP:.*is not be visible.* Element Should Be Visible id:prop-hide
3938

4039
Get Element Text
41-
${text} = Get Text id=prop-text
40+
${text} = Get Text id=prop-text
4241
Should Contain ${text} Please
4342

4443
Element should containt text
4544
Element Should Contain id=prop-text Please ${True}
46-
45+
4746
Element should not contain text
4847
Element Should Not Contain id=prop-text Please input2 ${True}
49-
48+
5049
Element text should be
51-
Element Text Should Be id=prop-text Please input ${True}
52-
50+
Element Text Should Be id=prop-text Please input ${True}
51+
5352
Element text should not be
54-
Element Text Should Not Be id=prop-text Please ${True}
53+
Element Text Should Not Be id=prop-text Please ${True}
5554

5655
*** Keywords ***
5756
Open browser to test page
58-
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
59-
${HEADLESS} Get variable value ${HEADLESS} ${False}
60-
&{options} = create dictionary headless=${HEADLESS}
61-
Open browser ${HOME_PAGE_URL} browser=${BROWSER} options=${options}
57+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
58+
${HEADLESS} Get variable value ${HEADLESS} ${False}
59+
&{options} = create dictionary headless=${HEADLESS}
60+
Open browser ${HOME_PAGE_URL} browser=${BROWSER} options=${options}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
*** Settings ***
2-
Library PuppeteerLibrary
3-
Test Setup Open browser to test page
4-
Test Teardown Close All Browser
2+
Library PuppeteerLibrary
3+
Test Setup Open browser to test page
4+
Test Teardown Close All Browser
55
Suite Teardown Close Puppeteer
66

7-
87
*** Variables ***
98
${DEFAULT_BROWSER} chrome
109
${HOME_PAGE_URL} http://127.0.0.1:7272/basic-html-elements.html
1110

12-
1311
*** Test Cases ***
1412
No node found when click
15-
Run Keyword And Expect Error REGEXP:.* Click Element id:login_button_error
13+
Set Timeout 2s
14+
Run Keyword And Expect Error * Click Element id:login_button_error
1615

1716
Test log error for sync keywords
1817
Run Keyword And Ignore Error Click Element id:login_button_error
1918

2019
Test log error for async keywords
21-
Run Keyword And Ignore Error Run Async Keywords
20+
Run Keyword And Ignore Error Run Async Keywords
2221
... Click Element id:login_button_error AND
2322
... Click Element id:login_button_2
2423

25-
2624
*** Keywords ***
2725
Open browser to test page
28-
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
26+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
2927
${HEADLESS} = Get variable value ${HEADLESS} ${True}
30-
&{options} = create dictionary headless=${HEADLESS}
28+
&{options} = create dictionary headless=${HEADLESS}
3129
Open browser ${HOME_PAGE_URL} browser=${BROWSER} options=${options}

PuppeteerLibrary/keywords/element.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def click_element(self, locator, noWaitAfter='False'):
2828
"""
2929
self.info(f"Clicking element '{locator}'.")
3030
self.loop.run_until_complete(self.get_async_keyword_group().click_element(
31-
locator=locator,
31+
locator=locator,
3232
noWaitAfter=noWaitAfter
3333
))
3434

@@ -52,7 +52,8 @@ def click_button(self, locator):
5252
| `Click Button` | id:submit |
5353
"""
5454
self.info(f"Clicking button '{locator}'.")
55-
self.loop.run_until_complete(self.get_async_keyword_group().click_button(locator))
55+
self.loop.run_until_complete(
56+
self.get_async_keyword_group().click_button(locator))
5657

5758
@keyword
5859
def click_image(self, locator):
@@ -63,22 +64,25 @@ def click_image(self, locator):
6364
| `Click Image` | id:cat_image |
6465
"""
6566
self.info(f"Clicking image '{locator}'.")
66-
self.loop.run_until_complete(self.get_async_keyword_group().click_image(locator))
67+
self.loop.run_until_complete(
68+
self.get_async_keyword_group().click_image(locator))
6769

6870
@keyword
6971
def click_element_at_coordinate(self, locator, xoffset, yoffset):
7072
""" Click element at specifict coordiate x and y offset
7173
"""
72-
self.info(f"Clicking element at coordinate '{locator}' at xoffset: '{xoffset}', yoffset: '{yoffset}'.")
73-
self.loop.run_until_complete(self.get_async_keyword_group().click_element_at_coordinate(locator, xoffset, yoffset))
74+
self.info(
75+
f"Clicking element at coordinate '{locator}' at xoffset: '{xoffset}', yoffset: '{yoffset}'.")
76+
self.loop.run_until_complete(self.get_async_keyword_group(
77+
).click_element_at_coordinate(locator, xoffset, yoffset))
7478

7579
@keyword
7680
def upload_file(self, locator, file_path):
7781
""" Upload file
7882
"""
7983
return self.loop.run_until_complete(self.get_async_keyword_group().upload_file(locator, file_path))
8084

81-
@keyword
85+
@keyword
8286
def press_keys(self, locator, *keys):
8387
""" Press Keys
8488
@@ -129,10 +133,10 @@ def element_should_not_be_visible(self, locator):
129133
"""
130134
return self.loop.run_until_complete(self.get_async_keyword_group().element_should_not_be_visible(locator))
131135

132-
133136
##############################
134137
# Property
135138
##############################
139+
136140
@keyword
137141
def get_text(self, locator):
138142
"""Returns text value of element identified by ``locator``.
@@ -191,7 +195,7 @@ def element_text_should_not_be(self, locator, expected, ignore_case=False):
191195
# Query Element
192196
##############################
193197
@keyword
194-
def get_element_count(self, locator):
198+
def get_element_count(self, locator, timeout=None):
195199
""" Returns the number of elements matching ``locator``.
196200
"""
197201
try:

PuppeteerLibrary/keywords/utility.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,33 @@ def set_timeout(self, timeout):
2020
See the Timeout section above for more information.
2121
2222
Example:
23-
23+
2424
| Open page that loads slowly | | |
2525
| Set Timeout | ${orig timeout} | |
2626
2727
"""
2828
orig_timeout = self.ctx.timeout
29-
self.ctx.get_current_library_context().set_default_timeout(timestr_to_secs(timeout))
29+
if self.ctx.get_current_library_context().browser_type.lower() == 'ptchrome':
30+
self.ctx.get_current_library_context().set_default_timeout(timestr_to_secs(timeout))
31+
else:
32+
self.loop.run_until_complete(
33+
self.ctx.get_current_library_context().set_default_timeout(timestr_to_secs(timeout))
34+
)
3035
self.info('Original timeout is ' + str(orig_timeout) + ' seconds')
3136
return orig_timeout
3237

3338
@keyword
3439
def run_async_keywords_and_return_first_completed(self, *keywords):
3540
"""Executes all the given keywords in a asynchronous and wait until first keyword is completed
36-
41+
3742
``Return`` Array of result for each keywords based on index
3843
3944
Example
4045
| `Run Async Keywords And Return First Completed` | Wait for response url | ${HOME_PAGE_URL}/login.html | AND |
4146
| ... | Wait for response url | ${HOME_PAGE_URL}/home.html | |
4247
"""
4348
run_keyword = _RunKeyword()
44-
return self.loop.run_until_complete( self._run_async_keywords_first_completed(run_keyword._split_run_keywords(list(keywords))) )
49+
return self.loop.run_until_complete(self._run_async_keywords_first_completed(run_keyword._split_run_keywords(list(keywords))))
4550

4651
@keyword
4752
def run_async_keywords(self, *keywords):
@@ -56,7 +61,7 @@ def run_async_keywords(self, *keywords):
5661
5762
"""
5863
run_keyword = _RunKeyword()
59-
return self.loop.run_until_complete( self._run_async_keywords(run_keyword._split_run_keywords(list(keywords))) )
64+
return self.loop.run_until_complete(self._run_async_keywords(run_keyword._split_run_keywords(list(keywords))))
6065

6166
@keyword
6267
def enable_debug_mode(self, slowMo=150, devtools=True):
@@ -89,11 +94,12 @@ async def disable_debug_mode_async():
8994
self.ctx.debug_mode = False
9095
self.ctx.clear_browser()
9196

92-
async def _run_async_keywords(self, iterable):
97+
async def _run_async_keywords(self, iterable):
9398
statements = []
9499
for kw, args in iterable:
95100
kw_name = kw.lower().replace(' ', '_')
96-
async_keywords = self.ctx.keywords[kw_name].__self__.get_async_keyword_group()
101+
async_keywords = self.ctx.keywords[kw_name].__self__.get_async_keyword_group(
102+
)
97103
statements.append(getattr(async_keywords, kw_name)(*args))
98104
try:
99105
return await asyncio.gather(*statements)
@@ -105,8 +111,10 @@ async def _run_async_keywords_first_completed(self, iterable):
105111
index = 0
106112
for kw, args in iterable:
107113
kw_name = kw.lower().replace(' ', '_')
108-
async_keywords = self.ctx.keywords[kw_name].__self__.get_async_keyword_group()
109-
org_statements.append(self._wrapped_async_keyword_return_index(index, getattr(async_keywords, kw_name)(*args) ))
114+
async_keywords = self.ctx.keywords[kw_name].__self__.get_async_keyword_group(
115+
)
116+
org_statements.append(self._wrapped_async_keyword_return_index(
117+
index, getattr(async_keywords, kw_name)(*args)))
110118
index += 1
111119
statements = org_statements
112120
error_stack_trace = ''
@@ -128,9 +136,9 @@ async def _run_async_keywords_first_completed(self, iterable):
128136
error_stack_trace += str(e)+'\n'
129137
continue
130138
if len(pending) == 0:
131-
raise Exception("All async keywords failed \r\n"+ error_stack_trace)
139+
raise Exception(
140+
"All async keywords failed \r\n" + error_stack_trace)
132141

133142
async def _wrapped_async_keyword_return_index(self, index, future):
134143
await future
135144
return index
136-

PuppeteerLibrary/playwright/playwright_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def is_server_started(self) -> bool:
9393
return True
9494
return False
9595

96-
def set_default_timeout(self, timeout):
96+
async def set_default_timeout(self, timeout):
9797
self.timeout = timeout
9898
self.get_current_page().get_page().set_default_timeout(timeout * 1000)
9999

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
versioneer>=0.18
22
robotframework>=3.2.1
3-
playwright==1.17.2
4-
pyppeteer==0.2.6
5-
# git+https://github.com/qahive/pyppeteer.git@dev2
3+
playwright==1.21.0
4+
pyppeteer==1.0.2
65
robotframework-libdoc2json>=0.4

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import versioneer
12
import re
23
from os.path import abspath, dirname, join
34
from setuptools import setup, find_packages
@@ -9,7 +10,6 @@
910

1011
# Get the version from the _version.py versioneer file. For a git checkout,
1112
# this is computed based on the number of commits since the last tag.
12-
import versioneer
1313
VERSION = str(versioneer.get_versions()['version']).split('+')[0]
1414
del versioneer.get_versions
1515

@@ -39,8 +39,8 @@
3939
platforms='any',
4040
install_requires=[
4141
'robotframework>=3.2.1',
42-
'playwright==1.17.2',
43-
'pyppeteer==0.2.6',
42+
'playwright==1.21.0',
43+
'pyppeteer==1.0.2',
4444
],
4545
python_requires='>3.6',
4646
# test_suite='nose.collector',

0 commit comments

Comments
 (0)