Last active
October 4, 2022 17:50
-
-
Save maxwellamaral/dd3d39415b4a5b81cbaf3ed4d2fdf1de to your computer and use it in GitHub Desktop.
Lidando com o time.sleep() vodu em testes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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