What will you learn in this lecture?
In the previous video, we learned about the future of ExpectedConditions. In this video, we will have the proper synchronization quiz.
Proper Synchronization Quiz
So now that we’ve covered everything there is to know about element synchronization, I wanted to teach you one final technique on how to appropriately navigate web pages and synchronize on them so that you don’t run into flaky test automation so that you drastically decrease it.
I’ve actually never seen this technique taught anywhere else so I wanted to bring it to you so that you actually know what to do.
And when everybody talks about how to synchronize right using implicit and explicit ways but nobody actually defines a method for how to deal with different kinds of flaky issues.
So I wanted to bring you a general approach that I normally follow.
It’s not foolproof. It’s you know.
It’s a general approach that will help guide you in most instances. It will help to prevent flaky tests and in some instances it might require a little bit of improvisation.
So we’re gonna do this with a quiz.
However, I’m gonna take you through all of the steps so that you know exactly what to do and then you’re gonna need to code the quiz to make it work.
So the general idea of how to properly synchronize using selenium webdriver is you want to open a page. Once you open up a page, you want to synchronize on the slowest loading element and then afterwards you want to proceed with actions.
What this means is every page load must be followed by a synchronization point using and expected or using an explicit wait on the slowest loading element.
So, if I was to do this and this is what we’re gonna do for our quiz, what you’re gonna do is you’re gonna open up ultimateqa.com.
Now, if we want to find the slowest loading element what we can actually do is open up developer tools.
As you saw, I just did and go to the network tab. I can refresh this page and I can see the network traffic exactly how all of the elements come in over here.
On the right-hand side, you can see the waterfall chart so it starts from the very first element from the very first HTTP request all the way to the very last HTTP request.
You can see this is the one that occurs last and even though here, I actually see two other calls that you can see started and took quite a bit of time to load.
So there’s some PHP that was actually being executed. So if you want to find the slowest loading element, what you can do is scroll all the way to the bottom and see which element here was the slowest loading.
You actually probably want to not look at any gifs, any scripts, any style sheets. What you want to be looking for is an exact element, maybe some kind of like a PNG or here perfect a JPEG.
So this is actually an image that was loaded the reason. We’re not looking at anything else is because they’re actually not elements but they’re part of the HTML so it’s kind of hard to sync on them.
But we’re for Selenium. Since we’re doing GUI based stuff, we want to synchronize on an element and so in this case, I found this one which is a JPEG that we can synchronize on.
So you can open it up and see what that looks like but I can actually find it in our HTML. By taking its name and then going to the elements and then using the controller feature to find our string and so in here you can see that I found this element.
It’s right here that lives inside of this div and now I can use this div to synchronize on one of the slowest loading elements.
It’s not the last one but it is one of the slower loading elements and so now you can synchronize on it.
And then the next step would be once you synchronize on it to click automation exercises link. So once you click the automation exercises link, the very next step is to again synchronize here just exactly like I taught you and then you’re gonna go to big page with many elements.
And so now you’re going to load this page. You’re gonna synchronize here and assert that this page is successfully loaded.
I leave all of the implementation up to you but you must have a solid running test that can run under any conditions and obviously stable with no synchronization issues so give that a shot.
As I said, these steps will work the majority of the time be flexible if you would like to synchronize on more than one element. You have that option.
Of course, do your best because a synchronization point is not necessarily bad. All it says is that the driver will wait for a maximum duration of time so if the element that you’re synchronizing on is already loaded even though you synchronized on a previous element, it’s not a big deal.
You only lose about half a second because that’s how long the web driver will need to pull for that element so give that a shot.
Here’s the test and its name code it out and then when you come back. I’m gonna give you the answer and then this will be great practice for you to utilize all the skills that you’ve previously learned.
In the next tutorial, we will learn the answer to the synchronization quiz.
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