Selenium is an open-source tool that is used for test automation. It is licensed under Apache License 2.0. Selenium is a suite of tools that helps in automating only web applications. This tutorial will give you an in-depth understanding of Selenium and its related tools and their usage.
Before proceeding with this tutorial, you should have a basic understanding of Java or any other object-oriented programming language. In addition, you should be well-versed with the fundamentals of testing concepts.
Selenium is not just a single tool but a set of tools that helps testers to automate web-based applications more efficiently. Let us now understand each one of the tools available in the Selenium suite and their usage.
The Selenium-IDE (Integrated Development Environment) is an easy-to-use Firefox plug-in to develop Selenium test cases. It provides a Graphical User Interface for recording user actions using Firefox which is used to learn and use Selenium, but it can only be used with Firefox browser as other browsers are not supported.
However, the recorded scripts can be converted into various programming languages supported by Selenium and the scripts can be executed on other browsers as well. The following table lists the sections that we are going to cover here.
* Download Selenium IDE
* Selenium IDE Features
* Creating Selenium IDE Tests
* Selenium IDE Script Debugging
* Inserting Verification Points
* Selenium Pattern Matching
* Selenium User Extensions
* Different Browser Execution
In order to develop Selenium RC or WebDriver scripts, users have to ensure that they have the initial configuration done. Setting up the environment involves the following steps.
Download and Install Java
We need to have JDK (Java Development Kit) installed in order to work with Selenium WebDriver/Selenium.
Download and Configure Eclipse
Prepare Eclipse IDE to develop Selenium WebDriver. (More)
Configure FireBug and FirePath
To work with Selenium RC or WebDriver, we need to locate elements based on their XPath or ID or name, etc. In order to locate an element, we need tools/plugins. (More)
Configure Selenium RC
Now let us look at how to configure Selenium Remote control. We will understand how to develop scripts with Selenium RC in later chapters, however for now, we will understand just the configuration part of it.
Step 1 : Navigate to the Selenium downloads section http://www.seleniumhq.org/download/ and download Selenium Server by clicking on its version number as shown below.
Step 2 : After downloading, we need to start the Selenium Server. To do so, open command prompt and navigate to the folder where the downloaded JAR file is kept as shown below. To start the server, use the command 'java -jar <<downloaded jar name >>' and if java JDK is installed properly, you would get a success message as shown below. Now we can start writing Selenium RC scripts.
Or if your want to use Docker to launch Selenium Service, below is an example:
Configure Selenium WebDriver
Now let us look at how to configure Selenium WebDriver. We will understand how to develop scripts with Selenium WebDriver in later chapters, however for now, we will understand just the configuration part of it.
Step 1 : Navigate to the selenium downloads section http://www.seleniumhq.org/download/ and download Selenium WebDriver by clicking on its version number as shown below.
Step 2 : The downloaded file is in Zipped format and one has to unzip the contents to map it to the project folder.
Step 3 : Import the jar files into project
(Source) Selenium Remote Control (RC) allows us to write automated web application UI tests with the help of full power of programming languages such as Java, C#, Perl, Python and PHP to create more complex tests such as reading and writing files, querying a database, and emailing test results.
Selenium RC Architecture
Selenium RC comes in two parts.
Now let us write a sample script using Selenium Remote Control. Let us use http://www.calculator.net/ for understanding Selenium RC. We will create a sample RC case to open Google page and maximize the browser for testing Selenium Server Service availability.
Step 1 : Start Selenium Remote Control (with the help of command prompt).
Step 2 : Create Eclipse Project, Import Selenium Client Libraries and try below sample code: (Groovy)
WebDriver is best explained with a simple architecture diagram as shown below.
Selenium RC Vs WebDriver
Scripting using WebDriver
Now it is time to code. The following script is easier to understand, as it has comments embedded in it to explain the steps clearly. Please take a look at the chapter "Locators" to understand how to capture object properties.
Most Used Commands
The following table lists some of the most frequently used commands in WebDriver along with their syntax.
* Selenium wiki - Remote WebDriver
* Stackoverflow - Set chrome.prefs with python bindi...g for selenium in chromedriver
* Stackoverflow - RemoteWebDriver Chrome - start maximized
* Stackoverflow - How to build remote Webdriver for Chrome