Selenium-based Automated Testing
Selenium consists of four components:
- Selenium IDE
- Selenium RC
- Selenium WebDriver
- Selenium Grid
Selenium Integrated Development Environment is a Chrome and Firefox plugin that can log interactions in the browser and generate its code in programming languages mentioned above, as well as Selenese which is Selenium’s own scripting language (yes, Selenium has its own scripting language!).
Selenium WebDriver, also known as a Selenium 2.0, is the most important tool of the Selenium Suite. Selenium WebDriver formed as a Selenium RC upgrade, and it does not require any manual process like Selenium Server, instead, there is direct communication between code and browser. Selenium WebDriver consists of:
- API – Application Programming Interface. Ports test scripts written in Ruby, Java, Python, etc. to Selenese (Selenium’s own scripting language), through bindings.
- Driver – Executable module that opens up a browser instance and runs the test script.
- Framework – Support libraries for integration with natural or programming language test frameworks, like Selenium with Cucumber or Selenium with TestNG.
The way how Selenium WebDriver works:
The WebDriver protocol has a local end named client which sends the commands (test scripts) to a browser-specific driver. The driver then executes these commands on its browser instance. So, if the test script calls for execution on Chrome and Firefox, the ChromeDriver will execute the test on Chrome; the GeckoDriver will execute the test on Firefox.
Note: Test scripts execute only when the WebDriver’s client and browser driver are connected. It doesn’t have to be on the same device. However, to enable test execution on multiple remote drivers, you need RemoteWebDriver and the Grid.
Selenium Grid is the last component of the Selenium Suite and it is used for the parallel testing or distributive testing. It allows us to execute test scripts on different machines at the same time.
The Architecture of Selenium Grid:
In Grid one of the systems is created as Hub. Hub works as a central point controlling all the nodes, it accepts access requests from WebDriver client. Nodes are an actual machine on which execution is done and contains a native OS, browsers and RemoteWebDriver.
The way how Selenium Grid works:
WebDriver-client executes the test on a faraway device through RemoteWebDriver. RemoteWebDriver is like a regular WebDriver, except its two components are the Client (your test script) and Server (a Java servlet that actually executes the test on the remote device).
In your test script, you define ‘desired capabilities’ (device, platform, browser, etc.) of the node where the test will execute. The Hub receives test script, runs through the registered nodes to find the one that matches the desired capabilities, and assigns the test to it for the execution.
Advantages and Disadvantages of Selenium
Advantages of Selenium
- Selenium is an open source software, anybody can download the source code and use it, modify the source code according to company requirements, but selling modified code is not allowed.
- Selenium supports various programming languages to write test scripts – Java, C#, Perl, Python, Ruby and PHP. Although it supports all mentioned languages, only one language can be used at the time. Most of the Selenium Testers use Java (nearly 70%).
- Selenium supports all currently available operating systems (Mac, Windows and Linux).
- Selenium supports various Browsers (Firefox, Google Chrome, Internet Explorer, Safari, etc.)
- Using Selenium Grid, we are able to execute tests in parallel, so that we can reduce the test execution time.
Disadvantages of Selenium
- Since Selenium is an open source software, nobody providing reliable technical support.
- With Selenium we can automate Computer Web Applications and Mobile Web Applications, but we cannot automate Computer Desktop Applications, Mobile Native Applications and Mobile Hybrid Applications.
- Selenium WebDriver does not have built in Results Report facility, we need to use JUnit or TestNG Testing Framework to generate Test Reports.
- There is no support for running tests in parallel on a single computer.
- Selenium + TestNG/JUnit is not the complete, comprehensive solutions to fully automate testing of your web application. You need different libraries (POI API, GSON, Extent Reports) to make it a complete solution for a testing framework. Managing multiple dependencies is difficult and requires extra maintenance work that everyone wants to avoid. A good dependency management tool such as Maven, Gradle or NPR can make this task easier.
In conclusion, the key holdups in adopting traditional QA methods are the issues faced by functional and business teams in understanding automation scripts. Additional effort is required to make them available to non-technical users, leading to reduced collaboration between the functional specialists and automation teams.
As you could see, Selenium has pros and cons and depending on your type of software you should consider which approach is the best. In our next article, we will introduce you with Scriptless Test Automation and its tools.
You can read about this also here.