From 2c7bae36cd816a2454072a215c5d511e9262e151 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Sep 2021 07:10:04 +0000 Subject: [PATCH 1/6] 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](https://github.com/Microsoft/playwright-python/compare/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] --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 31c0d9b..0cc4040 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ versioneer>=0.18 robotframework>=3.2.1 -playwright==1.11.1 +playwright==1.15.0 pyppeteer==0.2.5 # git+https://github.com/qahive/pyppeteer.git@dev2 robotframework-libdoc2json>=0.4 diff --git a/setup.py b/setup.py index b10f6ab..5abbfc9 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ platforms='any', install_requires=[ 'robotframework>=3.2.1', - 'playwright==1.11.1', + 'playwright==1.15.0', 'pyppeteer==0.2.5', ], python_requires='>3.6', From 2c6d73220226cef3e16e649ef8b9af13be72cd40 Mon Sep 17 00:00:00 2001 From: "Atthaboon Sanurt (P'Art)" Date: Wed, 22 Sep 2021 21:10:19 +0700 Subject: [PATCH 2/6] Add missing playwright dependencies --- .github/workflows/pythonpackage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 7b9ff22..d882f9e 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -73,6 +73,7 @@ jobs: pip install -r demoapp/requirements.txt pyppeteer-install python -m playwright install + npx playwright install-deps python demoapp/server.py & - name: System test uses: GabrielBB/xvfb-action@v1 From e431333fde2b1f3ffc3956934969d53bf2abc3f7 Mon Sep 17 00:00:00 2001 From: "DESKTOP\\atthaboon.s" Date: Wed, 22 Sep 2021 22:25:48 +0700 Subject: [PATCH 3/6] Init support trace file --- .gitignore | 3 ++- Examples/browser-management/tracing.robot | 24 +++++++++++++++++++ Examples/form-handler/checkbox-element.robot | 2 +- .../ikeywords/ibrowsermanagement_async.py | 11 +++++++++ .../keywords/browsermanagement.py | 11 +++++++++ .../playwright_browsermanagement.py | 11 +++++++++ .../playwright/playwright_context.py | 11 +++++++++ .../puppeteer_browsermanagement.py | 9 +++++++ 8 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 Examples/browser-management/tracing.robot diff --git a/.gitignore b/.gitignore index 34b85f1..2816e60 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ Examples/logs/ Examples/tmp-download/test.csv Examples;tmp-download/test.csv Examples/test.csv -.venv/ \ No newline at end of file +.venv/ +Examples/trace.zip diff --git a/Examples/browser-management/tracing.robot b/Examples/browser-management/tracing.robot new file mode 100644 index 0000000..1a2eff1 --- /dev/null +++ b/Examples/browser-management/tracing.robot @@ -0,0 +1,24 @@ +*** Settings *** +Library PuppeteerLibrary +Test Teardown Close All Browser +Suite Teardown Close Puppeteer + +*** Variables *** +${DEFAULT_BROWSER} pwchrome + + +*** Test Cases *** +Tracing log without path + Open browser to test page http://127.0.0.1:7272/login-form-example.html + Start tracing + Select Checkbox id=exampleCheck1 + Checkbox Should Be Selected id=exampleCheck1 + Stop Tracing + +*** Keywords *** +Open browser to test page + [Arguments] ${url} + ${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER} + ${HEADLESS} Get variable value ${HEADLESS} ${False} + &{options} = create dictionary headless=${HEADLESS} + Open browser ${url} browser=${BROWSER} options=${options} diff --git a/Examples/form-handler/checkbox-element.robot b/Examples/form-handler/checkbox-element.robot index b989dbb..c5cbec7 100644 --- a/Examples/form-handler/checkbox-element.robot +++ b/Examples/form-handler/checkbox-element.robot @@ -4,7 +4,7 @@ Test Teardown Close All Browser Suite Teardown Close Puppeteer *** Variables *** -${DEFAULT_BROWSER} chrome +${DEFAULT_BROWSER} pwchrome *** Test Cases *** diff --git a/PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py b/PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py index fa343cc..f7cb986 100644 --- a/PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py +++ b/PuppeteerLibrary/ikeywords/ibrowsermanagement_async.py @@ -28,6 +28,17 @@ async def wait_for_new_window_open(self, timeout=None): async def switch_window(self, locator='MAIN'): pass + ############################## + # Trace + ############################## + @abstractmethod + async def start_tracing(self): + pass + + @abstractmethod + async def stop_tracing(self, path=None): + pass + ############################## # Page ############################## diff --git a/PuppeteerLibrary/keywords/browsermanagement.py b/PuppeteerLibrary/keywords/browsermanagement.py index 1bc9871..743fc8f 100644 --- a/PuppeteerLibrary/keywords/browsermanagement.py +++ b/PuppeteerLibrary/keywords/browsermanagement.py @@ -162,6 +162,17 @@ def enable_emulate_mode(self, emulate_name): """ return self.loop.run_until_complete(self.get_async_keyword_group().enable_emulate_mode_async(emulate_name)) + ############################## + # Trace + ############################## + @keyword + def start_tracing(self): + return self.loop.run_until_complete(self.get_async_keyword_group().start_tracing()) + + @keyword + def stop_tracing(self, path=None): + return self.loop.run_until_complete(self.get_async_keyword_group().stop_tracing(path)) + ############################## # Page ############################## diff --git a/PuppeteerLibrary/playwright/async_keywords/playwright_browsermanagement.py b/PuppeteerLibrary/playwright/async_keywords/playwright_browsermanagement.py index 80d932a..de39970 100644 --- a/PuppeteerLibrary/playwright/async_keywords/playwright_browsermanagement.py +++ b/PuppeteerLibrary/playwright/async_keywords/playwright_browsermanagement.py @@ -79,6 +79,17 @@ async def switch_window(self, locator='MAIN'): raise Exception('Sorry Switch window support only NEW, MAIN, title and url') raise Exception('Can\'t find specify page locator.') + ############################## + # Trace + ############################## + async def start_tracing(self): + await self.library_ctx.start_tracing() + + async def stop_tracing(self, path=None): + if path is None: + path = 'trace.zip' + await self.library_ctx.stop_tracing(path) + ############################## # Page ############################## diff --git a/PuppeteerLibrary/playwright/playwright_context.py b/PuppeteerLibrary/playwright/playwright_context.py index dff06fb..fe1314b 100644 --- a/PuppeteerLibrary/playwright/playwright_context.py +++ b/PuppeteerLibrary/playwright/playwright_context.py @@ -28,6 +28,7 @@ class PlaywrightContext(iLibraryContext): playwright: any = None browser: any = None + current_context: any = None current_page: any = None current_iframe = None @@ -73,6 +74,7 @@ async def start_server(self, options: dict={}): self.browser = await self.playwright.firefox.launch( headless=merged_options['headless']) self.browser.accept_downloads = True + # self.current_context = await self.browser.new_context() async def stop_server(self): await self.playwright.stop() @@ -155,8 +157,17 @@ def get_async_keyword_group(self, keyword_group_name: str): } return switcher.get(keyword_group_name) + async def start_tracing(self): + if len(self.browser.contexts) > 0: + await self.browser.contexts[0].tracing.start(screenshots=True, snapshots=True) + + async def stop_tracing(self, path): + if len(self.browser.contexts) > 0: + await self.browser.contexts[0].tracing.stop(path=path) + def _reset_context(self): self.browser = None + self.current_context = None self.current_page = None self.current_iframe = None diff --git a/PuppeteerLibrary/puppeteer/async_keywords/puppeteer_browsermanagement.py b/PuppeteerLibrary/puppeteer/async_keywords/puppeteer_browsermanagement.py index 92d40a1..de4d171 100644 --- a/PuppeteerLibrary/puppeteer/async_keywords/puppeteer_browsermanagement.py +++ b/PuppeteerLibrary/puppeteer/async_keywords/puppeteer_browsermanagement.py @@ -88,6 +88,15 @@ async def switch_window(self, locator='MAIN'): raise Exception('Sorry Switch window support only NEW, MAIN, title and url') raise Exception('Can\'t find specify page locator.') + ############################## + # Trace + ############################## + async def start_tracing(self): + raise Exception('Not support') + + async def stop_tracing(self, path=None): + raise Exception('Not support') + ############################## # Page ############################## From abb4d1531615e9e12cd571640324debc33b1b5d7 Mon Sep 17 00:00:00 2001 From: "DESKTOP\\atthaboon.s" Date: Thu, 23 Sep 2021 09:07:46 +0700 Subject: [PATCH 4/6] Update default browser for chrome --- .gitignore | 1 + Examples/browser-management/tracing.robot | 15 ++++++++++++--- PuppeteerLibrary/keywords/browsermanagement.py | 17 ++++++++++++++++- .../library_context/library_context_factory.py | 8 +++++--- .../playwright/playwright_context.py | 2 +- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2816e60..4aecaab 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ Examples;tmp-download/test.csv Examples/test.csv .venv/ Examples/trace.zip +Examples/traces/ diff --git a/Examples/browser-management/tracing.robot b/Examples/browser-management/tracing.robot index 1a2eff1..7fb8742 100644 --- a/Examples/browser-management/tracing.robot +++ b/Examples/browser-management/tracing.robot @@ -4,16 +4,25 @@ Test Teardown Close All Browser Suite Teardown Close Puppeteer *** Variables *** -${DEFAULT_BROWSER} pwchrome +${DEFAULT_BROWSER} chrome *** Test Cases *** Tracing log without path + ${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER} + Open browser to test page http://127.0.0.1:7272/login-form-example.html + Run Keyword If '${BROWSER}' != 'ptchrome' Start tracing + Select Checkbox id=exampleCheck1 + Checkbox Should Be Selected id=exampleCheck1 + Run Keyword If '${BROWSER}' != 'ptchrome' Stop Tracing + +Tracing log with specific path + ${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER} Open browser to test page http://127.0.0.1:7272/login-form-example.html - Start tracing + Run Keyword If '${BROWSER}' != 'ptchrome' Start tracing Select Checkbox id=exampleCheck1 Checkbox Should Be Selected id=exampleCheck1 - Stop Tracing + Run Keyword If '${BROWSER}' != 'ptchrome' Stop Tracing trace2.zip *** Keywords *** Open browser to test page diff --git a/PuppeteerLibrary/keywords/browsermanagement.py b/PuppeteerLibrary/keywords/browsermanagement.py index 743fc8f..dc45b61 100644 --- a/PuppeteerLibrary/keywords/browsermanagement.py +++ b/PuppeteerLibrary/keywords/browsermanagement.py @@ -1,6 +1,7 @@ from PuppeteerLibrary.base.librarycomponent import LibraryComponent from PuppeteerLibrary.base.robotlibcore import keyword from PuppeteerLibrary.ikeywords.ibrowsermanagement_async import iBrowserManagementAsync +from robot.libraries.BuiltIn import BuiltIn class BrowserManagementKeywords(LibraryComponent): @@ -18,8 +19,9 @@ def open_browser(self, url, browser="chrome", alias=None, options={}): The ``browser`` argument specifies which browser to use. | = Browser = | = Name(s) = | = Engine = | - | Google Chrome | chrome | Puppeteer | + | Google Chrome Default | chrome | Playwright | | Google Chrome Playwright | pwchrome | Playwright | + | Google Chrome Puppeteer | ptchrome | Puppeteer | | Webkit (Safari engine) | webkit | Playwright | | Firefox | firefox | Playwright | @@ -167,10 +169,23 @@ def enable_emulate_mode(self, emulate_name): ############################## @keyword def start_tracing(self): + """Create trace log file + + # View the trace by running following command + + playwright show-trace trace.zip + """ return self.loop.run_until_complete(self.get_async_keyword_group().start_tracing()) @keyword def stop_tracing(self, path=None): + """Stop trace and generate the trace file. + + Default will be ``traces/.zip`` + """ + if path is None: + test_name = BuiltIn().get_variable_value("${TEST_NAME}") + path = 'traces/'+test_name+'.zip' return self.loop.run_until_complete(self.get_async_keyword_group().stop_tracing(path)) ############################## diff --git a/PuppeteerLibrary/library_context/library_context_factory.py b/PuppeteerLibrary/library_context/library_context_factory.py index dd4e2e1..127e8e8 100644 --- a/PuppeteerLibrary/library_context/library_context_factory.py +++ b/PuppeteerLibrary/library_context/library_context_factory.py @@ -7,12 +7,14 @@ class LibraryContextFactory: def create(self, browser_type: str) -> iLibraryContext: """Return iLibraryContext based on specific browser_type - Create context based on browser type (chrome, pwchrome, safari, webkit) + Create context based on browser type (chrome, pwchrome, ptchrome, safari, webkit) """ if browser_type.lower() == 'chrome': - return PuppeteerContext(browser_type) - if browser_type.lower() == 'pwchrome': return PlaywrightContext(browser_type) + elif browser_type.lower() == 'pwchrome': + return PlaywrightContext(browser_type) + elif browser_type.lower() == 'ptchrome': + return PuppeteerContext(browser_type) elif browser_type.lower() == 'safari': return PlaywrightContext(browser_type) elif browser_type.lower() == 'webkit': diff --git a/PuppeteerLibrary/playwright/playwright_context.py b/PuppeteerLibrary/playwright/playwright_context.py index fe1314b..cb71c35 100644 --- a/PuppeteerLibrary/playwright/playwright_context.py +++ b/PuppeteerLibrary/playwright/playwright_context.py @@ -64,7 +64,7 @@ async def start_server(self, options: dict={}): if self.playwright is None: self.playwright = await async_playwright().start() - if self.browser_type == "pwchrome": + if self.browser_type == "chrome" or self.browser_type == "pwchrome": self.browser = await self.playwright.chromium.launch( headless=merged_options['headless']) elif self.browser_type == "webkit": From 04f76340aa16456182a0188095390d28a7c2ea69 Mon Sep 17 00:00:00 2001 From: "Atthaboon Sanurt (P'Art)" Date: Thu, 23 Sep 2021 09:08:41 +0700 Subject: [PATCH 5/6] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index d882f9e..77a3a11 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -12,11 +12,11 @@ jobs: # python-version: [3.7, 3.8, 3.9] include: - python-version: 3.7 - browser: pwchrome + browser: chrome - python-version: 3.7 - browser: webkit + browser: ptchrome - python-version: 3.8 - browser: chrome + browser: webkit - python-version: 3.9 browser: firefox From dd1ae2493cab8e7a84303c27822e4a2a464ecada Mon Sep 17 00:00:00 2001 From: "DESKTOP\\atthaboon.s" Date: Thu, 23 Sep 2021 09:17:01 +0700 Subject: [PATCH 6/6] Update force tag --- Examples/locator/chain-locator.robot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/locator/chain-locator.robot b/Examples/locator/chain-locator.robot index 3ed9ddb..5dc7b43 100644 --- a/Examples/locator/chain-locator.robot +++ b/Examples/locator/chain-locator.robot @@ -1,12 +1,12 @@ *** Settings *** -Force Tags Ignore_chrome +Force Tags Ignore_ptchrome Library PuppeteerLibrary Test Setup Open browser to test page Test Teardown Close All Browser Suite Teardown Close Puppeteer *** Variables *** -${DEFAULT_BROWSER} pwchrome +${DEFAULT_BROWSER} chrome ${HOME_PAGE_URL} http://127.0.0.1:7272/register-form-example.html