In This Course
Did you know that a recent poll revealed that 80% of QA Automation Engineers cannot run more than 100 functional tests daily, with 95% reliability? Furthermore, over 50% of these Automation Engineers struggle to run between 0 – 50 automated functional tests per day!
Functional test automation is a hard job. However, you can make your job much easier by learning a pattern known as the Page Object Pattern. The Page Object Pattern helps to resolve a lot of the problems that other automation techniques cannot. Making your test automation more stable as a result.
This course is designed to teach you how to properly code the Page Object Pattern using Selenium Webdriver with C#.
However, all of the information here is equally applicable to any other functional testing tool because the Page Object Pattern is a universal principle that makes test automation more robust. Similar to other universal concepts such as Don’t Repeat Yourself or Single Responsibility Principle.
Therefore, if you know Object Oriented programming and a different functional automation tool, you can still comfortably follow along with all of the principles and patterns that I lay out in this course.
In this course, you will learn:
– Why other methods such as Record & Replay or Keyword Driven do not work when it comes to test automation
– What the Page Object Pattern is in automation
– Advantages and disadvantages of the Page Objects
– Amazing tips and tricks on how to:
- Implement the Page Objects using Selenium Webdriver
- Improve your Page Objects to follow DRY Principle
- Improve Page Objects to follow SRP Principle
- Create amazing Page Objects for gigantic web pages
In This Lecture
In this video, we will go through on Explaining the solution to the quiz.
Selenium Tutorial – Explaining the solution to the quiz
I hope that you spend some time trying that exercise and I hope that you’ve succeeded. If not it’s OK. It was really tough. I actually spent about 30 minutes trying to figure out how to automate the situation. And it’s because there are many variables on this page that make it extremely tough. For example when you first load the page you can’t just directly identify the toggle and try and open it by its locator because it’s not visible. And so you won’t be able to click on it. So that’s not going to work.
And what you’re going to get is element not clickable exception. And that’s some other element is going to receive your click. So in that case what you need to do is to place focus on the actual element. So that it’s visible now is going to be available for you to click on. There are several methods to do this utilizing any NY driver. I’m going to show you one but if you attempt to do that. The method was going to happen it will definitely pull the element into focus is going to pull that element into focus and the page will look something like this. Yes.
The element is in focus but it’s behind this Hetter up here. So again if you attempt to click on this you’re going to get another error telling you that this Hetter up here is going to receive the click because that toggle button is not visible. So what are you going to do. It’s really hard. What I decided to do was rather than placing focus on the element on the toggle I placed focus on this carousel of Polsce a ball of the toggle.
So now when I place focus on it the page is going to come to about this point.
And my toggle is clearly visible in the center of my screen and the ready to accept my clicks. That’s what I did. Let me show you the code. So here I road test five and as standard. I created another complicated page went to the complicated page and asserted that the complicated page opened successfully and nothing new here. What’s new here is I created a method called Open toggle and my open toggle is going to do all of those actions that I mentioned.
I’m going to utilize the actions class to move to the element that I called the Post’s slider that pole slider that’s the element right above the toggle which I identified in this manner. Now once we move to the element using the actions class then my toggle is open for clicking. So I just use the object repository in the toggle element which I identified in this manner and I clicked on it and that was fantastic.
After clicking on it I wrote an assertion stating that the complicated page that the toggle is open and that is true. So to check that the toggle is open. I had to use a selenium web driver weight class which has an explicit weight instead of an implicit weight. I didn’t want to use an implicit weight because if you noticed here the toggle opens a little bit slow and an implicit wait has a time out of zero seconds.
So if for whatever reason the toggle does not open fast enough your implicit wait also known as find element’s method is going to fail. So rather what you have to do is use an explicit weight.
I use an explicit weight and set a time out of five seconds. I rafted in a try catch block and I’m checking to see if the elements I’m waiting until the expected conditions. That element is visible and the element that’s visible is my toggle inner text locator. Let me go to the definition and my toggle text locator is of type by and I located it using X bath and making sure that it has text called Inside the toggle.
So we wait until this element is visible if the element is not visible what’s going to happen is selenium is going to throw a web drive or timeout exception which we’re going to catch and return false to our method. If the element is visible however no exception is going to be thrown.
And we’re going to return a true therefore giving us a fantastic test. Now that I’ve explained to you what I’ve done. Let me just run this test so that you can actually see it working.