Stqa Practical Final
Stqa Practical Final
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 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
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:
//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.");
}
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
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();
}
}
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
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
}
}
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>
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);
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>
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: