0% found this document useful (0 votes)
65 views35 pages

Stqa Practical Final

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views35 pages

Stqa Practical Final

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Index

S.NO Practical Name Date Signature


Create minimum of 4 test cases for

1 different web page formats (e.g., HTML, 08/08/24


XML, JSON, etc.).
Conduct a test suite for two different
2 22/08/24
websites using Selenium IDE.
A program to automate the login process
3 22/08/24
on a specific web page.
A program to update 10 student records in
4 29/08/24
an Excel file.
A program to select the number of students

5 who have scored more than 60 in any one 05/09/24


subject.
A program to provide the total number of
6 19/09/24
objects present or available on a web page.
A program to get the number of items in a
7 26/09/24
list or combo box on a web page.
A program to get the number of items in a
8 03/10/24
list or combo box on a web page.
Practical 1
Install Selenium IDE and create a test suite containing a minimum of 4 test
cases for different web page formats (e.g., HTML, XML, JSON, etc.).

Selenium DE Demo Installation:


1. Launch Mozilla Firefox Browser.
2. Type URL https://www.selenium.dev/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.
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.
7. 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.
8. Once the Firefox is booted and started again, we can see selenium IDE under
the tool’s menu list. Selenium IDE icon will be displayed in the Firefox toolbar.

Test Case 1:
Step 1 :
● Launch Firefox and Selenium IDE.
● Type the value for our Base URL : http//demo.guru99.com/test/newtours/
● Toggle the Record button on (if it is not yet toggled on by default).

Step 2 : In Firefox, navigate to http://demo.guru99.com/test/newtours/.


Step 3:
● Right-click on any blank space within the page, like on the Mercury
Tours logo on the upper left corner. This will bring up the Selenium IDE
context menu.
● Note: Do not click on any hyperlinked objects or images.
● Then, select "assertTitle exact: Welcome: Mercury Tours." This is a
command that makes sure that the page title is correct.

Step 4:
● In the "User Name" text box of Mercury Tours, type an invalid username,
"invalidUNN".
● In the "Password" text box, type an invalid password, "invalidPWD".
Step 5:
● Click on the "Sign-in" button. Firefox should take you to this page.

Step 6:
● Toggle. the record button off to stop recording.
Step 7:
● Now that we are done with our test script, we shall save it in a test case.
Step 8:
● Choose your desired location, and then name the Test Case as "Invalid
login".
● Click the "Save" button.
Step 9:
● Go back to Selenium IDE and click the Playback button to execute the
whole script. Selenium
● IDE should be able to replicate everything properly.

Step 10:
● Notice that the project file was saved as .side extension.
Step 11:
● Repeat the above procedure for 3 more test cases with different test name
on different websites.
o http://store.demoqa.com
o https://www.seleniumhq.org
o http://www.google.com
o http://www.yahoo.com
Practical 2
Conduct a test suite for two different websites using Selenium IDE. Perform
various actions like clicking links, filling forms, and verifying content.
Steps:
Create a new project

