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.py b/PuppeteerLibrary/keywords/waiting.py index b17ad0f..d36ec7e 100644 --- a/PuppeteerLibrary/keywords/waiting.py +++ b/PuppeteerLibrary/keywords/waiting.py @@ -175,3 +175,20 @@ 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)) + + @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 1249087..d98d0f4 100644 --- a/PuppeteerLibrary/keywords/waiting_async.py +++ b/PuppeteerLibrary/keywords/waiting_async.py @@ -93,6 +93,22 @@ 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, 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)) + + @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 @@ -100,10 +116,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)