Skip to content
Gallery
All Pracs
Share
Explore

STQA Docs

Practical No. 1

Aim: Install selenium IDE; Write a test suite containing minimum 4 test cases for different formats.
STEPS
Step 1: Launch Chrome and Selenium IDE. Type the value for our Base URL: Toggle the Record button on (if it is not yet toggled on by default).
Step 2: In Chrome, navigate to Chrome should take you to that page.
Step 3: In the Search textbox type "Programming".
Step 4: Click on the "Search" button. Chrome should take you to another page.
Step 5: Toggle the record button off to stop recording.
Step 6: Now that we are done with our test script, we shall save it in a test case.
Step 7: Choose your desired location, and then name the Test Case as "TestCase1". Click the "Save" button.
Step 8: Notice that the file was saved as side extension.
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: Repeat the same steps for 3 different websites as mentioned above.

Practical No.2

Aim: Conduct a test suite for any two websites.
Steps
Step 1: Launch Chrome and Selenium IDE. Type the value for our Base Toggle the Record button on (if it is not yet toggled on by default).
Step 2:
In Chrome, navigate to the same website. Chrome should take you to that page.
Step 3:
Perform some valid action in the page say either login or click a link
Step 4: Click on the "Sign-In" (if login) button. Chrome should take you to another page.
Step 5:
Toggle the record button off to stop recording.
Step 6:
Now that we are done with our test script, we shall save it in a test case, and start recording another test case under the same test suite for the same website.

Practical No.3

Aim: Install Selenium server (Selenium RC) and demonstrate it using a script in Java / PHP.
Code:
Create html file for javascript as input provided.:
<html>
<head>
<script type="text/javascript">
function gcd()
{
var x,y;
x=parseInt(document.myform.n1.value);
y=parseInt(document.myform.n2.value);
while(x!=y)
{
if(x>y)
{
x=x-y;
}
else
{
y=y-x;
}
}
document.myform.result.value=x
}
</script>
</head>
<body>
<center>
<h1>---Program to calculate GDC of two numbers---</h1>
<hr color="red">
<form name="myform">
EnterNumber 1:<input type="text"name="n1"value=""><br><br>
EnterNumber 2:<input type="text"name="n2"value=""><br><br>
<input type="button" name="btn" value="GetGCD" onClick="gcd()"/><br><br>
GCD:<input type="text"name="result"value="">
</form>
</center>
</body>
</html>
Steps and code:
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g. GCD)
Click Finish – Click Yes
Right Click “GCD” package
Click “Java Build Path”
Click Libraries tab
Click “Add External JARs” button
Add two external jar files:selenium-java-client-driver-1.0.2 & selenium-server-standalone 3.1.0
Click OK
Create a new class file as “GCD” by right click on src folder.
Create a html file “GCD2.html”
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; public class gcd { static String driverPath= "C:\\Eclipsews35\\Geckodriver\\geckodriver.exe"; public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("webdriver.gecko.driver", driverPath); FirefoxProfile fp = new FirefoxProfile(); fp.setPreference(FirefoxProfile.PORT_PREFERENCE, "7055"); FirefoxOptions options = new FirefoxOptions(); options.setProfile(fp); WebDriver driver = new FirefoxDriver(options); driver.get("C:\\Eclipsews35\\GCD2.html"); driver.manage().window().maximize(); driver.findElement(By.name("n1")).sendKeys("36"); driver.findElement(By.name("n2")).sendKeys("6"); driver.findElement(By.name("btn")).click(); String result = driver.findElement(By.name("result")).getAttribute("name=result"); System.out.println("GCD="+result); } }

Practical No.4

Aim: Write and test a program to perform arithmetic operation using Junit.
Steps and Code:
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g.Tests)
Click Finish – Click Yes
Go to Explorer -> Right click on Project name -> Build Path -> Configure Build path -> Libraries -> Add library -> Select Junit -> Click on Junit4 -> Finish.
Create a new class file as “Junit” in the “Tests” by right click on src folder.
Write the below code in the class file :-
package test public class Junit { public String Concatenate(String one, String two) { return one + two; } public int Multiply( int no1, int no2) { return no1*no2; } }
Create a Test Runner class to execute above test for Concatenate operation:-
package test import static org.junit.Assert.*; public class JunitTest { public void testConcatenate() { Junit test = new Junit(); String result = test.Concatenate(“one”, “two”); assertEquals (“onetwo”, result); } }
Create a Test Runner class to execute above test for Multiply operation:-
package test import static org.junit.Assert.*; public class multiplytest { public void testmultiply() { Junit test = new Junit(); int result = test.multiply(3,4); assertEquals (12, result); } }
10. Now execute the code.

