Software Testing Lab Manual
Software Testing Lab Manual
by
Dr.P.Sakthi Murugan
Published by
Printed at
RAASI ENTERPRISES
COIMBATORE – 641 044 | TAMIL NADU | INDIA
B.Sc. Computer Science with Cognitive
Semester V: 204CG1A5CQ–CORE PRACTICAL SOFTWARE TESTING
Systems
[Mr.P.SakthiMurugan]
Laboratory Manual
Dr.P.Sakthi Murugan
Publisher
Editors
Dr.P.SakthiMurugan
[2022]
All rights reserved. This book is published as part of recording or documenting Semester V:
204CG1A5CQ – CORE PRACTICAL SOFTWARE TESTING, Dr. N.G.P. Arts and College. No
part of this book may be reproduced, distributed, or transmitted in any form or by any means,
including photocopying, or other electronic methods.
ISBN NO :978-81-961752-5-2
Contents
Page.
E.No. Experiment
No.
This book provides guidance that will help students to grasp Selenium WebDriver concepts fast.
You will learn about the advanced features of the Selenium IDE and Selenium Builder, followed
by cross-browser tests, methods of Selenium WebDriver, best practices.
1.OPEN A FIREFOX BROWSER USING SELENIUM WEB DRIVER
Aim
To develop a test to open a Firefox browser using selenium web driver
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium1
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned
to get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver = new FirefoxDriver();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get ("http://www.google.com");
Program
package program1;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
publicclass selenium1 {
1
DrNGASC
Coimbatore, India
Output
Result
Thus the program has been executed successfully hence the browser opened successfully.
Dr.NGPASC
2
Coimbatore,India
2.PRINT A MESSAGE TO DISPLAY THAT THE WEBSITE IS OPENED
Aim
To test the case to print a message to display that the website is opened successfully wait
for 5 seconds and close the browser.
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium1
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get ("http://www.google.com");
Dr.NGPASC
3
Coimbatore,India
Program
package ptrogram1;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
publicclass selenium1 {
Output
Dr.NGPASC
4
Coimbatore,India
Result
Thus the browser is opened successfully hence the output is verified
Dr.NGPASC
5
Coimbatore,India
3.UPLOAD A FILE WITH SEND KEYS METHOD BY USING WEB
DRIVER
Aim
To develop tests to upload a file with send keys method by using web driver.
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned
to get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get ("http://www.google.com");
8: To find the element using the name of “q” and the send name to search and enter the elements
to search using KEY.ENTER
9: Click option by find the element type as the type of class name to perform the click() function
10: Program testes successfully
Dr.NGPASC
6
Coimbatore,India
Program
package ptrogram1;
importorg.openqa.selenium.By;
importorg.openqa.selenium.Keys;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
public class selenium3 {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","/home/skasc/Downloads/chromedriver”);
WebDriver driver=new ChromeDriver();
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("selenium");
driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
driver.findElement(By.className("Tg7LZd")).click();
}
}
Output
Dr.NGPASC
7
Coimbatore,India
Result
Thus the program is executed and tests the elements in the browser successfully hence the output
is verified.
Dr.NGPASC
8
Coimbatore,India
4. AUTOMATE TO ACCESS A LINK
Aim
To create a program for automate to access a link in selenium web driver by linktext()
andpartialLinktext()
Algorithm
10:To find the element using the id of “identifierId” and the send emailid to login
11: Program testes successfully
Dr.NGPASC
9
Coimbatore,India
Program
packagenewpackage;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
Output
Dr.NGPASC
10
Coimbatore,India
Result
Thus the program is executed and automates the test in the browser successfully hence the output
is verified.
Dr.NGPASC
11
Coimbatore,India
5.LOCATE A LINK BY SELECTING MULTIPLE ITEMS IN A
DROPDOWN
.
Aim
To Locate a Link by Selecting Multiple Items in a Dropdown
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium5
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get ("https://portal2.passportindia.gov.in/AppOnlineProject/user/
RegistrationBaseAction");
Dr.NGPASC
12
Coimbatore,India
Program
packagenewpackage;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
importorg.openqa.selenium.support.ui.Select;
Dr.NGPASC
13
Coimbatore,India
Output
Result
Thus the program is executed and locates a Link by Selecting Multiple Items in a Dropdown
hence the output is verified.
Dr.NGPASC
14
Coimbatore,India
6.DEVELOP ATEST TO LOCATE A FRAME USING TAG NAME
Aim
To develop a test to locate a frame using tag name
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium6
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_tes
t");
8: click iframe directly through XPath since it is an iframe. First we have to switch to the frame
and then we can click using xpath
driver.switchTo().frame("iframeResult ");
• In this step we need to find out the id of the iframe by inspecting through Firebug.
• Then switch to the iframe through ID.
driver.findElement(By.xpath("html/body/button")).click();
Dr.NGPASC
15
Coimbatore,India
STEP 9:Program testes successfully
/*********TO COPY XPATH Right click on the button click me->inspect->right click on
ur right panel->copy ->copy xpath and paste in the program**********/
Program
packagenewpackage;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
public class selenium6 {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","/home/skasc/Downloads/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_test");
driver.manage().window().maximize();
Dr.NGPASC
16
Coimbatore,India
driver.switchTo().frame("iframeResult");
driver.findElement(By.xpath("/html/body/button")).click();
driver.switchTo().defaultContent();
}
}
Output
Result
Thus the program to locate aframe using tag name is executed and hence the output is verified.
Dr.NGPASC
17
Coimbatore,India
7.TEST THE CASE TO SUBMIT A LOGIN FORM USING WEB
DRIVER
Aim
To create a program to test the case to submit a login form using web driver.
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium7
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get("http://newtours.demoaut.com/");
Program
packagenewpackage;
importjava.util.Scanner;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
public class selenium7 {
public static void main(String[] args) throws InterruptedException {
Dr.NGPASC
18
Coimbatore,India
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","/home/skasc/Downloads/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
@SuppressWarnings("resource")
Scanner scn = new Scanner(System.in);
System.out.println("Enter username");
String uname = scn.nextLine();
System.out.println("Enter password");
String pwd = scn.nextLine();
driver.findElement(By.name("userName")).sendKeys(uname);
driver.findElement(By.name("password")).sendKeys(pwd);
driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td/tabl
e/tbody/tr/td[2]/table/tbody/tr[2]/td[3]/form/table/tbody/tr[4]/td/table/tbody/tr[4]/td[2]/div/input")
).click();
}
}
Output
Dr.NGPASC
19
Coimbatore,India
Result
Thus the program to test the case to submit a login form using web driver is executed
successfullyand hence the output is verified.
Dr.NGPASC
20
Coimbatore,India
8.TEST TO SYNCHRONIZE WITH IMPLICIT WAIT
Aim
To develop a test to Synchronize with an implicit wait.
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium7
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get("http://newtours.demoaut.com/");
6.After open the web application to Maximize it.
driver.manage().window().maximize();
7.Use implicit( ) the window wait upto 30 second after close it.
8.Program testes successfully
Program
packagenewpackage;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
importjava.util.concurrent.TimeUnit;
Dr.NGPASC
21
Coimbatore,India
}
}
Output
Result:
Thus the program test to synchronize with an implicit wait executed successfully and hence the
output is verified.
Dr.NGPASC
22
Coimbatore,India
9.TEST TO SYNCHRONIZE WITH AN EXPLICIT WAIT
Aim
To develop a test to synchronize with an explicit wait.
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium7
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get("http://demo.guru99.com/test/guru99home/" );
6.After open the web application to Maximize it.
driver.manage().window().maximize();
7.Use wait until( )
WebElement guru99seleniumlink;
guru99seleniumlink=
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
"/html/body/div[1]/section/div[2]/div/div[1]/div/div[1]/div/div/div/div[2]/div[2]/div/div/div/div/
div[1]/div/div/a/i")));
guru99seleniumlink.click();
Program
Importorg.openqa.selenium.WebDriver;
Importorg.openqa.selenium.chrome.ChromeDriver;
Importorg.openqa.selenium.By;
Importorg.openqa.selenium.support.ui.ExpectedConditions;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.support.ui.WebDriverWait;
public class selenium9 {
public static void main(String[] args) throws InterruptedException {
Dr.NGPASC
23
Coimbatore,India
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","/home/skasc/Downloads/chromedriver");
WebDriver driver = new ChromeDriver();
WebDriverWait wait=new WebDriverWait(driver, 20);
driver.get("http://demo.guru99.com/test/guru99home/" );
//Maximizes the browser window
driver.manage().window().maximize() ;
//get the actual value of the title
WebElement guru99seleniumlink;
guru99seleniumlink=
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
"/html/body/div[1]/section/div[2]/div/div[1]/div/div[1]/div/div/div/div[2]/div[2]/div/div/div/div/
div[1]/div/div/a/i")));
guru99seleniumlink.click();
}
}
Output
Result
Thus the program test to synchronize with an explicit wait executed successfully and hence the
output is verified.
Dr.NGPASC
24
Coimbatore,India
10.IDENTIFYING AND HANDLING A POP-UP WINDOW BY ITS NAME
Aim
To test the case by identifying and handling a pop-up window by its name
Algorithm
1: Open Eclipse IDE
2: Create a new java project and followed by create a new class named as selenium7
3: Sets the system property to value named webdriver.chrome.driver and the path is mentioned to
get the chrome driver
4: Create an instance of the chromedriver.
WebDriver driver=newChromeDriver ();
5: get () method automatically opens a new browser window and fetches the page that you
specify inside its parentheses.
driver.get("https://demoqa.com/alerts");
6.To show the parent window
ArrayList<String>ar = newArrayList<String>(handles);
7. To display the Parent window Id
System.out.println(parentWindowID);
String childWindowID = ar.get(1);
System.out.println(childWindowID);
8.To switch to parent window and child window
driver.switchTo().window(childWindowID);
System.out.println("child window title is " + driver.getTitle());
driver.close();
driver.switchTo().window(parentWindowID);
System.out.println("parent window title is " + driver.getTitle());
9.Program testes successfully
Program
package login;
importjava.util.ArrayList;
importjava.util.Iterator;
importjava.util.Set;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.chrome.ChromeDriver;
importio.github.bonigarcia.wdm.WebDriverManager;
publicclass form{
publicstaticvoid main(String[] args) {
Dr.NGPASC
25
Coimbatore,India
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\web
drivers\\chromedriver.exe");
WebDriverdriver = newChromeDriver();
driver.get("https://demoqa.com/alerts");
driver.findElement(By.id("alertButton")).click();
Set<String>handles = driver.getWindowHandles();
ArrayList<String>ar = newArrayList<String>(handles);
System.out.println(ar);
String parentWindowID = ar.get(0);
System.out.println(parentWindowID);
String childWindowID = ar.get(1);
System.out.println(childWindowID);
driver.switchTo().window(childWindowID);
System.out.println("child window title is " + driver.getTitle());
driver.close();
driver.switchTo().window(parentWindowID);
System.out.println("parent window title is " + driver.getTitle());
}
}
Output
Dr.NGPASC
26
Coimbatore,India
Dr.NGPASC
27
Coimbatore,India
Result
Thus the program to test the case by identifying and handling a pop-up window by its name and
hence the output is verified
Dr.NGPASC
28
Coimbatore,India
PROGRAMMES OFFERED @ DrNGPASC
UG Programme PG Programme Research Programme
Faculty of Basic and Applied Faculty of Basic and Applied Master of Philosophy
Sciences Sciences Faculty of Basic and Applied
B.Sc. Physics M.Sc. Physics Sciences
B.Sc. Chemistry M.Sc. Medical Physics M.Phil. Mathematics
B.Sc. Mathematics M.Sc. Mathematics Faculty of Bio Sciences
B.Sc. Catering Science and Faculty of Bio Sciences M.Phil. Biochemistry
Hotel Management M.Sc. Chemistry M.Phil. Biotechnology
B.Sc. Costume Design and M.Sc. Biochemistry M.Phil. Microbiology
Fashion M.Sc. Biotechnology M.Phil. Food and Nutrition
Faculty of Bio Sciences M.Sc. Microbiology Faculty of Computer Science
B.Sc. Biochemistry M.Sc. Food and Nutrition M.Phil. Computer Science
B.Sc. Clinical Laboratory Faculty of Computer Science Faculty of Commerce
Technology M.Sc. Computer Science M.Phil. Corporate
B.Sc. Biotechnology M.Sc. Computer Science with Secretaryship
B.Sc. Microbiology Data Analytics M.Phil. Commerce
B.Sc. Food Science and Faculty of Commerce Faculty of Management
Nutrition M.Com. M.Phil. Management Studies
Faculty of Computer Science M.Com. Computer Applications M.Phil. Hospital Administration
B.Sc. Computer Science M.Com. Corporate Secretaryship Faculty of Humanities
B.C.A. M.Com. International Business M.Phil. Tamil
B.Sc. Computer Technology Faculty of Management M.Phil. English
B.Sc. Information Technology M.H.A.(Master of Hospital Doctor of Philosophy
B.Sc. Computer Science with Administration) Faculty of Basic and Applied
Data Analytics Faculty of Humanities Science
B.Sc. Computer Science with M.A. English Literature Ph.D. Mathematics
Cognitive Systems Faculty of Bio Sciences
B.Sc. Artificial Intelligence & Ph.D. Biochemistry
Machine Language Ph.D. Biotechnology
Faculty of Commerce Ph.D. Microbiology
B.Com. Ph.D. Food and Nutrition
B.Com. Computer Applications Faculty of Computer Science
B.Com. Corporate Ph.D. Computer Science
Secretaryship (CA) Faculty of Commerce
B.Com. Information Ph.D. Corporate Secretaryship
Technology Ph.D. Commerce
B.Com. Professional Faculty of Management
Accounting Ph.D. Management Studies
B.Com. Finance Faculty of Humanities
B.Com. Banking and Ph.D. Tamil
Insurance Ph.D. English
B.Com. Business Process
Services
B.Com. Business Analytics
B.Com. International Business
B.Com. Account & Taxation
B.Com. Cost Accounting
Faculty of Management
B.B.A. (CA)
Faculty of Humanities
B.A. English Literature
Dr. N.G.P. ARTS AND SCIENCE COLLEGE
(An Autonomous Institution, Affiliated to Bharathiar University, Coimbatore)
Approved by Government of Tamil Nadu & Accredited by NAAC with A++ Grade (3 rd Cycle - 3.64 CGPA)
Dr. N.G.P. –KalapattiRoad, Coimbatore – 641048, Tamil Nadu, India
Web: www.drngpasc.ac.in |Email: info@drngpasc.ac.in | Phone: +91-422-2369100