...

Selenium automation is becoming the most sought after automated testing tool. I reviewed different websites that dedicate their entire content to Selenium. As I observed endless theoretical backgrounds, examples, explanations, installations, and code segments, the one thing that I wanted to dig deeper into was why more and more organizations are migrating to Selenium?

In order to clearly understand the benefits of Selenium and why it is gaining popularity, we first need to understand automation testing.

Key Findings
• In the past decade, the growth of IT industry has brought along complex IT products and even more complicated applications. Effective testing is even more important as there is no scope for human errors or manual blunders.
• Automated testing is taking over manual processes as it faster and more efficient. It is not prone to errors, provides test coverage in short time, and comes at a low cost.
• The demand for automation testing is increasing at an unprecedented speed and scale. According to Transparency Market Research (TMR), the global test automation market will likely expand at a robust CAGR of 15.4% from 2017 to 2025 to become worth US$ 109.69 billion by 2025 from US$ 30.45 billion in 2016.
• Success here depends on identifying the right tool for the project. With so many automation tools to choose from, this process can be tricky.

Selenium, the All-time Favorite

Selenium, the open-source automation testing tool for web-based applications, is becoming increasingly popular. The extensively used automation tool has certain unique benefits that give it an edge over the competition. Let’s see why it is the most preferred choice of organizations and automation testers.

• The main reason for the success of Selenium is that the tests can be coded in any number of programming languages, they can be run directly in web browsers, and work across operating systems.
• The second reason for the success of Selenium as the most powerful automation tool are its features that are simple to use – its capable user interfaces help meet 90% needs of web application testers. and more of these make it a preferred choice for many testers.

Best Practices – Selenium Test Automation

Based on experience of leveraging Selenium for test automation, I recommend the following practices:

  1. Use PageObjects Pattern 

Page Object model is an object design pattern in Selenium, where web pages are represented as classes, and the various elements on the page are defined as variables on the class. All possible user interactions can then be implemented as methods on the class:

clickLoginButton();

setCredentials (user_name, user_password);

Since well-named methods in classes are easy to read, this works as an elegant way to implement test routines that are both readable and easier to maintain or update in the future.

Advantages of using Page Object Pattern:

• Easy to Maintain
• Easy Readability of scripts
• Reduce or Eliminate duplicity
• Re-usability of code
• Reliability

  1. Preferred selector order:

Preferred selector order: id > name >links text> css > xpath

CSS and XPath are location-based selectors, they are slower than other selectors.

• Id and name are often the easiest and sure way.
• CSS = Id + name.
• Last solution should be xpath.

  1. Avoid Thread.sleep prefer Wait

Instead of sleep, use explicit wait/implicit wait is the best practice, let’s see what actually the explicit wait, Thread.sleep(), Implicit wait’s working logic

Explicit wait:An explicit wait is a kind of wait for a certain condition to occur before proceeding further in the code.

Implicit wait:An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0

Thread.sleep()In sleep code will always wait for mentioned seconds inside the parentheses even in case working page is ready after 1 sec. So, this can slow the tests.

  1. Don’t Use a Specific Driver
    • Using Parameter notes you can easily handle different browser types and prepare your test for cross-browser and parallel execution.
    • Using JUnit, you have @RunWith(Parameterized.class) with @Parameters (browser).
    • Using TestNG you have @Parameters(“browser”) with XML configuration.
  2. Taking Screen Shots and Logs from HTML Sources
    • It will easily help the investigation in case something goes wrong. Basically, you have to create a kind of Watcher/ Listener for your tests.
    • In JUnit you can use @Rule.
    • In TestNG you can use extends TestListenerAdapter and use a XML configuration <listener> and org.testng.Reporter.log
  3. IE Not Working
    • The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
    • You must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose “Internet Options…” from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled “Enable Protected Mode”.
  4. Data Driven Testing
    • To use the same test with different inputs due to test a considerable variety of scenarios without code changing.

Selenium is a powerful tool, which can be leveraged effectively by developers and testers. With its useful features, Selenium serves as a key tool for browser compatibility testing as well as system functional testing. Using Selenium helps clients leverage benefits of custom Selenium Test Automation frameworks.

By leveraging proprietary test accelerators, clients can jump start test automation and reduce automation cycle-time. Selenium Test Automation Framework is a proven and tested framework having 90+ function libraries to directly jump start your test automation projects or complement your existing test automation suite. It is indeed strong when compared to other available tools for automation testing.