Testing Practical
Testing Practical
Practical – 3 :
Install Selenium server and demonstrate it using a script in Java
Documentation :
Software Needed :
1. XAMPP
2. Mozilla Firefox 38.0.5 (If higher version is installed in the system, it has
to uninstalled and the given version should be installed)
3. Java NetBeans IDE 7.0.1
4. JDK 1.8.0
5. Selenium-java-client-driver-1.0.1.jar
6. Selenium-server-standalone-3.13.0.jar - Save this file in a folder. That
folder has to be added to the path. To add a folder to the path, follow
the steps below.
a. Control Panel System and Security System
b. Advanced System Settings Environment Variables
c. Select Path variable Edit Add the absolute path of the folder
in the Path value OK
7. Before executing the java programs, Selenium server should be started
using the steps below
a. Go to Command Prompt
b. Go to the folder where you have saved the jar file
c. Execute the command
java –jar selenium-server-standalone-3.13.0.jar
d. Server will be started in a port normally in 4444.
e. Don’t close the window. Minimize it and start Java Programming
8. For all the practicals from practical 3, we need to create a package and
inside the package, we may create java class for the each practical.
9. Before coding, we need to add the jar files to the library using the
following steps
Prerequisite Knowledge :
Practical – 3 :
Install Selenium server and demonstrate it using a script in Java
Sample code:
1. Refer https://www.seleniumhq.org/docs/03_webdriver.jsp#setting-up-
webdriver-project
2. Under the topic “Introducing the Selenium-WebDriver API by
Example”, java code for accessing google webpage is given.
3. Create a new java class and paste the code.
4. Run the code. It should open firefox window and google site should be
opened with cheese as the search term
5. If this works fine, then the steps followed are right
<html>
<head>
<script type="text/javascript">
function gcd()
{
var x,y;
x=parseInt(document.myform.n1.value);
y=parseInt(document.myform.n2.value);
Prepared by : Prof. Jayshree Ravi, Mithibai College
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 two 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" name="btn" value="Get GCD" onClick="gcd()"> <br>
<br>
GCD is : <input type="text" name="result" value="">
</form>
</body>
</html>
Create a java class and paste the code. Run the code
GT.java :
package gt;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GT {
}
}
Practical – 4
Login.html:
<html>
<head>
<title>
Login page
</title>
</head>
<body>
<form id='login' action='user.php' method='post' accept-charset='UTF-8'>
UserName*:
<input type='text' name='username' id='username' maxlength="50" />
Password*:
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='button' value='Submit' />
</form>
</body>
</html>
User.php :
<?php
$u = $_POST['username'];
$p = $_POST['password'];
if(($u=="test")&&($p=="test"))
{
echo "Login Successful";
package gt;
import com.thoughtworks.selenium.webdriven.commands.Click;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {