Selenium
What is Selenium?
Selenium is a portable framework for testing web applications. Selenium provides a playback tool for authoring functional tests without the need to learn a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C#, Groovy, Java, Perl, PHP, Python, Ruby and Scala. The tests can then run against most modern web browsers. Selenium runs on Windows, Linux, and macOS. It is open-source software released under the Apache License 2.0.
Why Selenium?
The current industry trends have shown that there is a mass movement towards automation testing. Hence a cluster of repetitive manual testing scenarios has raised a demand to bring in the practice of automating these manual scenarios.
There are several Benefits of implementing Automation Test; let’s take a look at them:
Supports execution of repeated Test Cases
Aids in testing a large Test Matrix
Enables parallel execution
Encourages unattended execution
Improves accuracy thereby reducing human-generated errors
Saves time and money
All of these benefits result in the following:
High ROI
Faster GoTo market
There are several Automation testing benefits which are well understood and largely talked about in the software testing industry.
One of the most commonly asked questions that come with this are –
What is the best tool for me to get my tests automated?
Is there a cost involved in it?
Is it easy to adapt?
One of the best answers to all the above questions for automating web-based applications is Selenium. Because:
It’s an open-source
It has a large user base and helping communities
It has multi-browser and platform compatibility
It has active repository developments
It supports multiple language implementations
First Glance at Selenium
Selenium is one of the most popular Automated Testing suites. Selenium is designed in such a way to support and encourage Automation Testing of functional aspects of web-based applications and a wide range of browsers and platforms. Due to its existence in the open-source community, it has become one of the most accepted tools amongst the testing professionals.
Selenium supports a broad range of browsers, technologies, and platforms.
Selenium Components
Selenium is not just a single tool or a utility, its rather a package of several testing tools, hence it is referred to as a Suite. Each of these tools is designed to cater to different testing and test environment requirements.
The suite package constitutes of the following set of tools:
Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC)
Selenium WebDriver
Selenium Grid
Selenium RC and WebDriver, combined together are popularly known as Selenium 2. Selenium RC alone is also referred to as Selenium 1.
Brief Introduction To Selenium Versions
Selenium Core
Selenium is a result of the continuous efforts by an engineer named Jason Huggins from ThoughtWorks. Being responsible for the testing of an internal Time and Expenses application, he realized the need for an automation testing tool in order to get rid of repetitive manual tasks without compromising quality and accuracy.
As a result, he built a JavaScript program, named as “JavaScriptTestRunner†in early 2004 that could automatically control the browser’s actions which seemed very much similar to that of a user communicating with the browser.
Henceforth, Jason started demoing the tool to a vast audience. Eventually, the discussions were laid out to categorize this tool in an open-source category and its potential to grow as a re-usable testing framework for other web-based applications.
The tool was later acclaimed with the name “Selenium Coreâ€.
Selenium IDE (Selenium Integrated Development Environment)
Selenium IDE was developed by Shinya Kasatani. While studying Selenium Core, he realized that this JavaScript code can be extended to create an integrated development environment (IDE), which can be plugged into Mozilla Firefox. This IDE was capable of recording and playing back the user actions on a Firefox instance to which it was plugged-in. Later on, Selenium IDE became a part of Selenium Package in the year 2006. Later this tool turned out the great value and potential to the community.
Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback features make it exceptionally easy to learn with minimal acquaintances to any programming language. With several advantages, a few disadvantages accompanied Selenium IDE, thus making it inappropriate to be used in case of more advanced test scripts.
Advantages and Disadvantages of Selenium IDE:
The disadvantages of IDE are really not disadvantages of Selenium, in reality. Rather they are just limitations to what IDE could achieve. These limitations can be overcome by using Selenium RC or WebDriver.
Selenium RC (Selenium Remote Control)
Selenium RC is a tool written in Java to allow a user to construct test scripts for a web-based application in any programming language he/she chooses. Selenium RC came as a result to overcome the various disadvantages incurred by Selenium IDE or Core.
Loopholes and restrictions which were imposed while using Selenium Core made it difficult for the user to leverage the benefits of the tool to its totality. Thus it made the testing process a cumbersome and a far-reaching task.
One of the crucial restrictions was the Same Origin Policy.
Problem With Same Origin Policy:
The problem with Same Origin Policy is, it disallows to access the DOM of a document from an origin that is different from the origin we are trying to access the document.
Origin is a sequential combination of scheme, host, and port of the URL. For example, for the URL http://www.seleniumhq.org/projects/, the origin is a combination of HTTP, seleniumhq.org, 80 correspondingly.
Thus Selenium Core (JavaScript Program) cannot access the elements from an origin that is different from where it was launched.
For Example, if I have launched the JavaScript Program from “http://www.seleniumhq.org/â€, then I would have been able to access the pages within the same domain such as “http://www.seleniumhq.org/projects/†or “http://www.seleniumhq.org/download/â€. The other domains like google.com, yahoo.com would no more be accessible.
Thus, to test any application using Selenium Core, one has to install the entire application on the Selenium Core as well as a web server to overcome the problem of the same-origin policy.
So, In order to govern the same-origin policy without the need of making a separate copy of Application under test on the Selenium Core, Selenium Remote Control was introduced. While Jason Huggins was demoing Selenium, another fellow colleague at ThoughtWorks named Paul Hammant suggested a workaround of the same-origin policy and a tool that can be wired up with a programming language of our choice. Thus Selenium RC came into existence.
Unlike Selenium IDE, Selenium RC supports a wide range of browsers and platforms.
Workflow Description
The user creates a test script in the desired programming language.
For every programming language, there is a designated client library.
Client library deports the test commands to the selenium server.
Selenium server deciphers and converts the test commands into JavaScript commands and sends them to the browser.
The browser executes the commands using Selenium Core and sends the results back to the Selenium server
Selenium server delivers the test results to the client library.
There are a few pre-requisites to be in place before creating Selenium RC scripts:
A Programming Language – Java, C#, Python etc.
An Integrated Development Environment –Eclipse, Netbeans etc.
A Testing Framework (optional) – JUnit, TestNG etc.
And Selenium RC setup off course
Advantages and Disadvantages of Selenium RC:
Please refer the following figure to more about the advantages and disadvantages of Selenium RC.
Selenium Grid
With selenium RC, the life of a tester has always been positive and favorable until the emerging trends raised a demand to execute the same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably. Thus, catering these requirements Selenium Grid was brought into the picture.
Selenium Grid was introduced by Pat Lightbody in order to address the need for executing the test suites on multiple platforms simultaneously.
Selenium WebDriver
Selenium WebDriver was created by yet another engineer at ThoughtWorks named Simon Stewart in the year 2006. WebDriver is also a web-based testing tool with a subtle difference with Selenium RC. Since the tool was built on the fundamental where an isolated client was created for each of the web browsers; no JavaScript Heavy lifting was required. This led to a compatibility analysis between Selenium RC and WebDriver. As a result of which a more powerful automated testing tool was developed called Selenium 2.
WebDriver is clean and purely an object-oriented framework. It utilizes the browser’s native compatibility to automation without using any peripheral entity. With the increasing demand, it has gained a large popularity and user-base.
1) Selenium is an Open Source Software.
(All Selenium Projects (Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid) released under the Apache 2.0 license, It is free to use, anybody can download the source code and use, modify the source code according our company requirements, but selling modified code is not allowed.)
2) Selenium supports various programming languages to write programs (Test scripts)
(Selenium supports,
Java,
C#,
Perl,
Python,
Ruby
PHP
Note:
We can use any one the above languages, most of the Selenium Testers using Java (nearly 77%).
Selenium IDE (one of the tool in Selenium’s Tool suite) doesn’t support any programming.
UFT (Formerly QTP) supports VBScript only to write Test Scripts.)
3) Selenium supports various operating systems (MS Windows, Linux, Macintosh etc…)
(Once we create Test Cases on any Operating Environment (Ex: MS Windows), they can be executed on other supported Operating Environments (Ex:Linux, Macintosh Etc… easily)
4) Selenium supports various Browsers (Mozilla Firefox, Google Chrome, IE, Opera, Safari etc…)
(Once we create Test cases then execute the Test Cases using all Popular Browsers without any changes in Test Cases. Browser driver only varies from one Browser to another Browser but Test cases are same.
Note: Selenium IDE (one of the tool in Selenium’s Tool suite) supports Mozilla Firefox Browser only.)
5) Selenium supports Parallel Test Execution.
(Using Selenium Grid we can execute Tests in Parallel, so that we can reduce the Test execution Time).
6) Selenium uses less Hardware resources.
(When it compares to Vendor Tools like UFT, RFT, SilkTest etc… Selenium requires less Hardware Resources)
1) No reliable Technical Support from anybody.
(Since It is Open Source software nobody providing reliable technical support, if it is UFT/QTP Vendor (HP) provides Technical Support)
2) It supports Web based applications only.
(Selenium automates Web browsers only, using Selenium we can automate Computer Web Applications and Mobile Web Apps, but Selenium doesn’t support Computer Desktop Applications, Mobile Native Applications and Mobile Hybrid Applications.)
3) Difficult to use, takes more time to create Test cases.
(Selenium WebDriver (Powerful tool in Selenium’s Tool suite) has Programming interface only, no IDE, so we have to write steps for each and every task they take more time.
If it is UFT/QTP has Programming interface as well as IDE, we can Tool features (Ex: Recording, Checkpoints, Data Table etc…) and VBScript features (Ex: Conditional statements, Loop Statements, Functions etc…) to create Tests/Test Scripts.)
4) Difficult to Setup Test Environment when it compares to Vendor Tools like UFT, RFT, SilkTest etc…
(Selenium uses various tools and plug ins to support Test Automation, we need configure them manually, if it vendor tool like UFT/QTP we just download and install the tool (all required components were integrated by the vendor))
5) Limited support for Image Testing.
6 New features may not work properly.
(Since it is open source software nobody is responsible for new features usage, they may or may not work properly, it is vendor tool (Ex: UFT or RFT or SilkTest), vendor is responsible for new features usage.)
7) No Test Tool integration for Test Management.
(No Tool available in the Selenium’s Tool suite to support Test Management, we have to choose any tool from the market, If it is UFT, ALM is there for integration of Project/Test Management tasks.)
8) No Built-in Reporting facility.
(Selenium WebDriver doesn’t have built in Result Report facility, we need to take help from either JUnit ot TestNG Testing Framework to genrerate Test Reports.
UFT/QTP has built-in Result Reporting facility (Test Result Viewer), UFT provides Test Result for every Test iteration.)
Selenium 3
Selenium 3 is an advanced version of Selenium 2. It is a tool which is focused on automation of mobile and web applications. Stating that it supports mobile testing, we mean to say that the WebDriver API has been extended to address the needs of mobile application testing. The tool is expected to be launched soon in the market.
Environment And Technology Stack
With the advent and addition of each new tool in the Selenium suite, environments and technologies become more compatible. Here is an exhaustive list of environments and technologies supported by Selenium Tools.
Supported Browsers
The Selenium framework officially supports the following browsers:
There is also a set of specialized browsers out there typically used in development environments. We can make use of some of these browsers for automation purposes also, and Selenium ties in support for the following specialized drivers:
Supported Programming Languages
Supported Operating Systems
Supported Testing Frameworks
Conclusion
Here are the cruxes of this article.
Selenium is a suite of several automated testing tools, each of them catering to different testing needs.
All these tools fall under the same umbrella of an open-source category and support only web-based testing.
Selenium suite is comprised of 4 basic components; Selenium IDE, Selenium RC, WebDriver, and Selenium Grid.
The user is expected to choose wisely the right Selenium tool for his/her needs.
Selenium IDE is distributed as a Firefox plug-in and it is easier to install and use. The user is not required to possess prior programming knowledge. Selenium IDE is an ideal tool for a naive user.
Selenium RC is a server that allows a user to create test scripts in the desired programming language. It also allows executing test scripts within the large spectrum of browsers.
Selenium Grid brings out an additional feature to Selenium RC by distributing its test script on different platforms and browsers at the same time for execution, thus implementing the master-slave architecture.
WebDriver is a different tool altogether that has various advantages over Selenium RC. The fusion of Selenium RC and WebDriver is also known as Selenium 2. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
Selenium 3 is the most anticipated inclusion in the Selenium suite which is yet to be launched in the market. Selenium 3 strongly encourages mobile testing.
To learn more about Selenium visit:
https://www.selenium.dev/documentation/en/getting_started/
https://www.udemy.com/course/selenium-real-time-examplesinterview-questions/