How do you recognize a fake Selenium tester? By his code

You can recognize a fake Selenium tester by looking at his code. Look at how much code he writes in a day more importantly, look at how good the code is   The following code is written by a fake Selenium tester.   I have added some comments to explain what the code does.  …

Use a custom driver class instead of utility classes

How can I create my own driver class in Selenium? When learning test automation, you will want your test methods to be executed in multiple browsers such as Firefox and Chrome. A Firefox driver is created with the FirefoxDriver class: WebDriver driver = new FirefoxDriver(); A Chrome driver is created with the ChromeDriver class: WebDriver…

How to retry automatically Selenium tests

Test automation methods fail often. Sometimes because the test automation code has bugs so you need to fix them. Other times because the tested site does not load correctly or loads very slowly.   Lets look in more detail at this second case.   The test automation code is correct. You prove it correct by…

How to create page objects with Selenium WebDriver

Everything starts with a manual test case.  Our test case is for the Vancouver Public Library site.  It tests that a search done on the site’s home page returns results.        The test case tell us what actions the user takes  1. user opens home page  2. user searches for keyword  to verify…

How to reduce code duplication using predicates and lambda expressions

Many sites allow their clients to search for information and then browse through the results. Each result has multiple attributes such as title price status     In test automation projects, it is important to have the ability of filtering the results by different attributes. For example, filter the results with price greater than 0….

How to run scripts in a specific browser with Maven

mvn test is the Maven command for running test scripts in command prompt (or Jenkins). It runs all test scripts from the test class in the browser defined in the project. But what if you would like to specify the browser name as a parameter of the command? Such as mvn test -Dbrowser=chrome or mvn…

Correct and incorrect ways of creating page object classes

Let’s say that you want to automate test scenarios for the login page of a web site. The login page has 3 elements: – username textbox – password textbox – sign in button     Some of the test cases to be automated for this page are user can sign in with correct username and…

How to deal with windows authentication popups

  If you dont like Bugs Bunny, maybe you should not continue reading.   What is the first thing that I do every morning at work? Check the results of the automation scripts executed in Jenkins over night. I want to know how many scripts passed or failed because of the work done in the…

How to use locators with parameters

Sometimes, you need to interact in automation scripts with web elements that have similar HTML code. For example, you may want to automate the following test case: open site search for keyword check that the results page is displayed select the 2nd page of results check that the 2nd page is displayed select the 3rd…

Do not store element locators in property files

You have a small test automation project with about 50 test scripts and 10 page object classes. Each page object class uses approximately 10 web elements. The project has around 100 web element locators. Where should the elements’ locators be stored? Should they be stored in the page object classes, in enumerations, classes with static…

How to work with cookies

Browsers use cookies to store user preferences such as user location number of results per page sort order language Next time the user visits the site, the user preferences saved in the cookies are set automatically for the site. Each cookie is defined by the following fields: name value domain path expires size http isSecure…