Skip to content

Commit 855fd65

Browse files
atthaboondependabot[bot]
andauthoredSep 23, 2021
Support Playwright v15 and trace log (#130)
* Bump playwright from 1.11.1 to 1.15.0 Bumps [playwright](https://github.com/Microsoft/playwright-python) from 1.11.1 to 1.15.0. - [Release notes](https://github.com/Microsoft/playwright-python/releases) - [Commits](microsoft/playwright-python@v1.11.1...v1.15.0) --- updated-dependencies: - dependency-name: playwright dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Add missing playwright dependencies * Init support trace file * Update default browser for chrome * Update pythonpackage.yml * Update force tag Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: DESKTOP\atthaboon.s <[email protected]>
1 parent a1bfe69 commit 855fd65

File tree

13 files changed

+120
-14
lines changed

13 files changed

+120
-14
lines changed
 

‎.github/workflows/pythonpackage.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
# python-version: [3.7, 3.8, 3.9]
1313
include:
1414
- python-version: 3.7
15-
browser: pwchrome
15+
browser: chrome
1616
- python-version: 3.7
17-
browser: webkit
17+
browser: ptchrome
1818
- python-version: 3.8
19-
browser: chrome
19+
browser: webkit
2020
- python-version: 3.9
2121
browser: firefox
2222

@@ -73,6 +73,7 @@ jobs:
7373
pip install -r demoapp/requirements.txt
7474
pyppeteer-install
7575
python -m playwright install
76+
npx playwright install-deps
7677
python demoapp/server.py &
7778
- name: System test
7879
uses: GabrielBB/xvfb-action@v1

‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ Examples/logs/
2626
Examples/tmp-download/test.csv
2727
Examples;tmp-download/test.csv
2828
Examples/test.csv
29-
.venv/
29+
.venv/
30+
Examples/trace.zip
31+
Examples/traces/
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*** Settings ***
2+
Library PuppeteerLibrary
3+
Test Teardown Close All Browser
4+
Suite Teardown Close Puppeteer
5+
6+
*** Variables ***
7+
${DEFAULT_BROWSER} chrome
8+
9+
10+
*** Test Cases ***
11+
Tracing log without path
12+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
13+
Open browser to test page http://127.0.0.1:7272/login-form-example.html
14+
Run Keyword If '${BROWSER}' != 'ptchrome' Start tracing
15+
Select Checkbox id=exampleCheck1
16+
Checkbox Should Be Selected id=exampleCheck1
17+
Run Keyword If '${BROWSER}' != 'ptchrome' Stop Tracing
18+
19+
Tracing log with specific path
20+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
21+
Open browser to test page http://127.0.0.1:7272/login-form-example.html
22+
Run Keyword If '${BROWSER}' != 'ptchrome' Start tracing
23+
Select Checkbox id=exampleCheck1
24+
Checkbox Should Be Selected id=exampleCheck1
25+
Run Keyword If '${BROWSER}' != 'ptchrome' Stop Tracing trace2.zip
26+
27+
*** Keywords ***
28+
Open browser to test page
29+
[Arguments] ${url}
30+
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
31+
${HEADLESS} Get variable value ${HEADLESS} ${False}
32+
&{options} = create dictionary headless=${HEADLESS}
33+
Open browser ${url} browser=${BROWSER} options=${options}

‎Examples/form-handler/checkbox-element.robot

+1-1
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} pwchrome
88

99

1010
*** Test Cases ***

‎Examples/locator/chain-locator.robot

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
*** Settings ***
2-
Force Tags Ignore_chrome
2+
Force Tags Ignore_ptchrome
33
Library PuppeteerLibrary
44
Test Setup Open browser to test page
55
Test Teardown Close All Browser
66
Suite Teardown Close Puppeteer
77

88
*** Variables ***
9-
${DEFAULT_BROWSER} pwchrome
9+
${DEFAULT_BROWSER} chrome
1010
${HOME_PAGE_URL} http://127.0.0.1:7272/register-form-example.html
1111

1212

‎PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ async def wait_for_new_window_open(self, timeout=None):
2828
async def switch_window(self, locator='MAIN'):
2929
pass
3030

31+
##############################
32+
# Trace
33+
##############################
34+
@abstractmethod
35+
async def start_tracing(self):
36+
pass
37+
38+
@abstractmethod
39+
async def stop_tracing(self, path=None):
40+
pass
41+
3142
##############################
3243
# Page
3344
##############################

‎PuppeteerLibrary/keywords/browsermanagement.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from PuppeteerLibrary.base.librarycomponent import LibraryComponent
22
from PuppeteerLibrary.base.robotlibcore import keyword
33
from PuppeteerLibrary.ikeywords.ibrowsermanagement_async import iBrowserManagementAsync
4+
from robot.libraries.BuiltIn import BuiltIn
45

56

67
class BrowserManagementKeywords(LibraryComponent):
@@ -18,8 +19,9 @@ def open_browser(self, url, browser="chrome", alias=None, options={}):
1819
The ``browser`` argument specifies which browser to use.
1920
2021
| = Browser = | = Name(s) = | = Engine = |
21-
| Google Chrome | chrome | Puppeteer |
22+
| Google Chrome Default | chrome | Playwright |
2223
| Google Chrome Playwright | pwchrome | Playwright |
24+
| Google Chrome Puppeteer | ptchrome | Puppeteer |
2325
| Webkit (Safari engine) | webkit | Playwright |
2426
| Firefox | firefox | Playwright |
2527
@@ -162,6 +164,30 @@ def enable_emulate_mode(self, emulate_name):
162164
"""
163165
return self.loop.run_until_complete(self.get_async_keyword_group().enable_emulate_mode_async(emulate_name))
164166

167+
##############################
168+
# Trace
169+
##############################
170+
@keyword
171+
def start_tracing(self):
172+
"""Create trace log file
173+
174+
# View the trace by running following command
175+
176+
playwright show-trace trace.zip
177+
"""
178+
return self.loop.run_until_complete(self.get_async_keyword_group().start_tracing())
179+
180+
@keyword
181+
def stop_tracing(self, path=None):
182+
"""Stop trace and generate the trace file.
183+
184+
Default will be ``traces/<testcasename>.zip``
185+
"""
186+
if path is None:
187+
test_name = BuiltIn().get_variable_value("${TEST_NAME}")
188+
path = 'traces/'+test_name+'.zip'
189+
return self.loop.run_until_complete(self.get_async_keyword_group().stop_tracing(path))
190+
165191
##############################
166192
# Page
167193
##############################

‎PuppeteerLibrary/library_context/library_context_factory.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ class LibraryContextFactory:
77
def create(self, browser_type: str) -> iLibraryContext:
88
"""Return iLibraryContext based on specific browser_type
99
10-
Create context based on browser type (chrome, pwchrome, safari, webkit)
10+
Create context based on browser type (chrome, pwchrome, ptchrome, safari, webkit)
1111
"""
1212
if browser_type.lower() == 'chrome':
13-
return PuppeteerContext(browser_type)
14-
if browser_type.lower() == 'pwchrome':
1513
return PlaywrightContext(browser_type)
14+
elif browser_type.lower() == 'pwchrome':
15+
return PlaywrightContext(browser_type)
16+
elif browser_type.lower() == 'ptchrome':
17+
return PuppeteerContext(browser_type)
1618
elif browser_type.lower() == 'safari':
1719
return PlaywrightContext(browser_type)
1820
elif browser_type.lower() == 'webkit':

‎PuppeteerLibrary/playwright/async_keywords/playwright_browsermanagement.py

+11
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ async def switch_window(self, locator='MAIN'):
7979
raise Exception('Sorry Switch window support only NEW, MAIN, title and url')
8080
raise Exception('Can\'t find specify page locator.')
8181

82+
##############################
83+
# Trace
84+
##############################
85+
async def start_tracing(self):
86+
await self.library_ctx.start_tracing()
87+
88+
async def stop_tracing(self, path=None):
89+
if path is None:
90+
path = 'trace.zip'
91+
await self.library_ctx.stop_tracing(path)
92+
8293
##############################
8394
# Page
8495
##############################

‎PuppeteerLibrary/playwright/playwright_context.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PlaywrightContext(iLibraryContext):
2828

2929
playwright: any = None
3030
browser: any = None
31+
current_context: any = None
3132
current_page: any = None
3233
current_iframe = None
3334

@@ -63,7 +64,7 @@ async def start_server(self, options: dict={}):
6364
if self.playwright is None:
6465
self.playwright = await async_playwright().start()
6566

66-
if self.browser_type == "pwchrome":
67+
if self.browser_type == "chrome" or self.browser_type == "pwchrome":
6768
self.browser = await self.playwright.chromium.launch(
6869
headless=merged_options['headless'])
6970
elif self.browser_type == "webkit":
@@ -73,6 +74,7 @@ async def start_server(self, options: dict={}):
7374
self.browser = await self.playwright.firefox.launch(
7475
headless=merged_options['headless'])
7576
self.browser.accept_downloads = True
77+
# self.current_context = await self.browser.new_context()
7678

7779
async def stop_server(self):
7880
await self.playwright.stop()
@@ -155,8 +157,17 @@ def get_async_keyword_group(self, keyword_group_name: str):
155157
}
156158
return switcher.get(keyword_group_name)
157159

160+
async def start_tracing(self):
161+
if len(self.browser.contexts) > 0:
162+
await self.browser.contexts[0].tracing.start(screenshots=True, snapshots=True)
163+
164+
async def stop_tracing(self, path):
165+
if len(self.browser.contexts) > 0:
166+
await self.browser.contexts[0].tracing.stop(path=path)
167+
158168
def _reset_context(self):
159169
self.browser = None
170+
self.current_context = None
160171
self.current_page = None
161172
self.current_iframe = None
162173

‎PuppeteerLibrary/puppeteer/async_keywords/puppeteer_browsermanagement.py

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ async def switch_window(self, locator='MAIN'):
8888
raise Exception('Sorry Switch window support only NEW, MAIN, title and url')
8989
raise Exception('Can\'t find specify page locator.')
9090

91+
##############################
92+
# Trace
93+
##############################
94+
async def start_tracing(self):
95+
raise Exception('Not support')
96+
97+
async def stop_tracing(self, path=None):
98+
raise Exception('Not support')
99+
91100
##############################
92101
# Page
93102
##############################

‎requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
versioneer>=0.18
22
robotframework>=3.2.1
3-
playwright==1.11.1
3+
playwright==1.15.0
44
pyppeteer==0.2.5
55
# git+https://github.com/qahive/pyppeteer.git@dev2
66
robotframework-libdoc2json>=0.4

‎setup.py

+1-1
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==1.11.1',
42+
'playwright==1.15.0',
4343
'pyppeteer==0.2.5',
4444
],
4545
python_requires='>3.6',

0 commit comments

Comments
 (0)
Please sign in to comment.