Professional Documents
Culture Documents
INTRODUCTION TO SELENIUM
1. History of Selenium
• In 2004 invented by Jason R. Huggins and team.
• Original name is JavaScript Functional Tester [JSFT]
• Open source browser based integration test framework built originally by Thought
works.
• 100% JavaScript and HTML
• Web testing tool
• That supports testing Web 2.0 applications
• Supports for Cross-Browser Testing (ON Multiple Browsers)
• And multiple Operating Systems
• Cross browser – IE 6/7, Firefox .8+, Opera, and Safari 2.0+
2. What is Selenium?
• Acceptance testing tool for web-apps
• Tests run directly in browser
• Selenium can be deployed on Windows, Linux, and Macintosh.
• Implemented entirely using browser technologies -
JavaScript
DHTML
Frames
3. Selenium Components
– Selenium IDE
Created by Shinya Kasatani of Japan
– Selenium RC
Created by Paul Hammant
– Selenium Grid
Developed by Patrick Lightbody
Selenium IDE
• The Selenium-IDE (Integrated Development Environment) is the tool you use
to develop your Selenium test cases.
• It is Firefox plug-in
• Firefox extension which allows record/play testing paradigm
• Automates commands, but asserts must be entered by hand
• Creates the simplest possible Locator
• Based on Selenese
1
Software Testing and Quality Assurance
1. Selenium IDE Demo Installation
Version to be used
(Selenium IDE Version 3.1.1 works with Firefox 56.0 and later)
You need
Mozilla Firefox
Active Internet Connection
If you do not have Mozilla Firefox yet, you can download it
from http://www.mozilla.org/en-US/firefox/new.
STEPS:
1. Launch Mozilla Firefox Browser.
2. Type URL https://www.seleniumhq.org/download/
OR
https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/
3. Selenium IDE Add-ons page will get open then Click on Add to Firefox
button
4. Firefox will show one popup saying do you want to allow Mozilla Firefox to install
Selenium IDE Add-ons or not. Click on Install button.
2
Software Testing and Quality Assurance
5. Firefox will automatically install Selenium IDE software. After the installation is
completed, a pop up window appears asking to re-start the Firefox. Click on the
“Restart Now” button to reflect the Selenium IDE installation. Click on Restart
Now button.
6. On clicking on the Restart Now button, Firefox will restart automatically. In case you
missed the pop-up, simply close the Firefox and launch again.
7. Once the Firefox is booted and started again, we can see selenium IDE under the
tools menu list. Selenium IDE icon will be displayed in the Firefox toolbar.
8. Click on Selenium IDE icon to open Selenium IDE.
3
Software Testing and Quality Assurance
4 test cases for 4 websites
i. https://store.demoqa.com
ii. https://www.google.com
iii. https://www.seleniumhq.org
i. Website:- http://store.demoqa.com
Step 1:
Step 2:
4
Software Testing and Quality Assurance
Step 3:
Step 4:
5
Software Testing and Quality Assurance
ii. Website: - https://www.google.com
Step 1:
Step 2:
6
Software Testing and Quality Assurance
Step 3:
Step 4:
7
Software Testing and Quality Assurance
iii. Website: - www.seleniumhq.org
Step 1:
Step 2:
8
Software Testing and Quality Assurance
Step 3: -
Step 4: -
9
Software Testing and Quality Assurance
Practical 2
Aim: Conduct a test suite for any two web sites.
i. Test Case 1
Step1: - Open www.google.com
Open Selenium
10
Software Testing and Quality Assurance
Step 2: - Type Energy Efficient in the google search input box.
11
Software Testing and Quality Assurance
Step 3: Assert the title as “Energy Efficient google search”
12
Software Testing and Quality Assurance
ii. Test Case 2
Step 1: Open Firefox Web browser
Open Selenium
13
Software Testing and Quality Assurance
Step2: In the address bar type https://www.yahoo.com
14
Software Testing and Quality Assurance
Step 4: Verify the Test result
15
Software Testing and Quality Assurance
Practical 3
Aim: Install Selenium server and demonstrate it using a script in Java/PHP.
Step 1: Double click on “Eclipse shortcut on Desktop”
16
Software Testing and Quality Assurance
Step 3: Go to Eclipse –> Click File –> New –> Project (from various options need to select
just “project”)
17
Software Testing and Quality Assurance
Step 5: Give the project name
18
Software Testing and Quality Assurance
Step 7: Right Click on project name & Click “Java Build Path”
19
Software Testing and Quality Assurance
Step 9: Select “Selenium Client Drivers” unzipped in C:Selenium folder (Selenium
Server JAR file should not be added)
Step 10: Referenced libraries –> contains both the Selenium Client driver jar files.
20
Software Testing and Quality Assurance
Step 11: Create a new class file in project by right click on src folder.
Step 12:
21
Software Testing and Quality Assurance
Source Code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; import
org.openqa.selenium.remote.DesiredCapabilities;
System.setProperty("webdriver.gecko.driver",driverPath); DesiredCapabilities
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);
driver= new FirefoxDriver(capabilities);
driver.get("https://www.facebook.com/");
driver.manage().window().maximize(); driver.quit();
}
}
22
Software Testing and Quality Assurance
Output:
23
Software Testing and Quality Assurance
Practical 4
Aim: Write and test a program to login a specific web page. (Using JUnit)
24
Software Testing and Quality Assurance
Step 3: Under environment window clicks on "new" button.
25
Software Testing and Quality Assurance
Step 5: Provide variable name as "JUNIT_HOME"and Provide JUnit value as JUnit path where
you have copied JUnit jar files.
Step 6: create another variable with the name CLASSPATH. Variable value: C:/junit
26
Software Testing and Quality Assurance
Sankalp kadam Roll no. 27
Step 8: Right click on project: Click on "build path" and then Click on "Configure build path"
Step 9: Now click on "Add External JARs" button to add your downloaded
JUnit.jar file with eclipse
27
Software Testing and Quality Assurance
Sankalp kadam Roll no. 27
Step 10: Create a java class named TestJUnit.java and provide a simple assert statement.
28
Sankalp kadam Roll no. 27
Step 11: Create a java class named TestJUnit.java and provide a simple assert statement.
Source Code:
import org.junit.Test;
Source Code:
Step 13: Right click on TestRunner.java and click on "Run As" and Another window will be open
once you click on "Run As", click on "1 JUnit Test"
29
Sankalp kadam Roll no. 27
Output:
30
Sankalp kadam Roll no. 27
Practical 5
Aim: Write and test a program to update 10 student records into table into Excel file (using
TestNG)
Step 1: Select Help / Software updates / Find and Install &
Step 2:
31
Sankalp kadam Roll no. 27
Step 4: Make sure the check box next to URL is checked and click Next.
32
Sankalp kadam Roll no. 27
Step 5:
Step 6:
33
Sankalp kadam Roll no. 27
Step 7:
Step 8:
34
Sankalp kadam Roll no. 27
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jxl.*;
import jxl.read.*;
import jxl.write.*;
import java.io.*;
35
Sankalp kadam Roll no. 27
{
Label l1 = new Label(6, i, "fail");
ws.addCell(l1);
break; } }
}
wwb.write();
wwb.close(); } }
36
Sankalp kadam Roll no. 27
Practical 6
Aim: Write and test a program to select the number of students who have scored more than 60 in
any one subject (or all subjects).
Source Code:
import jxl.*;
import
jxl.read.*;
import
jxl.write.*;
import java.io.*;
import
org.testng.annotations.Test;
public class countstuds {
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new FileInputStream("D:\\selenium
pracs\\myBook1.xls"); Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new FileOutputStream("D:\\selenium
pracs\\countBook1res.xls"); WritableWorkbook wwb =
Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result",
0); int c=0;
for (int i = 0; i < s.getRows(); i++)
{ for (int j = 0; j <
s.getColumns(); j++)
{
if(i >= 1)
{ String b= new
String();
b=s.getCell(3,i).getContents(
); int x= Integer.parseInt(b);
if( x < 60)
{ c++;
break; }
}
a[i][j] = s.getCell(j, i).getContents();
Label l2 = new Label(j, i-c,
a[i][j]); ws.addCell(l2);
} }
wwb.write();
wwb.close();
} }
37
Sankalp kadam Roll no. 27
38
Sankalp kadam Roll no. 27
Practical 7
AIM: Write and test a program to provide total number of objects present / available
on the page.
Source Code:
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.remote.DesiredCapabilities;
System.setProperty("webdriver.gecko.driver",driverPath); DesiredCapabilities
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);
driver= new FirefoxDriver(capabilities);
driver.get("http://toolsqa.wpengine.com/");
java.util.List<WebElement> links =
driver.findElements(By.tagName("a"));
System.out.println("Total links are"+links.size()); for
(int i = 0; i<links.size(); i=i+1)
{
System.out.println("Link "+ i + " Link name "+ links.get(i).getText());
}
}
}
39
Sankalp kadam Roll no. 27
OUTPUT:
Total Links are 229.
40
Sankalp kadam Roll no. 27
Practical 8
AIM: Write and test a program to get the number of items in a list / combo box.
<body>
<select name="menu">
</select>
</body>
</html>
41
Sankalp kadam Roll no. 27
42
Sankalp kadam Roll no. 27
43
Sankalp kadam Roll no. 27
44
Sankalp kadam Roll no. 27
45
Sankalp kadam Roll no. 27
Source Code:-
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.remote.DesiredCapabilities;
OUTPUT:
46
Sankalp kadam Roll no. 27
47
Sankalp kadam Roll no. 27
Practical 9
AIM: Write and test a program to count the number of check boxes on the page checked and
unchecked count.
Step 1: Start xampp Server
<body>
<form>
<input type="checkbox">SSC<br/>
<input type="checkbox">HSC<br/>
<input type="checkbox">BCOM<br/>
<input type="checkbox">BTECH<br/>
</form>
</body>
</html>
48
Sankalp kadam Roll no. 27
49
Sankalp kadam Roll no. 27
50
Sankalp kadam Roll no. 27
51
Sankalp kadam Roll no. 27
52
Sankalp kadam Roll no. 27
Source Code :
Import org.openqa.selenium.By;
Import org.openqa.selenium.WebDriver;
Import org.openqa.selenium.WebElement;
Import org.openqa.selenium.firefox.FirefoxDriver;
Public class CheckBoxSelected {
static String driverPath = "C:\\Users\\Computer-lab\\Downloads\\geckodriver.exe";
public static WebDriver driver;
public static void main(String args[]){
System.setProperty("webdriver.gecko.driver",driverPath);
WebDriver driver = newFirefoxDriver();
driver.get("http://localhost:83/comboTest.html");
java.util.List<WebElement>options =
driver.findElements(By.xpath("//input[@type='checkbox']"));
53
Sankalp kadam Roll no. 27
Step 4: Run your program
54
Sankalp kadam Roll no. 27
Practical 10
Aim: Load Testing using JMeter, Android Application testing using Appium Tools,
Bugzilla Bug tracking tools.
Step 1: http://jmeter.apache.org/download_jmeter.cgi#binaries
55
Sankalp kadam Roll no. 27
Step 3: Change the name of the Test Plan node to Sample Test in the Name test Box.
Step 4: Right Click on Sample Test > Add > Thread Users > Thread Groups
56
Sankalp kadam Roll no. 27
Step 5: Name the Thread Group as Users.
Step 6: Right Click on User node and Add > Sampler > HTTP request option
57
Sankalp kadam Roll no. 27
Step 7: It will add one empty HTTP Request Sampler under the user node
Step 8: Configure the node elements Name , Server Name or Ip , Protocol , Path.
Step 9: To add listener: Right click on user node > Add > Listener > > View Result Tree Option
58
Sankalp kadam Roll no. 27
Step 10: Run the test Plan and View the Output.
59