Using Selenium WebDriver Waits as Retries in Your Tests

QAutomation News / By  Corina Pip 

The topic of Selenium tests failing due to timing issues comes up quite a lot. Random failures are attributed to the interaction being done too early, when the page has either not properly loaded, or when the WebElements themselves were not fully initialized. The biggest issue occurs when JavaScript is involved in rendering page elements.

Although in some cases testers will try to use Selenium WebDriver wait methods to wait for certain conditions to be fulfilled before trying the interaction, they might still get test failures. So what would be a good solution to have reliable tests? 🤔 Read on to see how we can create aggregated wait methods that will allow us to retry complex conditions.

The WebDriverWait class and methods

Before we start writing our aggregated wait methods, we need to look a little bit at the WebDriverWait class from Selenium. It allows us to create custom wait methods in our tests, where we can wait for all sorts of conditions to be fulfilled, like a WebElement to be displayed, or the text on a WebElement to equal a certain String, and so on. When creating your wait methods you might use some of the ExpectedConditions methods that exist in the Selenium library, or you might write some custom code yourself.

Continue reading from source link

One thought on “Using Selenium WebDriver Waits as Retries in Your Tests

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s