From 8a2ae5ae147e4377bf9971755ba9fb0a146df3c7 Mon Sep 17 00:00:00 2001 From: "Atthaboon Sanurt (P'Art)" Date: Tue, 21 Jul 2020 14:58:50 +0000 Subject: [PATCH 1/3] Add draft keyword --- PuppeteerLibrary/keywords/waiting.py | 8 ++++++++ PuppeteerLibrary/keywords/waiting_async.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/PuppeteerLibrary/keywords/waiting.py b/PuppeteerLibrary/keywords/waiting.py index b17ad0f..2ca14fe 100644 --- a/PuppeteerLibrary/keywords/waiting.py +++ b/PuppeteerLibrary/keywords/waiting.py @@ -175,3 +175,11 @@ def wait_until_element_does_not_contains(self, locator, text, timeout=None): """ return self.loop.run_until_complete(self.async_func.wait_until_element_does_not_contains_async(locator, text, timeout)) + @keyword + def wait_until_location_contains(self, expected, timeout=None): + """ + Waits until the current URL contains `expected`. + + The `expected` argument contains the expected value in url. + """ + return self.loop.run_until_complete(self.async_func.wait_until_location_contains_async(expected, timeout)) diff --git a/PuppeteerLibrary/keywords/waiting_async.py b/PuppeteerLibrary/keywords/waiting_async.py index 1249087..3afa4ea 100644 --- a/PuppeteerLibrary/keywords/waiting_async.py +++ b/PuppeteerLibrary/keywords/waiting_async.py @@ -93,6 +93,10 @@ async def validate_element_contains_text(): validate_element_contains_text, self.timestr_to_secs_for_default_timeout(timeout)) + @keyword + async def wait_until_location_contains_async(self): + return None + async def _wait_until_worker(self, condition, timeout, error=None): max_time = time.time() + timeout not_found = None From 3256413e16909fb1cf7b78e802f6ad26c6c7f09f Mon Sep 17 00:00:00 2001 From: atthaboons Date: Tue, 21 Jul 2020 22:38:07 +0700 Subject: [PATCH 2/3] Add wait for location contain text --- Examples/wait-for-demo.robot | 8 ++++++++ PuppeteerLibrary/keywords/browsermanagement.py | 4 +++- PuppeteerLibrary/keywords/waiting_async.py | 12 ++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Examples/wait-for-demo.robot b/Examples/wait-for-demo.robot index e47c000..5c27b15 100644 --- a/Examples/wait-for-demo.robot +++ b/Examples/wait-for-demo.robot @@ -55,3 +55,11 @@ Demo wait for element contains text Open browser ${HOME_PAGE_URL} options=${options} Wait Until Element Contains css:#container p Please input your user name Wait Until Element Does Not Contains css:#container p Invalid user name and/or password + +Demo wait for location contains + ${HEADLESS} Get variable value ${HEADLESS} ${False} + &{options} = create dictionary headless=${HEADLESS} + Open browser ${HOME_PAGE_URL} options=${options} + Go To ${HOME_PAGE_URL}/docs.html + Switch Window NEW + Wait Until Location Contains docs.html diff --git a/PuppeteerLibrary/keywords/browsermanagement.py b/PuppeteerLibrary/keywords/browsermanagement.py index 6dfce65..49df9c4 100644 --- a/PuppeteerLibrary/keywords/browsermanagement.py +++ b/PuppeteerLibrary/keywords/browsermanagement.py @@ -50,7 +50,9 @@ async def open_browser_async(): 'width': merged_options['width'], 'height': merged_options['height'] }, - args=['--no-sandbox', '--disable-setuid-sandbox']) + # Only for ubuntu + # args=['--no-sandbox', '--disable-setuid-sandbox']) + args=['--disable-setuid-sandbox']) self.ctx.current_page = await self.ctx.browser.newPage() await self.ctx.current_page.goto(url) await self.ctx.current_page.screenshot({'path': 'example.png'}) diff --git a/PuppeteerLibrary/keywords/waiting_async.py b/PuppeteerLibrary/keywords/waiting_async.py index 3afa4ea..8a0d6dc 100644 --- a/PuppeteerLibrary/keywords/waiting_async.py +++ b/PuppeteerLibrary/keywords/waiting_async.py @@ -94,8 +94,12 @@ async def validate_element_contains_text(): self.timestr_to_secs_for_default_timeout(timeout)) @keyword - async def wait_until_location_contains_async(self): - return None + async def wait_until_location_contains_async(self, expected, timeout=None): + async def validate_url_contains_text(): + return expected in self.ctx.get_current_page().url + return await self._wait_until_worker( + validate_url_contains_text, + self.timestr_to_secs_for_default_timeout(timeout)) async def _wait_until_worker(self, condition, timeout, error=None): max_time = time.time() + timeout @@ -104,10 +108,10 @@ async def _wait_until_worker(self, condition, timeout, error=None): try: if await condition(): return + else: + not_found = None except Exception as err: not_found = err - else: - not_found = None await asyncio.sleep(0.2) raise AssertionError(not_found or error) From 6c094e02a6d8eb7f5361e6d01d96b8a662d580ea Mon Sep 17 00:00:00 2001 From: atthaboons Date: Tue, 21 Jul 2020 22:44:41 +0700 Subject: [PATCH 3/3] Add wait until location does not contains --- PuppeteerLibrary/keywords/waiting.py | 9 +++++++++ PuppeteerLibrary/keywords/waiting_async.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/PuppeteerLibrary/keywords/waiting.py b/PuppeteerLibrary/keywords/waiting.py index 2ca14fe..d36ec7e 100644 --- a/PuppeteerLibrary/keywords/waiting.py +++ b/PuppeteerLibrary/keywords/waiting.py @@ -183,3 +183,12 @@ def wait_until_location_contains(self, expected, timeout=None): The `expected` argument contains the expected value in url. """ return self.loop.run_until_complete(self.async_func.wait_until_location_contains_async(expected, timeout)) + + @keyword + def wait_until_location_does_not_contains(self, expected, timeout=None): + """ + Waits until the current URL does not contains `expected`. + + The `expected` argument contains the expected value must not in url. + """ + return self.loop.run_until_complete(self.async_func.wait_until_location_does_not_contains_async(expected, timeout)) diff --git a/PuppeteerLibrary/keywords/waiting_async.py b/PuppeteerLibrary/keywords/waiting_async.py index 8a0d6dc..d98d0f4 100644 --- a/PuppeteerLibrary/keywords/waiting_async.py +++ b/PuppeteerLibrary/keywords/waiting_async.py @@ -101,6 +101,14 @@ async def validate_url_contains_text(): validate_url_contains_text, self.timestr_to_secs_for_default_timeout(timeout)) + @keyword + async def wait_until_location_does_not_contains_async(self, expected, timeout=None): + async def validate_url_not_contains_text(): + return expected not in self.ctx.get_current_page().url + return await self._wait_until_worker( + validate_url_not_contains_text, + self.timestr_to_secs_for_default_timeout(timeout)) + async def _wait_until_worker(self, condition, timeout, error=None): max_time = time.time() + timeout not_found = None