Practical No.5

Aim: Write and test a program to update 10 student records into table into Excel file
Steps
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g. TenRecords)
Click Finish – Click Yes
Right Click “TenRecords” project
Click “Java Build Path”
Click Libraries tab
Click “Add External JARs” button
Add two external jar files: jxl.2.6.jar file & selenium-server-standalone- 3.1.0
10.Click OK 11.Create a new class file as “xslData” in the “TenRecords” by right click on src folder.
12.Write the code-
xslData
package tenRecordExcel; import java.io.File; import java.io.IOException; import jxl.Workbook; import jxl.write.Label; import jxl.write.Number; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException; public class xslData { private String inputFile; public void setOutputFile(String inputFile) { this.inputFile = inputFile; } public void write() throws IOException, WriteException { File file = new File(inputFile); WritableWorkbook workbook = Workbook.createWorkbook(file); workbook.createSheet("Report", 0); WritableSheet excelSheet = workbook.getSheet(0); createLabel(excelSheet); createContent(excelSheet); workbook.write(); workbook.close(); } private void createLabel(WritableSheet sheet) throws WriteException { addCaption(sheet, 0, 0, "Student Name"); addCaption(sheet, 1, 0, "Subject 1"); addCaption(sheet, 2, 0, "subject 2"); addCaption(sheet, 3, 0, "subject 3"); addCaption(sheet, 4, 0, "Total"); } private void createContent(WritableSheet sheet) throws WriteException, RowsExceededException { for (int i = 1; i < 10; i++) { addLabel(sheet, 0, i, "Student " + i); addNumber(sheet, 1, i, ((i*i)+17)); addNumber(sheet, 2, i, ((i*i)+14)); addNumber(sheet, 3, i, ((i*i)+13)); int total; total=3*(i*i)+17+14+13; addNumber(sheet,4,i,total); } } private void addCaption(WritableSheet sheet, int column, int row, String s) throws RowsExceededException, WriteException { Label label; label = new Label(column, row, s); sheet.addCell(label); } private void addNumber(WritableSheet sheet, int column, int row, Integer integer) throws WriteException, RowsExceededException { Number number; number = new Number(column, row, integer); sheet.addCell(number); } private void addLabel(WritableSheet sheet, int column, int row, String s) throws WriteException, RowsExceededException { Label label; label = new Label(column, row, s); sheet.addCell(label); } public static void main(String[] args) throws WriteException, IOException { xslData test = new xslData(); test.setOutputFile("C:\\Users\\rhucha1\\eclipse-workspace\\Pract5\\p5.xls"); test.write(); System.out.println("Please check the result file under C:\\Users\\rhucha1\\eclipse-workspace\\Pract5\\p5.xls"); } }

Practical No.6

Aim: Write and test a program to select the number of students whose total is more than 60.
Steps
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g. score)
Click Finish – Click Yes
Right Click “score” project
Click “Java Build Path”
Click Libraries tab
Click “Add External JARs” button
Add two external jar files: jxl.2.6.jar file & selenium-server standalone-3.1.0
10.Click OK 11.Create a new class file as “scoreStu” in the “score” by right click on src folder. 12.Write the code
scoreStu
package score; 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 scoreStu { public void read() throws IOException { File inputWorkbook = new File("C:\\Users\\rhucha1\\eclipse-workspace\\Pract5\\p5.xls"); Workbook w; boolean flag=false; int count=0; try { w = Workbook.getWorkbook(inputWorkbook); Sheet sheet = w.getSheet(0); for (int j = 0; j < sheet.getRows(); j++) { Cell cell = sheet.getCell(4, j); if (cell.getType() == CellType.NUMBER) { if(Integer.parseInt(cell.getContents())>60){ count++; } } } System.out.println("Total number of students who scored more than 60 is: " +count); } catch (BiffException e) { e.printStackTrace(); } } public static void main(String[] args) throws IOException { scoreStu test = new scoreStu(); test.read(); } }

