What will you learn in this lecture?

In the previous video, we learned the 2 types of explicit waits. In this video, we will talk about WebDriverWait.

WebDriverWait

I know that I flew over this entire example of an explicit wait and the reason I did that is because there is a more efficient and I’d better two-way and a better to read method of doing explicit weights.

That’s exactly what I’m going to show you next.

It’s the most convenient and what I’ve done here to exemplify to you not only how these tests, how these explicit waits fix the test but also they’re more readable and they are easier to use.

You can see, I’ve placed the tests that were fixed implicitly. Over here on the left in the implicit wait that’s CS file and then I have the same exact tests fixed explicitly over here on the right-hand side in the explicit way that’s CS file.

So you can see that they do exactly the same thing.

This one goes to slow animation URL.

Obviously, it’s not going to have this step of setting an implicit wait because it’s no longer required. It still fills out the credit card info and then it sets an explicit wait.

I did the same thing for test three.

As you can see, test three here and then I did the same exact thing for test 4 as well.

Okay, so you can see how they look side by side.

They’re the exact same code but what’s changed is one as an explicit wait implementation and the other is an implicit wait implementation.

So let’s begin to the implicit explicit waits so that you can better understand exactly what’s happening. So here’s the first test fixed explicitly.

It’s doing all the same actions as before and down here is where we start to use an explicit wait condition. The way we use an explicit wait condition is you first have to initialize an instance of the web driver wait class.

The web driver wait class comes from open QA that Selenium support that UI namespace and you can see that there are two different types of implementations to the different types of constructors and you can supply the different options.

I basically have never used this constructor on line 25 however, if you find the need for it let me know I would be very interested to know why that would be needed.

I’ve always used this first constructor and so inside of this constructor, we’ve supplied a driver and a timespan. The timespan, obviously lets us know how long we want to wait for an element before throwing a webdriver time-out exception.

That’s what happens whenever we use our explicit waits.

Also, just wanted to mention, make sure that if using the webdriver wait class, you should have the appropriate namespaces. Import it up here.

I wanted to show you those because I obviously coded previously and so I imported all the appropriate namespaces. So back to here so now that we have our wait class which is going to do the waiting the wait class has a method called dot until we can take a look at this method.

Just using our F12 to navigate to the definition and you can see that it uses generics and it basically allows you to create any kind of function that you want and wait for a specific condition to be returned.

Let me better show you that so in this case what we can do is use we can wait until an expected condition, an expected condition is something that selenium has provided us to make life easy so you can see that it comes from that namespace right there open QA dot selenium that support that UI that expected conditions. 

These provide us many different options to check for the presence of an element take a look here.

[Tweet “Learn everything you need to know about Selenium Webdriver implicit and explicit waits.”]

Next Tutorial

In the next tutorial, we will talk ExpectedConditions.

What will you learn in this course?

Are your automated functional tests flaky? Do they randomly fail and you are unsure why? Is your team frustrated with the “instability” of your Selenium Webdriver tests?

If you are interested in fixing all of these problems and making your tests more stable, then you need to understand how to use all of the different types of waits in Selenium Webdriver. Knowing how to handle synchronization issues will make you a top-notch Test Engineer!

“The best tutorials I have ever seen, simply awesome. I take off my hat in front of you, you are a gorgeous professor, I am speechless to express how satisfied I am with these tutorials.” -Lisbey

In this course from Ultimate QA, you will learn:

– Learn the problems that can occur as a result of improper synchronization.

– Learn how to use Selenium Webdriver explicit waits.

– Master Selenium Webdriver implicit waits

– Understand what a DefaultWait is

– Comprehend how to use all of the different types of waits during appropriate situations

Take This Entire Course for Free

[Tweet “Learn how to correctly use implicit and explicit waits using #Selenium #Webdriver.”]

0 Shares
Tweet
Share
Share