Reputation: 17
I've got a question about using time.sleep() to test Angular2 app. I do know that there is something like Protractor (and Pytractor) and you can use it when writing functional tests in Selenium. You can also use Explicit Waits. I found this info e.g. here: https://stackoverflow.com/a/29503381/6401796 But what about using time import? Is that even correct to write tests like that for Angular2 apps? My code:
import time
def open_login_page(self):
wd = self.wd
wd.get(localhost)
time.sleep(10)
I'm waiting here for all elements to show up. Thank you for considering my request.
Upvotes: 0
Views: 191
Reputation: 50899
wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.ID, "someID")))
Explicit wait is waiting for the condition to met up to the specified time, 10 seconds in this example. If the element is visible after 2 seconds the script will continue after 2 seconds of waiting.
When using
time.sleep(10)
The script will wait for 10 seconds no matter what, unnecessary 8 seconds delay.
Upvotes: 1