Skip to content

Instantly share code, notes, and snippets.

@maxwellamaral
Last active October 4, 2022 17:50
Show Gist options
  • Save maxwellamaral/dd3d39415b4a5b81cbaf3ed4d2fdf1de to your computer and use it in GitHub Desktop.
Save maxwellamaral/dd3d39415b4a5b81cbaf3ed4d2fdf1de to your computer and use it in GitHub Desktop.
Lidando com o time.sleep() vodu em testes
def wait_for_site_page_title(self, page_title: str, MAX_WAIT=10):
"""
Função que lida com o time.sleep() em testes. Sabe-se que a sleep() não funciona para esperas explícitas utilizando Selenium
"""
if not page_title:
raise Exception('No title')
start_time = time.time()
while True:
try:
title = self.browser.title
self.assertIn(page_title, title)
return
except(AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment