Selenium is the most powerful free tool for automating functional testing of web applications. It is based on an imitation of the actions of an ordinary user when working in a browser. The developer is required to think over and write a script for user actions and checks, and Selenium will reproduce it in a browser. This also means that Selenium can be used not only for testing but also for performing any frequently repeated routine work for the web. To be more precise, Selenium is not even a tool, but a whole set of tools, each of which provides its own functionality for automation.
Main components of Selenium
The choice of a specific tool or several of them depends on the needs of the developer and the characteristics of the project that needs to be tested.
It is a plug-in for Mozilla Firefox that records and reproduces user actions in a browser. Selenium IDE does not require a deep programming knowledge from the tester, in most cases, it independently generates code and can rightfully be considered the easiest tool to use. Using the IDE, you can quickly become familiar with the command language and understand how Selenium works. Selenium IDE is mainly used to quickly create small scripts or to perform any routine. However, it is not possible to implement complex logic or validation in IDE scripts. You can also use Selenium IDE when writing tests in other tools to quickly get the identifiers of the elements on the page. An important feature of the Selenium IDE is that you can export the finished script in the format of any programming language supported by Selenium for JUnit or Nunit.
It is a set of libraries of API functions for various programming languages which allows you to write a program to control the browser in the selected programming language. WebDriver API is not tied to test frameworks, this allows you to use any unit testing frameworks of your choice. The library provides drivers for working in various browsers (Mozilla Firefox, Google Chrome, Opera, Internet Explorer, as well as Android and iPhone mobile browsers), as well as HtmlUnitDriver, which is the fastest cross-platform solution that allows you to run tests without rendering and launching the browser. Using Selenium WebDriver, you can create your own full-fledged testing framework.
Selenium RC has the same properties as WebDriver. It is also a set of libraries for browsers, but taking into account the narrow focus, namely, the possibility of remote control. Therefore, the arsenal of RC capabilities is much lower. Nevertheless, this version has lost its relevance and therefore is practically not in demand among users. At the moment, WebDriver is considered the main solution package.
Previously, Selenium Server was required to run Selenium RC, now if you intend to use only WebDriver, then Selenium Server will not be useful to you. But Selenium Server may be needed to run tests on remote machines with different operating systems and installed browsers.
This solution is presented as a cluster of servers under the control of the Selenium project. With this tool, you can manage a group of servers and configure the network at your discretion. Thus, you have the opportunity to launch the number of browsers that is necessary to complete the task.
What is Selenium good for?
There are a lot of Selenium benefits among which there are the two main ones:
- By creating test scenarios of Selenium that reproduce user actions, you test the application from the perspective of the end-user.
- Running tests in different browsers will make it easier to determine the Internet browser incompatibility.
Creating a project to develop tests using Selenium WebDriver
The steps required to create a software project that allows you to develop tests using Selenium depend on which programming language you are going to do.
Selenium Java combination
The easiest way for this programming language is to use Maven to create a project. Maven will automatically download the Selenium 2.0 Java client library along with all the dependencies and create a project using the pom.xml file (project configuration file). After you have done this, you can import the project into your preferred development environment (IDE) - IntelliJ IDEA or Eclipse. Another way to write tests using Selenium Webdriver and Java as a programming language is to download the Selenium Webdriver JAR files from the Selenium website.
Selenium PHP combination
To start automatic Selenium testing you need php-webdriver, a modern, powerful library for managing the browser by issuing Selenium commands.
php composer.phar require facebook/webdriver php composer.phar require phpunit/phpunit php composer.phar require rmccue/requests
Selenium C # combination
Starting with version 2.2.0, Selenium is supplied as a set of signed DLLs and all libraries on which Selenium depends. Prior to version 2.2.0, all Selenium DLLs were unsigned. To include Selenium in your project, simply download the latest version of the selenium-dotnet zip archive from https://code.google.com/p/selenium/downloads/list. Extract the contents of the archive and add links to the unzipped DLLs to your project.
Selenium Ruby combination
Ruby has borrowed all the best from other programming languages, from smalltalk to Java, from Perl to Python. In order to be able to run Selenium testing in Ruby, you need to execute the following commands:
gem install selenium-webdriver
gem install rest-client
gem install test-unit
Selenium Python combination
If you use Python to automate testing, then most likely you are already familiar with how the development of applications on it occurs. At the moment, probably more than tens of thousands of different libraries have been invented for it. The main advantage of this language is the simplicity of its syntax, as there is no “;" at the end of the line; no need to indicate the type of variable every time. To add Selenium to your Python environment, run the following command in a command line:
pip install selenium
Selenium Node JS combination
Make sure that you have all the necessary libraries installed before starting Selenium testing with Node JS.
npm install -g selenium-webdriver
List of online tools for web testing
Comparium is a user-friendly online tool for web testing. With its help, you can test your site in order to find any potential visual incompatibility in any Internet browser and even with specifying the platform. Just enter the URL of the site you want to test, wait for a few minutes and you will get screenshots of this site taken in each of the selected browsers. Comparium supports most popular browsers as well as operating systems. So, if you want to test the site in order to be sure that everything looks correct and without any bugs, then Comparium is a great choice.
With LambdaTest, you can easily test your public or locally hosted website in 1400+ different browsers, web browser versions, operating systems, and resolutions. Thanks to this solution, you can be sure that your customers will get the perfect pixel experience, no matter what device they are using. The app has a lot of useful features, including interactive testing and debugging in live remote browsers, execution of resolution Display Testing and automatic creation of screenshots on several devices, performing smart user interface testing, etc.
In this multifunctional service, you can also check the cross-browser site online. The number of supported browsers, screen sizes, and devices is huge - about 700 combinations. SauceLabs estimates the compatibility of not only PC browser, but also mobile devices. The service is paid, but there is a free period of 14 days. This online web testing tool also offers the possibility of unlimited manual testing.
Browsera is a really multifunctional tool that allows you to test not only the cross-browser layout, but also the performance of scripts in different situations, the display of dynamic pages, the degree of site security etc. This solution automatically notifies you of possible problems that are detected when running web testing. Instead of checking each screenshot, you will receive a report that will explain in detail which pages of your site have problems.
Frequently Asked Questions: Selenium tutorial
Selenium is an open-source and free to use tool. You do not need to pay for a license to use it.
- Cross-browser compatibility (Firefox, Chrome, Internet Explorer, Safari, etc.);
- Support for a large number of programming languages (Java, C #, Ruby, Python, Pearl, etc.);
- Compatible with all major platforms (Windows, Mac OS, Linux, etc.);
- A huge number of users and, accordingly, massive public support;
- Ability to automate scripts;
- Test distribution support;
- Regular and recent library enhancements;
- Performs tests in parallel using Selenium nets;
- Supports mobile devices;
- Can be extended to various technologies that provide the DOM.
Since Selenium is intended only for testing web applications, there are some limitations in its use:
- Mobile apps cannot be tested with Selenium;
- Desktop applications cannot be tested with Selenium;
- Captcha and barcode readers cannot be tested with Selenium;
- To generate reports, the user needs to use external tools, such as TestNG or jUnit;
- Knowledge of a programming language is necessary for writing scripts in Selenium.
Selenium - a set of tools for automated testing, consists of the following components:
- Selenium IDE (Integrated Development Environment) is a Firefox plugin that allows testers to record their actions by following the workflow they need to test.
- Selenium RC (Remote Control) was the flagship testing system, which allowed more than simple browser actions and linear execution. It used the full power of programming languages such as Java, C #, PHP, Python, Ruby, and PERL to create more complex tests.
- Selenium WebDriver - is the successor to Selenium RC, which sends commands directly to the web browser and retrieves the results.
- Selenium Grid is a tool used for parallel testing on different computers and different browsers at the same time, which minimizes runtime.
List of drivers used to automate the Internet browser:
- Firefox driver;
- Remote WebDriver.
Mobile testing drivers supported by Selenium WebDriver:
TestNG - written in Java, a testing framework based on the advantages of JUnit and NUnit, which makes it equally convenient for both developers and testers. Here are some new features that make it more productive and easier to use:
- Multithreaded code security testing;
- Support data-driven testing;
- Parameter Support;
- Support for a variety of tools and plugins (Eclipse, IDEA, Mave, etc.);
- At run time and logging the default JDK installation;
- Dependent methods for server-side application testing;
- Flexible configuration for testing.
Selenium Grid has the following advantages:
- Cross-browser testing.
- Parallel execution of test cases.
- Multi-platform testing.
There are several reasons for test crashes in Selenium WebDriver:
- Selenium WebDriver pending access did not appear on the web page and operation timed out.
- Selenium WebDriver is trying to access a nonexistent object.
- Selenium WebDriver cannot find the object because the locator has been changed.
A few reasons why Python is better than Java for automated testing in Selenium:
- Python is simpler and more compact than Java.
- Java uses traditional curly braces to start and end blocks, while Python uses padding.
- Java uses static typing, while Python uses dynamic typing.