STQA
STQA
<?php
$rno=$_POST["txtrno"];
$name=$_POST["txtname"];
$m1=$_POST["m1"];
$m2=$_POST["m2"];
$m3=$_POST["m3"];
$tot=$m1+$m2+$m3;
$per=$tot/3.0;
echo "Roll no=".$rno."<br>";
echo "Name=".$name."<br>";
echo "Maths=".$m1."<br>";
echo "Physics=".$m2."<br>";
echo "Chemistry=".$m3."<br>";
echo "Total=".$tot."<br>";
echo "Percentage=".$per."<br>";
if($m1<35||$m2<35||$m3<35)
echo "fail";
else
if($per<50)
echo "Pass";
else
if($per<60)
echo "Second";
else
if($per<75)
echo "First class";
else
echo "Distinction";
?>
result.php^
OUTPUT:
Testcases
PRACTICAL 2
<html>
<head><title>Shopping website</title></head>
<body>
<form method="POST" action="shopping.php">
Enter type of user:
<select name="user">
<option value="0">Select user</option>
<option value="1">Guest user</option>
<option value="2">Customer</option>
</select>
<br>
Do you have a gift card?
<select name="gift">
<option value="0">Select</option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>
<br>
<input type=submit value="submit">
</form>
</body>
</html>
Shopping.php
<?php
$user=$_POST["user"];
$gift=$_POST["gift"];
if(($user=="0")||($gift=="0"))
echo "Invalid input";
else
if($user=="1")
{
if($gift=="1")
echo"You are eligible for 20% discount";
else
echo"You are eligible for 15% discount";
}
else
{
if($user=="2")
{
if($gift=="1")
echo"you are eligible for 20% discount";
else
echo"you are not eligible for discount";
}
}
?>
OUTPUT
PRACTICAL 3-GCD
<html>
<head><title>GCD</title>
<script language="javascript">
function gcd()
{
var x,y;
x=parseInt(document.f1.t1.value);
y=parseInt(document.f1.t2.value);
while(x!=y)
{
if(x>y)
x=x-y;
else
y=y-x;
}
document.f1.t3.value=x;
}
</script>
</head>
<body>
<h1>Program to find GCD of two numbers</h1>
<form name="f1">
Enter first number:<input type=text name="t1"><br>
Enter second number:<input type=text name="t2"><br>
<input type="button" name="btn" value="find GCD" onClick="gcd()">
GCD:<input type=text name="t3"><br>
</form>
</body>
</html>
OUTPUT
:
GCD
Find gcd of two numbers
<html>
<head><title>GCD</title>
<script language="javascript">
function gcd()
{
var x=parseInt(document.f1.t1.value);
var y=parseInt(document.f1.t2.value);
while(x!=y)
{
if(x>y)
x=x-y;
else
y=y-x;
}
document.f1.t3.value=x;
}
</script>
</head>
<body>
<form name="f1">
<h1>Program for GCD of two numbers</h1>
Enter first number:<input type="text" name="t1"><br>
Enter second number:<input type="text" name="t2"><br>
GCD of two numbers:<input type="text" name="t3"><br>
<input type="button" name="btn" value="Find GCD" onClick="gcd()">
</form>
</body>
</html>
PRACTICAL 4-LOGIN a)php login chrome b)facebook chrome c)facebook firefox
PRACTICAL 5
FACTORIAL
Factclass.java
package FactorialPackage;
factorial.java
package FactorialPackage;
import org.junit.Test;
public class factorial {
@Test
public void testfactorial() {
factclass f1=new factclass();
int f=f1.factorial(5);
assertEquals(f,120);
}
Output:
Wrong output:
PRACTICAL 6-Addition,sub,mul,div
Arthmetic_Class
package arthmetic;
}
}
arithmetic.java
package arthmetic;
import org.junit.Test;
@Test
public void testarthmetic() {
Arthmetic_Class a1=new Arthmetic_Class();
int f=a1.addition(2, 2);
assertEquals(f,4);
}
O/p
Subtraction
Multiplication
Division
REVERSE PROGRAM
reverseClass.java
package reverse;
public class reverseClass
{
public int reverse(int num)
{
int reversed = 0;
while(num != 0)
{
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
return(reversed);
}
public static void main(String[] args) {
}}
reverse.java
package reverse;
import static org.junit.Assert.*;
import org.junit.Test;
public class reverse {
@Test
public void testreverse() {
reverseClass r1=new reverseClass();
int f=r1.reverse(123);
assertEquals(f,321);
}}
O/P:
package reverse;
import static org.junit.Assert.*;
import java.util.Scanner;
import org.junit.Test;
public class reverset {
@Test
public void testreverse() {
System.out.println("Enter the number: ");
Scanner sc=new Scanner(System.in);
int p1=sc.nextInt();
System.out.println("Enter the expected value: ");
int exp=sc.nextInt();
revClass r1=new revClass();
int n1=r1.reverse(p1);
assertEquals(n1,exp);
}}
Output:
UNIT TESTING PROGRAM digits of sum(just for practice)
sum.java
package sumofdigits;
import java.util.Scanner;
public class sum
{
public int digits(int number)
{
int digit,sum = 0;
while(number > 0)
{
digit = number % 10;
sum = sum + digit;
number = number / 10;
}
return sum;
}
public static void main(String[] args)
{
}
}
digit.java
package sumofdigits;
import java.util.Scanner;
import static org.junit.Assert.*;
import org.junit.Test;
@Test
public void testsum() {
int n,n1;
sum r1=new sum();
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
n=sc.nextInt();
System.out.print("Enter the expected sum of digits: ");
n1=sc.nextInt();
int s=r1.digits(n);
assertEquals(s,n1);
}
}
B1->12-08-2024
PRAC 6A
ExcelupdateClasss.java
package ExcelupdatePackage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
}
Add jxl file through add external jar files
PRAC 6 B
package combop;
import jxl.Cell;
import jxl.read.biff.BiffException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.*;
import jxl.write.*;
import java.io.*;
import jxl.*;
public class count
{
@BeforeClass
public void f1()
{}
@Test
public void test2() throws Exception
{
FileInputStream fi=new
FileInputStream("D:\\TYCS_RANJEET_TecH_RC\\selenium pracs\\myBook1.xls");
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);
String a[][]=new String[s.getRows()][s.getColumns()];
FileOutputStream fo=new
FileOutputStream("D:\\TYCS_RANJEET_TecH_RC\\selenium pracs\\myBook1res.xls");
WritableWorkbook wwb=Workbook.createWorkbook(fo);
WritableSheet ws=wwb.createSheet("result1",0);
int c=0;
for(int i=0;i<s.getRows();i++)
for(int j=0;j<s.getColumns();j--)
{
if(i>=1)
{
String b=new String();
b=s.getCell(3,i).getContents();
int x=Integer.parseInt(b);
if(x<60)
{
c++;
break;
}
}
a[i][j]=s.getCell(j,i).getContents();
Label l2=new Label(j,i-c,a[i][j]);
ws.addCell(l2);
}
wwb.write();
wwb.close();
}
}
Output:
5/08/24
Prac8
Save in wamp64 -> www folder
state.html
<html>
<head>
<title>States</title>
</head>
<body>
<form name="f1" action="POST">
States:
<select id="statename">
<option>Maharashtra</option>
<option>Kerala</option>
<option>Jammu&Kashmir</option>
<option>Manipur</option>
</select>
</form>
</body>
</html>
Combo
package combopack;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
public class combo {
System.setProperty("webdriver.firefox.marionette","D:\\TYCS_RANJEET_TecH_RC\\Seleniu
m\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://localhost/state.html");
Select selectDropdown=new Select(driver.findElement(By.id("statename")));
java.util.List<WebElement>optionCount=driver.findElements(By.xpath("//select/option"));
System.out.println("Total number of item count in dropdown
list="+optionCount.size());
for(int i=0;i<optionCount.size();i++)
{
System.out.println(optionCount.get(i).getText());
}
}
Output:
5/8/2024
package prac7;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
public class prac6
{
public static void main(String[] args)
{
System.setProperty("webdriver.firefox.marionette","D:\\TYCS_RANJEET_Tec
H_RC\\Selenium\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.rediff.com");
java.util.List<WebElement>links=driver.findElements(By.tagName("a"));
System.out.print("Total links are="+links.size());
for(int i=0;i<links.size();i++)
{
System.out.println("Link"+i+"Link
Name"+links.get(i).getText());
}
}
Output:
Prac 9 26/08/2024
hobbies.html
<html>
<head><title>Hobby</title></head>
<body>
<form method="POST">
Hobbies:
<input type="checkbox" id="c1" value="dance">Dancing<br>
<input type="checkbox" id="c2" value="draw">Drawing<br>
<input type="checkbox" id="c3" value="sing">Singing<br>
<input type="checkbox" id="c4" value="trek">Trekking<br>
<input type="checkbox" id="c5" value="cook">Cooking<br>
</form>
</body>
</html>
Check
package checkbox;
Import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
public class check
{
public static void main(String[] args)
{
System.setProperty("webdriver.firefox.marionette","D:\\TYCS_RANJEET_Tec
H_RC\\Selenium\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://localhost/hobbies.html");
driver.findElement(By.xpath("//input[@value='dance']")).click();
driver.findElement(By.xpath("//input[@value='draw']")).click();
java.util.List<WebElement>
elements=driver.findElements(By.xpath("//input[@type='checkbox']"));
int checkedcount=0;
int uncheckedcount=0;
for(int i=0;i<elements.size();i++)
{
if(elements.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);
}
}
Output:
Jmeter