Selenium-based Automated Testing
Selenium is an open-source Automated Testing tool which provides a single interface to help you write test scripts in programming languages like Java, JavaScript, Python, Ruby, etc. to test web-based applications. Selenium is a free Automated Testing suite for web applications across different browsers and platforms. It is quite similar to HP Quick Test Pro (QTP now UFT) only that Selenium focuses on automating web-based applications.
Selenium consists of four components:
- Selenium IDE
- Selenium RC
- Selenium WebDriver
- Selenium Grid
Selenium IDE
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 RC
Selenium Remote Control, also known as Selenium 1, was the first tool of Selenium Suite. Selenium RC is a server, written in Java, that accepts commands for the browser via HTTP. All the browsers which support JavaScript can be automated using Selenium RC.
In Selenium RC there is a manual process called Selenium Server which acts as a middleman between the code and the browser, and it is mandatory to start before the execution. The commands (API’s) are sent to Server which interprets the command and converts it into JavaScript and then JavaScript is injected to the browser. After that, the browser executes the JavaScript and responds to a Server, which again interprets the command and returns the code to the respective language.
Selenium WebDriver
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.
- Library houses the API and language-specific bindings. Although plenty of third-party bindings exist to support different programming languages, the core client-side bindings supported by the main project are: Selenium Java (as selenium jar files), Selenium Ruby, Selenium dotnet (or Selenium C#, available as .dll files), Selenium Python, and Selenium JavaScript (Node).
- 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
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.