Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Examples/wait-for-demo.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion PuppeteerLibrary/keywords/browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
17 changes: 17 additions & 0 deletions PuppeteerLibrary/keywords/waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
20 changes: 18 additions & 2 deletions PuppeteerLibrary/keywords/waiting_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,33 @@ 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
while time.time() < max_time:
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)

Expand Down