Seleneium
Seleneium
Dr. D. P. Mohapatra
Associate Professor
Department of Computer Science & Engineering
National Institute of Technology, Rourkela-769008
[email protected]
Plan of the Talk
Introduction to Selenium
Selenium Integrated Development Environment (IDE)
Installation of Selenium IDE
Using Selenium IDE
Selenium Remote Control (RC)
Selenium Web Driver
04 January 2017 2
Overview of Selenium
04 January 2017 3
Selenium contd….
04 January 2017 4
Selenium: History
04 January 2017 5
Selenium: History
04 January 2017 6
Story about Selenium
04 January 2017 7
Story about Selenium
Selenium.
04 January 2017Selenium is used for treating Mercury Poisoning 8
Components of Selenium
04 January 2017 9
Components of Selenium Contd…
Selenium IDE
Selenium IDE provides facility to export recorded script in
many languages like HTML, Java, Ruby, Python, C#, Junit
and TestNG.
Script created for application testing is called test case in
selenium IDE language and set of test cases is called test
suite in selenium IDE.
It provides record and playback facility to regression test in
any web application.
04 January 2017 10
Components of Selenium Contd…
Selenium RC
This is the older version of selenium.
It works on multiple browsers.
04 January 2017 11
Components of Selenium Contd…
Webdriver
Web driver is the new version of selenium.
It also supports Android and Iphone Testing.
Grid
Grid is used to run test cases parallely on multiple
machines and browsers.
04 January 2017 12
Comparison Table
04 January 2017 13
Purpose of use
04 January 2017 14
Purpose of use
04 January 2017 15
Hardware Requirements
Operating system(s)
▪ Windows - XP, 2003, 2003 Server, Windows Vista,
Windows 7, Windows 2008
▪ Linux
▪ MacOS - Leopard, Snow Leopard.
Memory: Minimum 2 GB RAM.
04 January 2017 16
Hardware Requirements
04 January 2017 17
Software Requirements
Firefox
Please be sure you have a recent version of Firefox
installed.
Java Script
The Selenium Remote Control server runs on Java Script.
It thus runs on any operating system that supports a recent
Java implementation.
04 January 2017 18
Software Requirements
04 January 2017 19
Selenium Integrated
Development Environment (IDE)
04 January 2017 20
Selenium Integrated Development
Environment (IDE)
04 January 2017 21
Selenium Integrated Development
Environment (IDE)
04 January 2017 22
Selenium Integrated Development
Environment (IDE)
Start and
Replay Stop
Toolbar Recording
Selenese
Script
Editor
Accessor
y
Area
Selenium
Log
04 January 2017 23
Installation of Selenium IDE
04 January 2017 24
Installation of Selenium IDE contd….
04 January 2017 25
Installation of Selenium IDE contd….
Click on "Allow’’.
04 January 2017 26
Installation of Selenium IDE contd….
04 January 2017 27
Installation of Selenium IDE contd….
04 January 2017 28
Installation of Selenium IDE contd….
04 January 2017 29
Installation of Selenium IDE contd….
The Firefox Add-ons window pops up, first shows a progress bar, and
when the download is complete, displays the window shown
04 January 2017 30
Installation of Selenium IDE contd….
04 January 2017 31
Installation of Selenium IDE contd….
04 January 2017 32
Installation of Selenium IDE contd….
Also, you will see the Selenium-IDE icon in the toolbar as shown
04 January 2017 33
Installation of Selenium IDE contd….
04 January 2017 34
Elements in Selenium IDE Toolbar
Speed Control
04 January 2017 36
Recording a Selenium Test Case
04 January 2017 37
Running Your First Selenium Script
Once the test is run you can view the test log in the bottom of
the IDE window
04 January 2017 38
Selenium IDE Test Case Pane
In Selenium IDE, you can open more than one test case at a
time.
The test case pane shows you the list of currently opened
test cases.
When you open a test suite, the test case pane will
automatically list all the test cases contained in it.
04 January 2017 39
Selenium IDE Test Case Pane
04 January 2017 40
Selenium IDE Editor
You can think of the editor as the place where all the actions
happen. It is available in two views:
1. Table
2. Source.
04 January 2017 41
Selenium IDE Editor
Table View
• This is where you create and modify Selenese commands.
• After playback, each step is color-coded.
04 January 2017 42
Selenium IDE Editor
Source View
• It displays the steps in HTML (default) format.
• It also allows you to edit your script just like in the
Table View.
04 January 2017 43
Using Selenium IDE
04 January 2017 44
Using Selenium IDE
04 January 2017 45
Using Selenium IDE
04 January 2017 46
Using Selenium IDE
04 January 2017 47
Using Selenium IDE
04 January 2017 48
Using Selenium IDE
04 January 2017 49
Using Selenium IDE Contextual Menu
04 January 2017 50
Using Selenium IDE Contextual Menu
Like the previous example, create a new test case and hit
‘record’. Then go to Google.com, type in a query (‘automated
testing’) and wait for the search results page to load.
After the results page opens, right click on the main search field
on Google. A contextual menu will pop up with a list of actions
you can perform.
04 January 2017 51
Using Selenium IDE Contextual Menu
Contd….
04 January 2017 52
Using Selenium IDE Contextual Menu
contd….
04 January 2017 53
Using Selenium IDE Contextual Menu
contd….
You can also see a list of all available commands on the same
menu. This will give you a huge list of commands to choose from
like ‘verifyTitle’, ‘verifyValue’, ‘open’, ‘storeTitle’, etc.
04 January 2017 54
Using Selenium IDE Contextual Menu
contd….
Using these different options, you can create automated tests to
check different elements in a web app.
For this example, if you stop the recording and play back the
test, Selenium IDE will first open Google.com, type in the
desired query, and finally, verify that the query has been entered
into the search bar.
04 January 2017 55
Selenium Remote
Control (RC)
04 January 2017 56
Selenium RC Components
The Selenium Server
which launches and kills browsers, interprets and
runs the Selenese commands passed from the test program,
and
• acts as an HTTP proxy, intercepting and verifying HTTP
messages passed between the browser and the AUT.
04 January 2017 57
Selenium RC Components
Client libraries
which provide the interface between
• each programming language and
• the Selenium RC Server.
04 January 2017 58
Selenium RC Architecture
04 January 2017 59
Selenium RC Architecture
04 January 2017 60
Selenium Server
04 January 2017 61
Selenium Server
04 January 2017 62
Client Libraries
04 January 2017 63
Client Libraries
04 January 2017 64
Client Libraries
04 January 2017 65
Installation steps for Selenium RC
The pre-requisites to install RC are to have Java 1.5 or above version and Eclipse
IDE installed in your machine.
1. You can download and install Java URL from the following
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. You can download and install Eclipse from the following
URL:http://www.eclipse.org/downloads/download.php?file=/technology/epp/
downloads/release/helios/R/eclipse-jee-helios-win32.zip
3. Extract the Zip Folder and run the eclipse.exe File. There is no separate
installation required rather than running the .Exe file.
4. Now go to http://seleniumhq.org/download/ and click on Download
under Selenium Server section
04 January 2017 66
Installation steps for Selenium RC
04 January 2017 67
Installation steps for Selenium RC
5. Click download link under selenium Client drivers for your desired language.
(e.g. To download Selenium Java client drivers, click on Download link for
Java)
04 January 2017 68
Installation steps for Selenium RC
04 January 2017 69
Installation steps for Selenium RC
6. Extract the Client drivers into to your Local disk.
7. Open Eclipse IDE.
8. Create a New Project (Right Click on Project
Explore-->New-->select Java Project-->Give the name and click on
Finish.
9. Right click on the Project-->Build Path-->Configure Build Path-->
Libraries tab-->Add External Jars.
10. Add the following list of jars to the libraries and Click on Ok to
complete the setup.
Selenium-server-standalone-2.14.0
Selenium-java-2.14.0
04 January 2017 70
Selenium-java-2.14.0-srcs
Configuring TestNG Framework to Selenium
RC
1. Go to http://testng.org/doc/download.html and download the latest version of
TestNG.
2. Extract the zip file to your local disk
3. Go to Eclipse and add the testng-6.3.1.jar file to the external jar files as
above.
4. Now go to Help Menu and click on Install New Software
5. Click on Add button.
6. Give the Name as TestNG (you can give any name, but we prefer TestNG)
7. In the location provide the following URL and click on OK
http://beust.com/eclipse (For Eclipse 3.4 and
above) http://beust.com/eclipse1 (For Eclipse 3.3 and below)
8. Now Check the checkbox TestNG and click on Next to install the TestNG
04 January 2017 71
Steps to Run Selenium Server
04 January 2017 73
Implementation of Selenium RC
04 January 2017 74
Implementation of Selenium RC contd….
04 January 2017 75
Implementation of Selenium RC contd….
package pack;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class rcdemo {
public static void main(String[] args) {
Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome",
"http://www.nitrkl.ac.in");
Selenium selenium1 = new DefaultSelenium("localhost", 4444, "*googlechrome",
"http://www.gmail.com");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
selenium1.start();
selenium1.open("/");
selenium1.windowMaximize();
}
}
04 January 2017 76
Implementation of Selenium RC contd….
Then both the given websites will open.
04 January 2017 77
Implementation of Selenium RC contd….
04 January 2017 78
Selenium Webdriver
04 January 2017 79
Introduction
04 January 2017 80
Introduction
04 January 2017 81
Introduction
04 January 2017 82
Installation of Selenium
WebDriver
Step 1 - Install Java on your computer
Download and install the Java Software Development
Kit (JDK).
04 January 2017 83
Installation of Selenium
WebDriver contd….
Next –
04 January 2017 84
Installation of Selenium
WebDriver contd….
This JDK version comes bundled with Java Runtime
Environment (JRE) so you do not need to download and
install the JRE separately.
Step 2 - Install Eclipse IDE
Download "Eclipse IDE for Java Developers" . Be sure
to choose correctly between Windows 32 Bit and 64 Bit
versions.
04 January 2017 85
Installation of Selenium
WebDriver contd….
You should be able to download a ZIP file named
"eclipse-java-juno-SR1-win32-x86_64.zip" (the version
number “SR1” may change over time).
04 January 2017 86
Installation of Selenium
WebDriver contd….
Inside that ZIP file, there is an "eclipse" folder which
contains all the application files. You can extract the
"eclipse" folder anywhere you want in your PC; but for
this tutorial, extract it to your C drive.
04 January 2017 88
Installation of Selenium WebDriver
contd….
This download comes as a ZIP file named "selenium-2.25.0.zip".
For simplicity, extract the contents of this ZIP file on your C drive so that
you would have the directory “C:\selenium-2.25.0\”.
This directory contains all the JAR files that we would later import on
Eclipse.
Step 4 - Configure Eclipse IDE with WebDriver
1. Launch the “eclipse.exe” file inside the “eclipse” folder that we extracted in
Step 2.
2. If you followed Step 2 correctly, the executable should be located on
C:\eclipse\eclipse.exe.
3. When asked to select for a workspace, just accept the default location.
04 January 2017 89
Installation of Selenium WebDriver
contd….
04 January 2017 90
Installation of Selenium WebDriver
contd….
4. Create a new project through File > New > Java Project.
5. Name the project as “myproject”.
6. Right-click on the newly created project and select New > Package.
7. Name that package as "mypackage".
8. Create a new Java class under mypackage by right-clicking on it and then
selecting New > Class, and then name it as "myclass".
9. Your Eclipse IDE should look like the image below.
04 January 2017 91
Installation of Selenium WebDriver
contd….
Open Eclipse.
04 January 2017 94
Implementation of Selenium
Webdriver contd….
Go to new->JAVA project.
04 January 2017 95
Implementation of Selenium
Webdriver contd….
04 January 2017 96
Implementation of Selenium
Webdriver contd….
04 January 2017 97
Implementation of Selenium
Webdriver contd….
04 January 2017 98
Implementation of Selenium
Webdriver contd….
Enter java class name and package name and then
click finish.
04 January 2017 99
Implementation of Selenium
Webdriver contd….
Then click on OK
package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;