Test Case 1:
1. Open url (Example: https://www.google.com)
2. Start recording
3. Type "energy efficient" in the Google Search Input Box

4. Click outside on an empty spot.


5. Click Search Button
6. Verify the Text Present as "energy efficient"
Assert the Title as "energy efficient - Google Search"

7. Save the test case with .HTML Extension.


Test Case 2:
1. Follow the similar steps to create one more test case with the url as
https://www.yahoo.com
2. Save the test case with .html extension
Steps for creating test suite:
1. Open a new Test Suite
Rename it.

2. Add Test cases which are already created


3. Save Suite with .html extensions.
4. Run the test suite.

5. All test cases under the test suite will execute automatically.
Practical 3
Write a program using Selenium WebDriver to automate the login process on a
specific web page. Verify successful login with appropriate assertions.
Pre-requisite: JDK(“jdk-12.0.2_windows-x64_bin.exe”),Eclipse IDE,
Selenium server Driver(“3.141.59”),Client
Driver((client-combined-3.141.59)),Gecko
driver(“geckodriver-v0.35.0-win64.zip”), Stable internet Connection.
Procedure:
1. Download Selenium-Java-3.141.59.zip, Selenium-Server-3.141.59.zip,
Selenium-Server-Standalone.jar, geckodriver-v0.35.0-win64.zip. UnZip those
files Zip files.
2. Open Eclipse and Create the Java Project without creating the module.
Project Name: Practical3
3. Create Package. Package name : p3
4. Create Class. Class Name : FB_Login
5. Add JAR file in Configure Build Path as shown below:

6. Write the code in FB_login.java


package p3;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.firefox.*;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
//import org.openqa.selenium.firefox.internal.ProfilesIni;
public class FB_login {
static String driverPath =
"C:\\Users\\TAUHEED\\geckodriver-v0.35.0-win64\\geckodriver.exe";
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", driverPath);

FirefoxProfile fp = new FirefoxProfile();


fp.setPreference(FirefoxProfile.PORT_PREFERENCE,"7055");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(fp);

//objects and variables instantiation


WebDriver driver = new FirefoxDriver(options);
String appUrl = "https://www.facebook.com/";

//launch the firefox browser and open the application url


driver.get(appUrl);

//maximize the browser window


driver.manage().window().maximize();

//declare and initialize the variable to store the expected title of the
webpage.
String expectedTitle = "Facebook– log in or sign up";

//fetch the title of the web page and save it into a string variable
String actualTitle = driver.getTitle();

//compare the expected title of the page with the actual title of the page
and print the result
if (expectedTitle.equals(actualTitle)) {
System.out.println("Verification Successful- The correct title is
displayed on the web page.");
}
else {
System.out.println("Verification Failed- An incorrect title is
displayed on the web page.");
}

//enter a valid username in the email textbox


WebElement username = driver.findElement(By.id("email"));
username.clear();
username.sendKeys("your email id");

//enter a valid password in the password textbox


WebElement password = driver.findElement(By.id("pass"));
password.clear();
password.sendKeys("your password");
password.sendKeys(Keys.ENTER);

//click on the Sign in button


WebElement LogInButton =
driver.findElement(By.xpath("//button[@name='login']"));
LogInButton.click();

//close the web browser


driver.close();
System.out.println("Test script executed successfully.");

//terminate the program


System.exit(0);
}
}

Note: Change the geckodriver path according to your local folder in which it is
available.
Output:
Practical 4
Write a program using Selenium WebDriver to update 10 student records in an Excel
file. Perform data manipulation and verification.
Pre-requisite: Eclipse IDE, JXL.jar(“jexcelapi _2_6_12.zip”).
JXL.jar:
● Java libraries are distributed as a “.jar” file-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.
Procedure:
1. Open Eclipse and Create the Java Project without creating the module.
Project Name: Practical4
2. Create Package. Package name : p4
3. Create Class. Class Name : Stud_Data
4. Add JAR file in Configure Build Path : jxl.jar

5. Write the code in Stud_Data.java


package P4;
import jxl.*; //used for WorkbookSettings,Workbook
import jxl.write.*; //used forWriteException,WritableWorkbook,WritableSheet,Label
import jxl.write.Number; //used for Number
import java.io.*; //used for IOException,File
import java.util.Locale; //used for Locale
public class Stud_Data {
public static void main(String[] args) throws IOException,WriteException {
// TODO Auto-generated method stub
int r=0,c=0;
String header[]={"Student
Name","Subject1","Subject2","Subject3","Total"};
String
sname[]={"Carls","James","Paul","Philip","Smith","Thomson","Rhodey","Stark","Ga
ry" ,"AnneMarie"};
int marks[]={50,45,60,55,70,45,67,78,89,90,30};
File file = new File("student.xls");
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook =
Workbook.createWorkbook(file,wbSettings);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
//creating header row
for(r=0;r<1;r++) {
for(c=0;c<header.length;c++) {
Label l=new Label(c,r,header[c]);
excelSheet.addCell(l);
}
}
//filling name in column1
for(r=1;r<=sname.length;r++) {
for(c=0;c<1;c++) {
Label l=new Label(c,r,sname[r-1]);
excelSheet.addCell(l);
}
}
//filling name in column2,3,4
for(r=1;r<=sname.length;r++) {
for(c=1;c<4;c++) {
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!!!!!");
}
}

6.Run this file from the Eclipse IDE.


Output:
The excel file “student.xls” will be created in eclipse_workspace folder where the
project is saved.
Practical 5
Write a program using Selenium WebDriver to select the number of students who
have scored more than 60 in any one subject (or all subjects). Perform data extraction
and analysis.

Pre-requisite: Eclipse IDE , External Excel File


Procedure:
1. Create an external excel file in D drive. Save the file as Student.xls.

2. Open Eclipse and Create the Java Project without creating the module.
Project Name: Practical5
3. Create Package. Package name : p5
4. Create Class. Class Name : Data_Extraction
5. Add JAR file in Configure Build Path : jxl.jar
6. Data_Extraction.java Code:
package p5;

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 Data_Extraction {
private String inputFile;
public void setInputFile(String inputFile) {this.inputFile = inputFile;}
public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
boolean flag=false;
int count=0;
try
{
w=Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getRows(); j++) {
for (int i = 0; i < sheet.getColumns()-1; i++) {
Cell cell = sheet.getCell(i, j);
if (cell.getType() == CellType.NUMBER) {
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();}
}
public static void main(String[] args) throws IOException {
Data_Extraction test = new Data_Extraction();
test.setInputFile("D:\\MEME\\OES\\Software Testing and Quality
Assurance\\student.xls");
test.read();
}
}

Note: Change the excel path according to local folder created

Output:
Total number of students who scored more than 60 in one or more subjects: 8
Practical 6
Write a program using Selenium WebDriver to provide the total number of
objects present or available on a web page. Perform object identification and
counting.
Pre-requisite: JDK(“jdk-12.0.2_windows-x64_bin.exe”),Eclipse IDE,
Selenium server Driver(“3.141.59”),Client
Driver((client-combined-3.141.59)),Gecko
driver(“geckodriver-v0.35.0-win64.zip”), Stable internet Connection.
JDK:-JDK is a development environment for building applications, applets, and
components using the Java programming language.
Selenium Server Driver:- Selenium Server is essential to execute Selenium RC
tests and WebDriver tests in remote machines through Selenium Grid. Selenium
WebDriver is used to perform automation testing of various web-applications
against various browsers. Selenium Server is essentially based on how one
intends to use Selenium WebDriver.
Selenium Client Driver:- a collection of open source APIs which are used to
automate the testing of a web application.
Eclipse IDE:- Eclipse provides a wide range of debugging tools that let you
debug locally and remotely.
GeckoDriver: A WebBrowser engine inbuilt within Mozilla Firefox browser.
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
Procedure:
1. Download Selenium-Java-3.141.59.zip, Selenium-Server-3.141.59.zip,
Selenium-Server-Standalone.jar, geckodriver-v0.35.0-win64.zip. UnZip those
files Zip files.
2. Open Eclipse and Create the Java Project without creating the module.
Project Name: Practical6
3. Create Package. Package name : p6
4. Create Class. Class Name : FindAllLinks
5. Add JAR file in Configure Build Path as shown below

6. Write the code in FindAllLinks.java


package p6;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FindAllLinks {


static String driverPath =
"C:\\Users\\MEME\\geckodriver-v0.35.0-win64\\geckodriver.exe";
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver",driverPath);

WebDriver driver = new FirefoxDriver();


String appUrl ="https://www.google.co.in/";
driver.get(appUrl);
java.util.List<WebElement> links =
driver.findElements(By.tagName("a"));
for (int i = 1; i<links.size(); i=i+1)
{
System.out.println(links.get(i).getText());
}
System.out.println("Total No. of Links: "+links.size());

}
}

Note: Change the geckodriver path according to your local folder in which it is
available.

Output:
Practical 7
Write a program using Selenium WebDriver to get the number of items in a list
or combo box on a web page. Perform element identification and counting.
Pre-requisite: JDK(“jdk-12.0.2_windows-x64_bin.exe”),Eclipse IDE,
Selenium server Driver(“3.141.59”),Client
Driver((client-combined-3.141.59)),Gecko
driver(“geckodriver-v0.35.0-win64.zip”), Stable internet Connection.
Download Selenium-Java-3.141.59.zip, Selenium-Server-3.141.59.zip,
Selenium-Server-Standalone.jar, geckodriver-v0.35.0-win64.zip if they are not
already downloaded. UnZip those files Zip files.
1. Open Eclipse and Create the Java Project without creating the module.
Project Name: Practical7
2. Create Package. Package name : p7
3. Create Class. Class Name : ComboBox
4. Add JAR file in Configure Build Path as shown below

5. Create the notepad file with .html extension save it and open it in browser and
copy its url.
Code in Combobox.html
<select id="continents">
<option value="Asia">Asia</option>
<option value="Europe">Europe</option>
<option value="Africa">Africa</option>
</select>

Note : Copy the url path for using in the code

6. Write the code in ComboBox.java

package p7;
import java.util.List;
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.firefox.*;
//import org.openqa.selenium.firefox.FirefoxOptions;
//import org.openqa.selenium.firefox.FirefoxProfile;
//import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.support.ui.Select;
public class ComboBox {
static String driverPath =
"C:\\\\Users\\\\MEME\\\\geckodriver-v0.35.0-win64\\\\geckodriver.exe";
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver",driverPath);
//NOTE THAT: following commented lines are required for old
machines
//DesiredCapabilities capabilities = DesiredCapabilities.firefox();
//capabilities.setCapability("marionette",true);
//ProfilesIni allProfiles = new ProfilesIni();
//FirefoxProfile fp = new FirefoxProfile();
//fp.setPreference(FirefoxProfile.PORT_PREFERENCE,"7055");
//FirefoxOptions options = new FirefoxOptions();
//options.setProfile(fp);

WebDriver driver = new FirefoxDriver();


String appUrl = "file:D:\\TAUHEED\\OES\\Software Testing and
Quality Assurance\\ComboBox.html"; //STATIC URL(LOCAL FILE)
driver.get(appUrl);
Select oSelect = new
Select(driver.findElement(By.id("continents")));
//Select oSelect = new
Select(driver.findElement(By.tagName("select"))); //this works too
List<WebElement> oSize = oSelect.getOptions();
int iListSize = oSize.size();
for(int i =0; i < iListSize ; i++)
{
// Storing the value of the option
String sValue = oSelect.getOptions().get(i).getText();
// Printing the stored value
System.out.println(sValue);
}
System.out.println("Total No. Items in Dropdown: "+iListSize);
//driver.quit();
}
}

Note: Change the geckodriver path and html path according to your local folder
in which it is available.

Output:
Practical 8
Write a program using Selenium WebDriver to count the number of checkboxes
on a web page, including checked and unchecked counts. Perform checkbox
identification and counting.
Pre-requisite: JDK(“jdk-12.0.2_windows-x64_bin.exe”),Eclipse IDE,
Selenium server Driver(“3.141.59”),Client
Driver((client-combined-3.141.59)),Gecko
driver(“geckodriver-v0.35.0-win64.zip”), Stable internet Connection.
Download Selenium-Java-3.141.59.zip, Selenium-Server-3.141.59.zip,
Selenium-Server-Standalone.jar, geckodriver-v0.35.0-win64.zip if they are not
already downloaded. UnZip those files Zip files.
1. Open Eclipse and Create the Java Project without creating the module.
Project Name: Practical8
2. Create Package. Package name : p8
3. Create Class. Class Name : CheckBox
4. Add JAR file in Configure Build Path as shown below

5. Create the notepad file with .html extension, save it and open it in browser
and copy its url.
Code in CheckBox.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>

Note : Copy the url path for using in the code

6. Write the code in CheckBox.java

package p8;
import java.util.List;
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.firefox.*;
//import org.openqa.selenium.firefox.FirefoxOptions;
//import org.openqa.selenium.firefox.FirefoxProfile;
//import org.openqa.selenium.firefox.internal.ProfilesIni;
public class CheckBox {
static String driverPath =
"C:\\Users\\MEME\\geckodriver-v0.35.0-win64\\geckodriver.exe";
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver",driverPath);
WebDriver driver = new FirefoxDriver();
//String appUrl =
"https://practice.expandtesting.com/checkboxes";//DYNAMIC
URL(WEBSITE)
String appUrl ="file:D:\\MEME\\OES\\Software Testing and
Quality Assurance\\CheckBox.html"; //STATIC URL(LOCALFILE)
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);
}
}

Note:
1. Change the geckodriver path and html path according to your local folder in which
it is available.
2. Above program has two url code. Static url (CheckBox.html) and Dynamic url
(https://practice.expandtesting.com/checkboxes). Program has to be run by
making either one url as comment line.

Output:

For Dynamic URL


For Static URL

You might also like