Practical No.7

AIM: Write and test a program to provide total number of objects (links) present / available on the page.
Steps
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g. TestWebPage)
Click Finish – Click Yes
Right Click “TestWebPage” package
Click “Java Build Path”
Click Libraries tab
Click “Add External JARs” button
Add two external jar files:selenium-java-client-driver-1.0.2 & selenium-server-standalone-3.1.0 10.Click OK 11.Create a new class file as “CheckLinks” by right click on src folder.
12.Write the code-
CheckLinks
import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class CheckLinks { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver","C:\\Users\\rhucha1\\eclipse-workspace\\Selenium Drivers\\geckodriver.exe"); FirefoxDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://www.microsoft.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++){ System.out.println("Link" +i+ "Link name "+links.get(i).getText()); } } }

Practical No.8

Aim: Write and test a program to get the number of items in a list / combo box.
Steps
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g. ListCombo)
Click Finish – Click Yes
Right Click “ListCombo” package
Click “Java Build Path”
Click Libraries tab
Click “Add External JARs” button
Add two external jar files:selenium-java-client-driver-1.0.2 & selenium-server-standalone-3.1.0 10.Click OK 11.Create a new class file as “ListComboBox” by right click on src folder.
12.Write the code-
ListComboBox
package ListCombo; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class ListComboBox { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver","C:\\Users\\rhucha1\\eclipse-workspace\\Selenium Drivers\\geckodriver.exe"); FirefoxDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("https://www.facebook.com/campaign/landing.php?campaign_id=1"); Select oSelect = new Select(driver.findElement(By.xpath("//select[@id='month']"))); List<WebElement> oSize = oSelect.getOptions(); int listsize = oSize.size(); System.out.println("Total no of elements in drop down box is " + listsize); for (int i = 0; i < listsize; i++) { String s = oSelect.getOptions().get(i).getText(); System.out.println(s); } } }

Practical No.9

AIM: Write and test a program to select one / many check boxes on the page.
STEPS:
Go to Eclipse –> Click File –> New –> Project (from various options need to select just “project”)
In Select Wizard –> Click Java –> “Java Project”
Give the project name (e.g. checkbox)
Click Finish – Click Yes
Right Click “checkbox” package
Click “Java Build Path”
Click Libraries tab
Click “Add External JARs” button
Add two external jar files:selenium-java-client-driver-1.0.2 & selenium-server-standalone-3.1.0
Click OK
Create a new class file as “CountCheckbox” by right click on src folder.
Create a html file “CheckBox.html”
Write the code
CheckBox.html
<html> <head> <title>Form</title> </head> <body> <form> User ID : <input type="text" name="user_id" /> <br /> Password: <input type="password" name="password" /> <br /> Description : <br /> <textarea rows="5" cols="50" name="description"> Enter description here... </textarea > <br /> <input type="checkbox" name="maths" /> Maths <input type="checkbox" name="physics" /> Physics <input type="checkbox" name="chem" /> Chemistry <input type="checkbox" name="comp" /> Computers <br /> <input type="radio" name="subject" value="Yes" /> Yes <input type="radio" name="subject" value="No" /> No <br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> <input type="button" name="ok" value="OK" /> </form> </body> </html>
CountCheckbox.java
package checkbox; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class CountCheckbox { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\\Users\\rhucha1\\eclips e-workspace\\Selenium Drivers\\geckodriver.exe"); FirefoxDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("C:\\Users\\rhucha1\\eclipse-workspace\\checklinks\\CheckBox.html"); List<WebElement> elements = driver.findElements(By.xpath("//Input[@type='checkbox']")); int checkedCount = 0; int uncheckedCount = 0; for (int i = 0; i < webElements.size(); i++) { if (webElements.get(i).isSelected() == true) checkedCount++; else uncheckedCount++; } System.out.println("Number of checked checkboxes are" + checkedCount); System.out.println("Number of unchecked checkboxes are" + uncheckedCount); } }

Ekda cross check kar 🚀 →all good :)
maybe now
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.