Stqa
Stqa
Page 1 of 54
Practical No.1
AIM: Install Selenium IDE. Write a test suite containing minimum 4 test cases for
different formats.
REQUIREMENTS:
1. Just google “Selenium IDE chrome” and click on the first link. Add the “Selenium IDE” extension
to your browser.
Before:
After:
2. For testing, we need a test case suite, so we create a WebApplication in NetBeans IDE. File >
New Project > Java Web > Web Application > Add GlassFish Server > Finish.
Open NetBeans IDE:
Page 2 of 54
3. In index.html, we write the following code for “ARITHMETIC OPERATIONS” test case suite. : ---
index.html---
<html>
Page 3 of 54
<head>
<title>prac1</title> <script
language="javascript">
function addition()
{
var num1=parseInt(document.arithmetic.n1.value);
var num2=parseInt(document.arithmetic.n2.value);
var result=num1+num2;
document.arithmetic.res.value=result;
}
function subtraction()
{
var num1=parseInt(document.arithmetic.n1.value);
var num2=parseInt(document.arithmetic.n2.value);
var result=num1-num2;
document.arithmetic.res.value=result;
}
function multiplication()
{
var num1=parseInt(document.arithmetic.n1.value);
var num2=parseInt(document.arithmetic.n2.value);
var result=num1*num2;
document.arithmetic.res.value=result;
}
function division()
{
var num1=parseInt(document.arithmetic.n1.value);
var num2=parseInt(document.arithmetic.n2.value);
Page 4 of 54
var result=num1/num2;
document.arithmetic.res.value=result;
}
</script>
</head>
<body>
<h1 align="center"> Arithmetic Operations </h1>
<form name="arithmetic">
<table border="1" align="center">
<tr>
<td>Number 1: </td>
<td><input type="text" name="n1" size="20"></td>
</tr>
<tr>
<td>Number 2: </td>
<td><input type="text" name="n2" size="20"></td>
</tr>
<tr>
<td colspan=2>
<input type="button" name="add" value="Add"
onclick="javascript:addition();"> <input
type="button" name="sub" value="Subtract"
onclick="javascript:subtraction();"> <input
type="button" name="mul" value="Multiply"
onclick="javascript:multiplication();"> <input
type="button" name="div" value="Divide"
onclick="javascript:division();">
</td>
</tr>
Page 5 of 54
<tr>
<td colspan="2">Result is: <input type="text" name="res" size="20" value=""></td>
</tr>
</table>
</form> </body> </html>
4. Create a JSP file “newjsp.jsp” with a link to the created HTML file.
---newjsp.jsp---
5. Run this JSP file from NetBeans. It will then open up in a browser.
• Then from the browser, open the link:
• Now you’ll be redirected to ARITHMETIC OPERATIONS page. Copy the URL of the page and
open “Selenium IDE” extension:
Page 6 of 54
• Now, Record a new test project in a new project:
Page 7 of 54
• A new tab will be opened, maximize that tab(this tab is your working tab for recording):
• Just as you stop your recording, you’ll be prompted to Name your new test, we’ll make our new
test as “addition”:
Page 8 of 54
• Save the project after each test case:
• We’ll be prompted to paste our URL again, then click Start Recording:
Page 9 of 54
NOTE THAT each clicks are recorded:
Page 10 of 54
The test will run automatically and the completion will be shown step-by-step in the “Log” area in
the Selenium IDE:
Page 11 of 54
NOTE2: Paste here the URL again if the Glassfish Error occurs between any test case:
• Now create 3 more test cases(subtraction, multiplication, division). Then “Run all tests”:
6) Finish!
Page 12 of 54
Practical No. 2
AIM: Conduct a test case suite for any two websites.
REQUIREMENTS:
1) Just google “Selenium IDE chrome” and click on the first link. Add the “Selenium IDE”
extension to your browser.
2) For testing, we’ll choose “redbus.in” as our first website. We’ll be checking some Selenium
IDE Commands like assertText, verifyTitle, storeText, echo. Detailed info for several
commands are provided at https://ui.vision/docs/selenium-ide .
• Now google “redbus.in”.
• Copy the URL of the page and open “Selenium IDE” extension:
Page 13 of 54
Name your project:
A new tab will be opened, maximize that tab(this tab is your working tab for recording):
Page 14 of 54
(This command verifies title of the webpage and keeps on continuing the execution.) So anywhere on the
window, do Right Click> select Selenium IDE> click Verify Title:
• Now after filling the FROM, TO, ONWARD DATE, we proceed further by clicking on
Search Buses: (make sure not to do unnecessary clicks)
Page 15 of 54
So, we want to make sure that our automated testcase chooses our specified Bus Provider.
To ensure that, here we do Right Click over the name of the bus provider> then select Selenium IDE>
and click Assert Text :
So, we select the price> right click over it> select Selenium IDE> click Store Text :
Now Selenium IDE will prompt us to enter the name of the variable in which that price will be stored:
Page 16 of 54
• After clicking OK, we can see how the target is automatically mapped to the css attribute of the
page, and our price is stored:
Here we’ll display the price of the ticket from the variable “price” that we stored during the use of
storeText command.
To create a new command, we just click onto the next line and enter our command:
Page 17 of 54
• We’ll enter the Command name echo, & Value ${price} because we are calling the created variable
“price” from this command:
Page 18 of 54
• After the test gets completed, we can see the echo: 350 in the log area of Selenium IDE showing
the output of the echo command.
Here we can see how 350 is stored in variable “price” by storeText command, and that variable is then
called by the echo command, which is then returning the value fetched from the page:
3) Finish!
(Assert and verify commands are both useful for verifying condition match or not. The difference is that
verify command will verify the condition and if it’s not match, it will give error message in Log area and
the macro(testcase) continues to run. With the assert command, if the condition does not match then
it will stop remaining macro(testcase) execution in the selenium IDE software testing tool.)
Page 19 of 54
Practical 2 – Part ||
Conduct a test suite for two different websites using Selenium IDE. Perform various
actions like clicking links, filling forms, and verifying content.
A:
Page 20 of 54
3. Click event to a target specified “linkText = Rust Hello World”
B:
Page 21 of 54
- Add this following commands in test:
Page 22 of 54
7. Close
Result:
Page 23 of 54
Practical No. 3
AIM: Install Selenium Server(Selenium RC) and demonstrate it using a script in Java.
PRE-REQUISITES(*here are w.r.t. Windows 10(64 bit), so choose accordingly w.r.t. your specs):
1) To Download “JDK”:
• Visit
https://www.oracle.com/technetwork/java/javase/downloads/jdk12downloads52
95953.html
• Visit https://www.seleniumhq.org/download/
• Under section “Selenium Standalone Server”, click download version “3.141.59”
• You’ll get the executable jar file(selenium-server-standalone-3.141.59)
b) For “Selenium Client Driver”:
• Visit https://www.seleniumhq.org/download/
• Under section “Selenium Client & WebDriver Language Bindings”, download the
“3.141.59” version of Java.
• Extract the file and you’ll see two jar files. From them, we’ll be using this
executable jar file(client-combined-3.141.59) 4) To Download “Gecko Driver”:
• Visit https://github.com/mozilla/geckodriver/releases
• Under section “Assets”, download “geckodriver-v0.24.0-win64.zip” file.
• You’ll get the application file “geckodriver”.
Page 24 of 54
2) Create a Project(File > New > Java Project ):
3) Name the project as “gcd” > click Finish > click Don’t Create module:
Page 25 of 54
6) Create a Class(right-click on Project Name > New > Class > Name it > Finish):
Page 26 of 54
7) Adding “Selenium Server Driver and Client Driver(JAR files)” in Eclipse IDE: • right-click
on Project Name > Build Path > Configure Build Path…
• Browse and add JAR files > click Apply and Close :
Page 27 of 54
8) Creating a link for HTML file(wherein calculation part is present):
(NOTE that this file will be run by the ‘script in JAVA’(which we’ll create later)) •
Create a Notepad file with the following code and save it as “gcdhtml.html”:
---(gcdhtml.html)---
<html>
<head>
<body>
<center>
<h1>---Program to calculate GCD of two numbers---</h1>
<hr color="red">
<form name="myform">
Enter Number 1: <input type="text" name="n1" value=""> <br> <br>
Enter Number 2: <input type="text" name="n2" value=""> <br> <br>
<input type="button" name="btn" value="Get GCD" onClick="gcd()"><br><br>
GCD: <input type="text" name="result" value="">
</form>
</center>
</body>
</html>
• Close the file. Then right-click > Open with > Firefox Browser
Page 28 of 54
• Copy URL from the webpage:
Page 29 of 54
System.out.println("GCD="+result);
}
}
10) Run the file from Eclipse IDE:
• OUTPUT:
11) Finish!
-acts as a proxy between Web Driver enabled clients(Eclipse, NetBeans, etc.) and Mozilla Firefox
browser or simply acts as a link between Selenium Web Driver tests and Mozilla Firefox browser.
-a test tool that allows you to write automated web application UI tests in any programming
language against any HTTP website using any mainstream JavaScript-enabled browser.
1) A server which automatically launches and kills browsers, and acts as a HTTP proxy for web
requests from them.
2) Client libraries for your favourite computer language.
Page 30 of 54
PRACTICAL No. 4
AIM: Write a program using Selenium WebDriver to update 10 student records in an
Excel file. Perform data manipulation and verification.
PRE-REQUISITES:
• Visit http://www.java2s.com/Code/Jar/j/Downloadjxl26jar.htm
• Download this file: “jxl/jxl-2.6.jar.zip( 603 k)” and extract it.(you’ll get the .jar file)
STEPS:
Page 31 of 54
3) Name the project as “p5” > click Finish > click Don’t Create module:
6) Create a Class(right-click on Project Name > New > Class > Name it > Finish):
Page 32 of 54
7) Adding “JXL(JAR file)” in Eclipse IDE: right-click on Project Name > Build Path > Configure
Build Path…
Page 33 of 54
8) Creating the script in JAVA:
(NOTE that this script will be run by Eclipse IDE)
(In simple words, it’s like we are
-ordering Eclipse to run a script or to do a job
-of creating and opening .xls file
-and putting the values in the cells with the help of jxl.jar -and to
show the result.
-Hence automating the work in a local system(PC)).
---(Excelwriter.java)---
package excelwrite;
Page 34 of 54
Number num = new Number(c, r, marks[r-1]);
excelSheet.addCell(num);
}
}
//filling name in total
for(r=1;r<=sname.length;r++) {
for(c=4;c<5;c++) {
int total=marks[r-1]+marks[r-1]+marks[r-1];
Number num = new Number(c, r, total); excelSheet.addCell(num);
}
}
workbook.write();
workbook.close();
System.out.println("Excel File Created!!!!!");
}
}
9) Run the file from Eclipse IDE:
• OUTPUT:
10) Finish!
What is JXL.JAR:
-jxl.jar is the library of JExcelApi , which is open source java API to read, write, and modify Excel
spreadsheets dynamically. It contains all the compiled *.class files, associated metadata and
resources that are used by the Java Excel API internally .
Page 35 of 54
PRACTICAL No. 5
AIM: Write and test a program to select the number of students from Excel file(table) who
have scored 60 or more in any one subject(or all subjects). Perform data extraction and
analysis.
PRE-REQUISITES:
STEPS:
Page 36 of 54
3) Name the project as “p6” > click Finish > click Don’t Create module:
6) Create a Class(right-click on Project Name > New > Class > Name it > Finish):
Page 37 of 54
7) Adding “JXL(JAR file)” in Eclipse IDE:
• right-click on Project Name > Build Path > Configure Build Path…
• now go under: Java Build Path > Libraries > Classpath > click Add External JARs…
• Browse and add JAR file > click Apply and Close :
Page 38 of 54
(NOTE that this script will be run by Eclipse IDE)
(In simple words, it’s like we are
-ordering Eclipse to run a script or to do a job
-of opening .xls file
-and fetching the marks count>=60 from the cells with the help of jxl.jar
and to show the result.
-Hence automating the work in a local system(PC)).
---(Excelreader.java)---
package excelread;
import java.io.File;
import
java.io.IOException;
import jxl.Cell; import
jxl.CellType; import
jxl.Sheet; import
jxl.Workbook;
import jxl.read.biff.BiffException;
public class Excelreader {
private String inputFile;
public void setInputFile(String inputFile) {this.inputFile = inputFile;}
if(Integer.parseInt(cell.getContents())>=60){
flag = true;
if(flag == true){
count++;
flag=false;
}
break;
}
}
}
}
System.out.println("Total number of students who scored more
than 60 in one or more subjects: " +count);
}
catch (BiffException e) {e.printStackTrace();}
Page 39 of 54
}
test.setInputFile("C:\\Users\\Usman\\eclipseworkspace\\p5\\student.xls");
test.read();
}
}
10) Finish!
Page 40 of 54
PRACTICAL No. 6
AIM: Write and test a program to provide total number of objects present/available on
webpage. Perform element identification and counting.
PRE-REQUISITES:
1) Check that you have JDK.
2) Check that you have Eclipse IDE.
3) Check that you have Selenium Server Driver and Client Driver(JAR files).
4) Check that you have Gecko Driver.
5) Check that you have a stable Internet connection.
STEPS:
Page 41 of 54
3) Name the project as “p8” > click Finish > click Don’t Create module:
6) Create a Class(right-click on Project Name > New > Class > Name it > Finish):
Page 42 of 54
7) Adding “Selenium Server Driver and Client Driver(JAR files)” in Eclipse IDE: • right-click
on Project Name > Build Path > Configure Build Path…
• now go under: Java Build Path > Libraries > Classpath > click Add External JARs…
• Browse and add JAR files > click Apply and Close :
Page 43 of 54
(In simple words, it’s like we are
-ordering Eclipse to run a script or to do a job
-of opening the browser, visiting the URL
-and finding the <a> tag WebElements with the help of Selenium Drivers
and to show the result.
-Hence automating the work in browser)
java.util.List<WebElement> links =
driver.findElements(By.tagName("a"));
Page 44 of 54
PRACTICAL No. 7
AIM: Write and test a program using Selenium WebDriver to get the number of items in
a list/combo box. Perform element identification and counting.
PRE-REQUISITES:
STEPS:
Page 45 of 54
3) Name the project as “p9” > click Finish > click Don’t Create module:
6) Create a Class(right-click on Project Name > New > Class > Name it > Finish):
7) Adding “Selenium Server Driver and Client Driver(JAR files)” in Eclipse IDE: • right-click
on Project Name > Build Path > Configure Build Path…
Page 46 of 54
• now go under: Java Build Path > Libraries > Classpath > click Add External JARs…
• Browse and add JAR files > click Apply and Close :
8) Create HTML file in a notepad > Save it > Open it in browser > Copy the URL:
(NOTE THAT: as this is our LOCAL FILE, this file will be opened thru STATIC URL in script)
---(combobox.html)---
Page 47 of 54
<select id="continents">
<option value="Asia">Asia</option>
<option value="Europe">Europe</option>
<option value="Africa">Africa</option>
</select>
Page 48 of 54
file:///D:/Usman/College/503%20pracs/combobox.html"; //STATIC URL(LOCAL FILE)
driver.get(appUrl);
• OUTPUT:
Page 49 of 54
PRACTICAL No. 8
AIM: Write and test a program to count the number of check boxes on the page,
including checked and unchecked counts. Perform checkbox
identification and counting.
PRE-REQUISITES:
STEPS:
Page 50 of 54
3) Name the project as “p10” > click Finish > click Don’t Create module:
6) Create a Class(right-click on Project Name > New > Class > Name it > Finish):
Page 51 of 54
7) Adding “Selenium Server Driver and Client Driver(JAR files)” in Eclipse IDE: • right-click
on Project Name > Build Path > Configure Build Path…
• now go under: Java Build Path > Libraries > Classpath > click Add External JARs…
• Browse and add JAR files > click Apply and Close :
8) Create HTML file in a notepad > Save it > Open it in browser > Copy the URL:
Page 52 of 54
(NOTE THAT: as this is our LOCAL FILE, this file will be opened thru STATIC URL in script)
---(multicheckbox.html)---
<input type="checkbox" value="A">A<br>
<input type="checkbox" value="B" CHECKED>B<br>
<input type="checkbox" value="C">C<br>
<input type="checkbox" value="D" CHECKED>D<br>
<input type="checkbox" value="E">E<br>
Page 53 of 54
String appUrl = "https://www.toolsqa.com/automation-practice-form/";
//DYNAMIC URL(WEBSITE)
//String appUrl =
"file:///D:/Usman/College/503%20pracs/multicheckbox.html"; //STATIC URL(LOCAL
FILE)
driver.get(appUrl);
List<WebElement> checkBoxes =
driver.findElements(By.xpath("//input[@type='checkbox']"));
int checkedCount=0, uncheckedCount=0;
for(int i=0; i<checkBoxes.size(); i++){
System.out.println(i+" checkbox is selected
"+checkBoxes.get(i).isSelected());
if(checkBoxes.get(i).isSelected())
{checkedCount++;} else {uncheckedCount++;}
}
//driver.quit();
System.out.println("No. of selected checkbox: "+checkedCount);
System.out.println("No. of unselected checkbox: "+uncheckedCount);
}
}
Page 54 of 54