In This Course

In this course, you will:

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

2. Learn how to use Selenium Webdriver explicit waits

3. Master Selenium Webdriver implicit wait

4. Understand what a DefaultWait is

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

Free Video Course

In this Lecture

This lecture talks about what a DefaultWait class is. You’ll also learn it’s application and it’s advantages. After that, you’ll have to answer the quiz one DefaultWait Class.

Selenium Tutorial – DefaultWait Class and Quiz

The next type of wait that I want to show you is known as a fluent wait but it’s known as fluent wait in java. The reason that it’s known as a fluent wait in java is actually because the WebDriverWait class inherits from the fluent wait class in java. However, if we look at our WebDriverWait wait class and I navigate to the definition here, we can see that our WebDriverWait class inherits from the default class. Therefore, the WebDriverWait is the child of the DefaultWait parent.

For us with the C# bindings, our fluent wait going to be known as a DefaultWait. I just want to make you aware of that because whenever you look on the web and you see people talking about the fluent wait in java you know that it’s equivalent to a DefaultWait in the C# Bindings.

What is this DefaultWait?

Well if we navigate to the definition and take a look, we see that there are two different constructors for the DefaultWait. There is a property called Message, Pollinginterval and Timeout.

Then there are some methods that allow us to IgnoreExceptionTypes, do the polling and ThrowTimeoutException. That vantage of using a DefaultWait is that it allows us to do more closely define things such as the time out and how long our time out is going to be. It allows us to define a message that is thrown when an exception occurs, it allow us to define the PollingInterval and it even allow us to IgnoreExceptionTypes. We not only will ignore the NoSuchElementException, which is ignored by the WebDriver wait automatically. We can ignore other exception types if we decide to do so.

You can kind of see it’s pretty readable to use this kind of thing. People like to use the DefaultWait because it’s readable. It allows you to very easily define the implementation of the wait class.

Application

Take a look when I did here. I created my WebDriver wait using the DefaultWait class and the DefaultWait class of course returns the DefaultWait class. Once that’s done, we define the Timeout, we define the Message, we define the PollingInterval and we define which type of exceptions to ignore then we do our standard stopwatch interval and we wait until the element is visible.

One thing that I want to point to you to is the “Until” implementation. If you take a look the Until implementation actually comes from DefaultWait class, it does not come from the WebDriver Wait class. If you look at the WebDriverWait class and look at its definition, you can see it’s very thin and very small nice class and it has two constructors that you guys know about.

It does not have the “Until” method. The “Until” method actually belong to a parent, the DefaultWait right here. When we do expected condition, it actually a delegate definition that tells the Selenium WebDriver bindings that to do something.

That’s how actually that was working. If I hover over this ElementIsVisible. You can see that it’s  a delegate, exactly what the “Until” method expects from the DefaultWait class. We can run this and I actually, what I did was a defined a constant string variable here Ids, then I made a bad Id. Just to make that even more clear. I made that a fake Id that it does not exist just you guys can see what happens when I run this test. Let me go ahead and run it.

Result

Of course, it should fail because that fake element doesn’t exist. The idea of that element is not there on the DOM. If I look in here, you can see my message and it says here, “Timed out after 10 seconds.” Then look at our exception message, “Dude, where’s my element?”

The rest of the detail is for the exception. You can see that we basically defined how our wait is going to behave with these conditions. Now I told you guys the advantages that it allows you to very granularly define all of these properties for the wait class. However, it’s not very common that people, this QA engineers, don’t use these DefaultWait classes very commonly. Actually, I want to show you guys reason why.

Quiz

Let me ask you guys this. If I comment that out and I comment this out. I would like for you to tell me if you were using the webdriver wait class and you wanted to define this same exact behavior that’s represented here by the DefaultWait class? How would you do that? What would you do with the WebDriverWait class? And what code would you write to repeat this functionalities here?

Take a second to think about it and when you come back, I’m going to give you the answer.

 

Pin It on Pinterest

Shares
Share This