Practical 01:: Requirement: Aim: Code: Output
Practical 01:: Requirement: Aim: Code: Output
Practical 01:: Requirement: Aim: Code: Output
Requirement:
Aim:
Code:
Output:
Practical 2
Test Suite 1
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
try
{
Thread.sleep(2000);
WebElement navBar = driver.findElement(By.id("js_u"));
System.out.println("Test Case Pass");
driver.close();
}
catch(Exception e)
{
System.out.print("Test Case Failed");
}
Output:
govind
Test Suite 2
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Gmail {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\janvi\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://accounts.google.com/ServiceLogin?");
driver.findElement(By.id("identifierId")).sendKeys(“Your email");
driver.findElement(By.id("identifierNext")).click(); // click next
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} driver.findElement(By.name("password")).sendKeys("Your
password"); driver.findElement(By.id("passwordNext")).click(); // click sign in
String title = driver.getTitle();
if(title.equals("Google Account"))
{
System.out.println("LOGIN SUCCESSFUL...");
}
else
{
System.out.println("LOGIN FAILED");
}
}
}
Output:
PRACTICAL 03:
Requirement: HTML file for LCM andGCD , Selenium Jar files, Eclipse
Aim: To find LCM and GCD
Code:
LCM code
lcm.html
<html>
<head>
<script type ="text/javascript">
function lcm()
{
var a,b;
a=parseInt(document.myform.txt1.value);
b=parseInt(document.myform.txt2.value);
x=a*b;
y=x/gcd(a,b);
document.myform.result.value=y;
}
function gcd(a,b){
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
return a;
}
</script>
</head>
<body>
<h1 align ="Center">Program to calculate Lcm of 2 numbers</h1>
<hr color ="red">
<center>
Enter Two numbers:
<form name ="myform">
Number 1 :<input type="text" name="txt1" value =" ">
<br><br>
Number 2 :<input type="text" name="txt2" value =" ">
<br><br>
<input type="button" value ="get LCM"
onClick="lcm()"><br><br>
LCM is :<input type="text" name="result" value="">
</body>
</html>
Output:
GCD Code:
gcd.html
<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>
<h1 align ="Center">Program to calculate gcd of 2 numbers</h1>
<hr color ="red">
<center>
Enter Two numbers:
<form name ="myform">
Number 1 :<input type="text" name="n1" value =" ">
<br><br>
Number 2 :<input type="text" name="n2" value =" ">
<br><br>
<input type="button" value ="get GCD"
onClick="gcd()"><br><br>
GCD is :<input type="text" name="result" value="">
</body>
</html>
GCd.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gcd {
Output:
PRACTICAL 04 A
Requirement : Selenium Jar files ,chrome/gecko Driver, Eclipse , a google
account
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
driver.findElement(By.id("identifierId")).sendKeys("[email protected]
"); // enter username
driver.findElement(By.id("identifierNext")).click(); // click next
try
{
Thread.sleep(5000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
driver.findElement(By.name("password")).sendKeys("*******");
// enter password
driver.findElement(By.id("passwordNext")).click(); // click sign
in
String title = driver.getTitle();
System.out.println(title);
if(title.equals("Sign in – Google accounts"))
{
System.out.println("LOGIN SUCCESSFUL...");
}
else
{
System.out.println("LOGIN FAILED");
}
Output:
PRACTICAL 04 B:
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
driver.findElement(By.id("email")).sendKeys("[email protected]");
driver.findElement(By.id("pass")).sendKeys("*******");
WebElement Login = driver.findElement(By.id("loginbutton"));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Login.click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();}}}
Practical 05
Requirement : Excel file for Student Record, Jxl Jar Files,Testng (Testing Library
Aim : Write and test a program to update 10 student records into table
into Excel file.
Code :
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.testng.annotations.*;
public class StudentUpdate {
@BeforeClass //@BeforeClass runs once before the entire test.
public void setUp() throws Exception {}
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new
FileInputStream("C:\\Users\\Kewal\\Desktop\\Selenium
jars\\Students.xlsx");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new
FileOutputStream("C:\\Users\\Kewal\\Desktop\\Selenium
jars\\Students.xlsx");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result1", 0);
PRACTICAL 06 : 6.A
Requirement : Excel file for Student Record, jxl jar files, Testng library
Aim : To find number of Students with scores more than 60
Code :
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 Result
{
public String inputFile;
catch (BiffException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException
{
Result test = new Result();
test.setInputFile("G:\\TY_Pract\\Students.xls");
test.read();
}
}
Output :
PRACTICAL 06 : 6.B
Requirement : Excel file for Student Record, jxl jar files, Testng library
Aim : To find number of Students with scores less than 60
Code :
import jxl.*;
import jxl.read.*;
import jxl.write.*;
import java.io.*;
import org.testng.annotations.Test;
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new
FileOutputStream("G:\\TY_Pract\\Scores.xls");
Output :
PRACTICAL 07:
Requirement:Selenium Jar files ,chrome/gecko Driver, Eclipse
Code:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestLink {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\shaht\\Download
s\\SeleniumIDE\\SeleniumIDE\\chrome driver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
List <WebElement> mylist= driver.findElements(By.xpath("//a"));
System.out.println("Number of links =" +mylist.size());
}
}
Output:
PRACTICAL 09:
Requirement:Selenium Jar files ,chrome/gecko Driver, Eclipse
Aim: Write and test a program to count the number of check boxes /radio
buttons on the page checked and unchecked count.
Code:
Html:
<html>
<head><title>testSTQAprac</title></head>
<body>
<h2>Text Input</h2>
<form>
First name:<br><input type="text" id="fname" name="fname" ><br>
Last name:<br><input type="text" id="lname" name="lname" >
<h2>Select Gender</h2>
<input type="radio" value="Male" id="male" name="gender" checked
>Male</radio><br>
<input type="radio" value="Female" id="female"
name="gender">Female</radio><br>
<input type="radio" value="other" id="other"
name="gender">other</radio>
<h2>Select Languages Known</h2>
<input type="checkbox" id="java" name="java" value="Java"
>Java<checkbox><br>
<input type="checkbox" id="PHP" name="PHP" value="PHP"
checked>PHP<checkbox><br>
<input type="checkbox" id="C#" name="C#" value="C#"
>C#<checkbox><br>
<input type="checkbox" id="Python" name="Python" value="Python"
checked>Python<checkbox><br>
<input type="checkbox" id="Ruby" name="Ruby" value="Ruby"
>Ruby<checkbox><br>
<br><input type="submit">
</form>
</body>
</html>
Java:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver","S://SeleniumIDE//c
hromeDriver//chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("S:\\programming\\Eclipse\\STQAcheckbox.html");
driver.manage().window().maximize();
int chck=0,uchk=0;
List <WebElement>
mylist=driver.findElements(By.xpath("//input[@type =
'checkbox']"));
for(WebElement we : mylist){
if(we.isSelected()) {
chck+=1;
}
else {
uchk+=1;
}
}
int rad=0,urad=0;
List <WebElement>
list=driver.findElements(By.xpath("//input[@type = 'radio']"));
for(WebElement we : list){
if(we.isSelected()) {
rad+=1;
}
else {
urad+=1;
}
}
System.out.println("Number of Checked boxes : " +
chck);
System.out.println("Number of Unchecked boxes : " +
uchk);
System.out.println("Number of Checked radio : " +
rad);
System.out.println("Number of Unchecked radio : " +
urad);
}
}
Output:
PRACTICAL : 08-A
Code: Java
import java.util.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class TestComboBox {
System.setProperty("webdriver.chrome.driver","C:\\Users\\RD\\eclipse-work
space\\SeleniumIDE\\SeleniumIDE\\Mozilla Driver\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.facebook.com/r.php");
driver.manage().window().maximize();;
Select se = new
Select(driver.findElement(By.xpath("//Select[@id='month']")));
List <WebElement> mylist = se.getOptions();
mylist.size();
System.out.println("Number of items: " +mylist.size());
}
Output :
Practical-8B
Html Code:
<html>
<body>
<form>
<label for="country">Choose your country:</label>
<select name="country" id="country">
<option value="India">India</option>
<option value="USA">USA</option>
<option value="Japan">Japan</option>
<option value="Australia">Australia</option>
</select>
</form>
</body>
</html>
Code:
package pkg;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
Output: