SELENIUM LAB MANUAL
Common Setup (Do Once Before All Experiments)
1. Install Java JDK 11/17 (or higher) and set JAVA_HOME and Path.
2. Install Eclipse IDE for Java Developers.
3. Create a Maven Project in Eclipse (File > New > Maven Project).
4. In [Link], add Selenium dependency (selenium-java 4.x) and save.
5. Right-click project > Maven > Update Project (Force Update).
6. Create package: src/main/java > [Link].
7. Ensure Google Chrome or Microsoft Edge is installed and updated.
Note: Selenium Manager (Selenium 4.6+) usually downloads the correct driver automatically. So you
normally do not need to download [Link] or set [Link] for drivers.
Experiment 1: Recording in Context Sensitive Mode and Analog Mode (Selenium
IDE)
Tools/Requirements:
• Selenium IDE extension (Chrome/Edge)
• Any demo site for drag-and-drop (optional)
Procedure:
1. Open Chrome/Edge and install the Selenium IDE extension from the browser extensions store.
2. Click the Extensions icon and open Selenium IDE.
3. Click 'Create a new project' and enter a project name.
4. Click 'Add new test' and name the test case (e.g., TC_Record_Google).
5. Click the red 'Record' button.
6. Enter the base URL (e.g., [Link] and click 'Start Recording'.
7. Perform actions: click the search box, type a keyword, press Enter, click a result, then go back.
8. Stop recording and review the generated commands (open, click, type, assert).
9. Run the test using the 'Run current test' (play) button.
10. For analog-style actions: try recording a drag-and-drop or slider movement on a demo site and
replay it.
11. Save the project in Selenium IDE.
Notes:
• Selenium IDE is mainly context-sensitive (element based). True analog recording is limited.
• For complex gestures use Selenium WebDriver code with the Actions class.
Output:
Running 'TC_Record_Google'
open | [Link] |
type | name=q | selenium
assertTitle | Google |
Test completed successfully
Result: PASS
Experiment 2: GUI Checkpoint for Single Property (Title/Text/Attribute)
Tools/Requirements:
• Selenium WebDriver (Java)
• TestNG or JUnit (recommended)
Procedure:
1. Create a new Java class in package [Link] (e.g., Exp2_SinglePropertyCheckpoint).
2. Launch the browser using Selenium WebDriver and open the target URL.
3. Choose one GUI property to verify (page title OR element text OR an attribute).
4. Capture the actual value ([Link]() / [Link]() / [Link]()).
5. Compare with expected value using assertion (TestNG/JUnit) or if-else logic.
6. Print PASS/FAIL in the console.
7. Close the browser.
Notes:
• Use WebDriverWait if the page/property loads slowly.
Sample Java Code:
// Exp 2: Single Property Checkpoint (Page Title)
package [Link];
import [Link];
import [Link];
public class Exp2_SinglePropertyCheckpoint {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
[Link]("[Link]
String expectedTitle = "Google";
String actualTitle = [Link]();
[Link]("Actual Title : " + actualTitle);
[Link]("Expected Title : " + expectedTitle);
if ([Link](expectedTitle)) {
[Link]("PASS: Title is correct");
} else {
[Link]("FAIL: Title is incorrect");
}
[Link](2000);
[Link]();
}
}
Output
Actual Title : Google
Expected Title : Google
PASS: Title is correct
Experiment 3: GUI Checkpoint for Single Object/Window (Displayed/Enabled)
Tools/Requirements:
• Selenium WebDriver (Java)
Procedure:
1. Create a new Java class (e.g., Exp3_SingleObjectCheckpoint).
2. Launch browser and open the URL.
3. Identify the target element and choose a stable locator (id/name/css/xpath).
4. Use WebDriverWait to wait until the element is present/visible.
5. Verify one condition (isDisplayed / isEnabled / isSelected).
6. Print PASS/FAIL and close the browser.
Notes:
• Avoid [Link] for synchronization; prefer explicit waits.
Sample Java Code:
// Exp 3: Single Object Checkpoint (Element displayed and enabled)
package [Link];
import [Link].*;
import [Link];
public class Exp3_SingleObjectCheckpoint {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
[Link]("[Link]
WebElement searchBox = [Link]([Link]("q"));
[Link]("Displayed: " + [Link]());
[Link]("Enabled : " + [Link]());
[Link]([Link]() && [Link]()
? "PASS: Search box is ready"
: "FAIL: Search box is not ready");
[Link](2000);
[Link]();
}
}
Experiment 4(a): Bitmap Checkpoint for Object/Window (Screenshot Comparison)
Algorithm / Steps
1. Start the program.
2. Launch the Chrome browser.
3. Open the Google homepage.
4. Locate the Google Search Box using its name attribute (q).
5. Create a folder named Screenshots if it does not already exist.
6. Capture the screenshot of the search box object.
7. Save the screenshot as current_searchbox.png.
8. Check whether baseline_searchbox.png exists.
9. If the baseline image is not found:
o Display a message asking the user to rename current_searchbox.png to
baseline_searchbox.png.
10. If the baseline image exists:
o Compare the baseline and current images pixel by pixel.
11. If both images are identical:
o Display BITMAP CHECKPOINT : TEST PASS.
12. Otherwise:
o Display BITMAP CHECKPOINT : TEST FAIL.
13. Close the browser.
package [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class NewTest{
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
try {
[Link]("[Link]
// Locate object
WebElement searchBox = [Link]([Link]("q"));
// Create Screenshots folder
File folder = new File("Screenshots");
if (![Link]()) {
[Link]();
}
// Capture current screenshot
File currentImage =
[Link]([Link]);
File currentFile =
new File("Screenshots/current_searchbox.png");
[Link](currentImage, currentFile);
[Link]("Current screenshot saved:");
[Link]([Link]());
// Baseline image
File baselineFile =
new File("Screenshots/baseline_searchbox.png");
if (![Link]()) {
[Link]("Baseline image not found.");
[Link]("Rename current_searchbox.png as baseline_searchbox.png");
}
else {
boolean result = compareImages(baselineFile, currentFile);
if(result) {
[Link]("BITMAP CHECKPOINT : TEST PASS");
[Link]("Images are identical.")
}
else {
[Link]("BITMAP CHECKPOINT : TEST FAIL");
[Link]("Images are different.");
}
}
}
catch(Exception e) {
[Link]("Execution Failed");
[Link]();
}
finally {
[Link]();
} }
// Method to compare image pixels
public static boolean compareImages(File img1, File img2)
throws Exception {
BufferedImage image1 = [Link](img1);
BufferedImage image2 = [Link](img2);
if([Link]()!=[Link]()|| [Link]()!=[Link]())
{
return false;
}
for(int x=0; x<[Link](); x++)
{
for(int y=0; y<[Link](); y++)
{
if([Link](x,y) != [Link](x,y)
return false;
}
}
}
return true;
}
First Excecution
Current screenshot saved:
C:\Users\YourName\eclipse-workspace\YourProject\Screenshots\current_searchbox.png
Baseline image not found.
Rename current_searchbox.png as baseline_searchbox.png
Second Execution
Current screenshot saved:
C:\Users\YourName\eclipse-workspace\YourProject\Screenshots\current_searchbox.png
BITMAP CHECKPOINT : TEST PASS
Images are identical.
Experiment 4(b): Bitmap Checkpoint for Screen Area (Crop + Compare)
Algorithm / Steps
1. Start the program.
2. Launch the Chrome browser.
3. Maximize the browser window.
4. Open the Google homepage.
5. Wait for 3 seconds to allow the page to load completely.
6. Capture a screenshot of the entire browser window.
7. Convert the screenshot into a BufferedImage.
8. Create a folder named C:\SeleniumScreenshots if it does not already exist.
9. Crop the top-left screen area of size 800 × 600 pixels.
10. Save the cropped image as current_google_area.png.
11. Check whether baseline_google_area.png exists.
12. If the baseline image does not exist:
o Display a message asking the user to rename current_google_area.png as
baseline_google_area.png.
13. If the baseline image exists:
o Compare the baseline image and the current image pixel by pixel.
o Calculate the similarity percentage.
14. If the similarity is 95% or more, display TEST PASS.
15. Otherwise, display TEST FAIL.
16. Close the browser.
17. End the program.
import [Link];
import [Link].*;
import [Link];
public class NewTest {
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
try {
[Link]().window().maximize();
[Link]("[Link]
[Link](3000);
// Capture screenshot
File screenshot =((TakesScreenshot) driver).getScreenshotAs([Link]);
BufferedImage fullImage = [Link](screenshot);
// Local folder
File folder = new File("C:\\SeleniumScreenshots");
if (![Link]())
{
[Link]();
}
// Capture screen area
int width = [Link](800, [Link]());
int height = [Link](600, [Link]());
BufferedImage currentArea = [Link](0,0,width,height);
File currentFile = new File( "C:\\SeleniumScreenshots\\current_google_area.png");
[Link](currentArea, "png", currentFile);
[Link]( "Current screenshot saved:");
[Link]([Link]());
File baselineFile = new File("C:\\SeleniumScreenshots\\baseline_google_area.png");
if(![Link]()) {
[Link]("Baseline image not found.");
[Link]("Rename current_google_area.png to baseline_google_area.png");
}
else {
BufferedImage baseline = [Link](baselineFile);
double similarity =compareImages(baseline, currentArea);
[Link]( "Image Similarity : " + similarity + "%");
if(similarity >= 95) {
[Link]( "BITMAP CHECKPOINT : TEST PASS");
}
else {
[Link]("BITMAP CHECKPOINT : TEST FAIL");
}
}
}
finally {
[Link]();
}
}
public static double compareImages( BufferedImage img1,BufferedImage img2)
{
if([Link]()!=[Link]() || [Link]()!=[Link]()) {
return 0;
}
long totalPixels = [Link]()* [Link]();
long samePixels = 0;
for(int x=0; x<[Link](); x++)
{
for(int y=0; y<[Link](); y++)
{
if([Link](x,y) == [Link](x,y))
{
samePixels++;
}
}
return
((double)samePixels / totalPixels) * 100;
Output
First Execution
Current screenshot saved:
C:\SeleniumScreenshots\current_google_area.png
Baseline image not found.
Rename current_google_area.png to baseline_google_area.png
Second Execution
Current screenshot saved:
C:\SeleniumScreenshots\current_google_area.png
Image Similarity : 99.72%
BITMAP CHECKPOINT : TEST PASS
Experiment 5: Database Checkpoint – Default Check (Record Exists)
***************************************
// Not For Students (for your refrence)
To install H2 DATABASE Dependency for [Link]
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.4.240</version>
</dependency>
**************************************
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class NewTest {
public static void main(String[] args) {
try {
// Connect to H2 Database
Connection con =
[Link]("jdbc:h2:./StudentDB","sa","");
Statement stmt = [Link]();
// Create table if it does not exist
[Link]("CREATE TABLE IF NOT EXISTS STUDENT ("+ "ID INT PRIMARY KEY,
"+ "NAME VARCHAR(50),"+ "EMAIL VARCHAR(100))");
// Remove previous data (optional)
[Link]("DELETE FROM STUDENT");
// Insert one record
[Link]("INSERT INTO STUDENT VALUES " +
"(1,'Ajay','ajay@[Link]')");
// Database Checkpoint
ResultSet rs = [Link]("SELECT * FROM STUDENT WHERE ID = 1");
if ([Link]()) {
[Link]("Record Exists");
[Link]("ID : " + [Link]("ID"));
[Link]("Name : " + [Link]("NAME"));
[Link]("Email : " + [Link]("EMAIL"));
[Link]("TEST PASSED");
} else {
[Link]("Record Not Found");
[Link]("TEST FAILED");
}
// Close connection
[Link]();
} catch (Exception e) {
[Link]();
}
}
}
Output
Record Exists
ID : 1
Name : Ajay
Email : ajay@[Link]
TEST PASSED
Process finished with exit code 0
=================================================================================
Experiment 6: Database Checkpoint – Custom Check (Validate Specific Value)
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class NewTest{
public static void main(String[] args) {
try {
// Connect to H2 Database
Connection con = [Link](
"jdbc:h2:./StudentDB", "sa", "");
Statement stmt = [Link]();
// Create table if it does not exist
[Link]("CREATE TABLE IF NOT EXISTS STUDENT ("
+ "ID INT PRIMARY KEY, "
+ "NAME VARCHAR(50), "
+ "EMAIL VARCHAR(100))");
// Delete previous records
[Link]("DELETE FROM STUDENT");
// Insert sample record
[Link](
"INSERT INTO STUDENT VALUES "
+ "(1,'Ajay','ajay@[Link]')");
// Retrieve the record
ResultSet rs = [Link](
"SELECT NAME FROM STUDENT WHERE ID = 1");
if ([Link]()) {
String actualName = [Link]("NAME");
String expectedName = "Ajay";
// Custom Check
if ([Link](expectedName)) {
[Link]("Expected Name : " + expectedName);
[Link]("Actual Name : " + actualName);
[Link]("CUSTOM CHECK PASSED");
} else {
[Link]("Expected Name : " + expectedName);
[Link]("Actual Name : " + actualName);
[Link]("CUSTOM CHECK FAILED");
}
} else {
[Link]("Record Not Found");
}
[Link]();
} catch (Exception e) {
[Link]();
}
}
}
Output
Expected Name : Ajay
Actual Name : Ajay
CUSTOM CHECK PASSED
Process finished with exit code 0
=================================================================================
Experiment 7(a): Data Driven Test – Dynamic Test Data Submission
Create Html file
<!DOCTYPE html>
<html>
<head>
<title>Student Registration</title>
</head>
<body>
<h2>Student Registration Form</h2>
<label>Name:</label>
<input type="text" id="name"><br><br>
<label>Email:</label>
<input type="text" id="email"><br><br>
<button onclick="submitForm()">Submit</button>
<p id="result"></p>
<script>
function submitForm(){
var name=[Link]("name").value;
var email=[Link]("email").value;
[Link]("result").innerHTML=
"Registration Successful";
}
</script>
</body>
</html>
Save the Html file in the location which is in BOLD in program
package [Link];
import [Link].*;
import [Link];
public class DynamicDataSubmission {
public static void main(String[] args)
throws Exception {
WebDriver driver = new ChromeDriver();
// Open local HTML page
[Link]("[Link]
// Dynamic Test Data
String[][] data = {
{"Ajay","ajay@[Link]"},
{"Rahul","rahul@[Link]"},
{"Anita","anita@[Link]"}
};
for(int i=0;i<[Link];i++)
{
WebElement name = [Link]([Link]("name"));
WebElement email = [Link]([Link]("email"));
[Link]();
[Link]();
[Link](data[i][0]);
[Link](data[i][1]);
[Link]([Link]("button")).click();
String result = [Link](
[Link]("result")).getText();
[Link]("-----------------------");
[Link]("Test Case : "+(i+1));
[Link]("Name : "+data[i][0]);
[Link]("Email : "+data[i][1]);
[Link](result);
if([Link]("Registration Successful"))
[Link]("TEST PASS");
else
[Link]("TEST FAIL");
[Link](1000);
}
[Link]();
}
}
Output
Test Case : 1
Name : Ajay
Email : ajay@[Link]
Registration Successful
TEST PASS
-----------------------
Test Case : 2
Name : Rahul
Email : rahul@[Link]
Registration Successful
TEST PASS
-----------------------
Test Case : 3
Name : Anita
Email : anita@[Link]
Registration Successful
TEST PASS
=================================================================================
Experiment 7(b):Data Driven Test – Through Flat Files (CSV/TXT)
Step 1: Create a HTML File([Link])
<!DOCTYPE html>
<html>
<head>
<title>Student Registration Form</title>
</head>
<body>
<h2>Student Registration Form</h2>
<label>Name :</label>
<input type="text" id="name">
<br><br>
<label>Email :</label>
<input type="text" id="email">
<br><br>
<button onclick="submitForm()">Submit</button>
<p id="result"></p>
<script>
function submitForm()
{
var name=[Link]("name").value;
var email=[Link]("email").value;
if(name!="" && email!="")
{
[Link]("result").innerHTML=
"Registration Successful";
}
else
{
[Link]("result").innerHTML=
"Registration Failed";
}
}
</script>
</body>
</html>
Step 2: Create CSV file with data([Link])
Ajay,ajay@[Link]
Rahul,rahul@[Link]
Anita,anita@[Link]
Step 3 Selenium Code
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DataDrivenCSV {
public static void main(String[] args) throws Exception {
// Launch Chrome
WebDriver driver = new ChromeDriver();
// Maximize browser
[Link]().window().maximize();
// Open HTML page
[Link]("[Link]
// Read CSV file
BufferedReader br =
new BufferedReader(
new FileReader(
"C:\\SeleniumFiles\\[Link]"));
String line;
int testCase = 1;
while ((line = [Link]()) != null) {
// Split CSV data
String[] data = [Link](",");
// Locate elements
WebElement name =
[Link]([Link]("name"));
WebElement email =
[Link]([Link]("email"));
// Clear old values
[Link]();
[Link]();
// Enter data
[Link](data[0]);
[Link](data[1]);
// Click Submit
[Link]([Link]("button")).click();
// Read Result
String result =
[Link]([Link]("result")).getText();
// Display Output
[Link]("--------------------------------");
[Link]("Test Case : " + testCase);
[Link]("Name : " + data[0]);
[Link]("Email : " + data[1]);
[Link]("Expected Result : Registration Successful");
[Link]("Actual Result : " + result);
if([Link]("Registration Successful"))
{
[Link]("TEST PASS");
}
else
{
[Link]("TEST FAIL");
}
testCase++;
[Link](1500);
[Link]();
[Link]();
Output
Test Case : 1
Name : Ajay
Email : ajay@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
--------------------------------
Test Case : 2
Name : Rahul
Email : rahul@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
--------------------------------
Test Case : 3
Name : Anita
Email : anita@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
==================================================================================
Experiment 7(c): Data Driven Test – Through Front Grids (Web Tables)
Create Html file(web_table)
<!DOCTYPE html>
<html>
<head>
<title>Front Grid Example</title>
</head>
<body>
<h2>Student Data (Front Grid)</h2>
<table border="1" id="studentTable">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
<tr>
<td>Ajay</td>
<td>ajay@[Link]</td>
</tr>
<tr>
<td>Rahul</td>
<td>rahul@[Link]</td>
</tr>
<tr>
<td>Anita</td>
<td>anita@[Link]</td>
</tr>
</table>
<br><br>
<h2>Registration Form</h2>
Name :
<input type="text" id="name">
<br><br>
Email :
<input type="text" id="email">
<br><br>
<button onclick="submitForm()">
Submit
</button>
<p id="result"></p>
<script>
function submitForm(){
[Link]("result").innerHTML=
"Registration Successful";
}
</script>
</body>
</html>
Selenium Code
package [Link];
import [Link];
import [Link].*;
import [Link];
public class DataDrivenFrontGrid {
public static void main(String[] args)
throws Exception {
WebDriver driver = new ChromeDriver();
[Link]().window().maximize();
[Link]("[Link]
// Read all rows except header
List<WebElement> rows =
[Link](
[Link]("//table[@id='studentTable']/tbody/tr"));
for(int i=2;i<=[Link]();i++) {
String name =
[Link](
[Link]("//table[@id='studentTable']/tbody/tr["+i+"]/td[1]"))
.getText();
String email =
[Link](
[Link]("//table[@id='studentTable']/tbody/tr["+i+"]/td[2]"))
.getText();
WebElement txtName =
[Link]([Link]("name"));
WebElement txtEmail =
[Link]([Link]("email"));
[Link]();
[Link]();
[Link](name);
[Link](email);
[Link](
[Link]("button")).click();
String result =
[Link](
[Link]("result")).getText();
[Link]("--------------------");
[Link]("Name : " + name);
[Link]("Email : " + email);
[Link](result);
if([Link]("Registration Successful"))
[Link]("TEST PASS");
else
[Link]("TEST FAIL");
[Link](1500);
[Link]();
}
OutPut
Name : Ajay
Email : ajay@[Link]
Registration Successful
TEST PASS
--------------------
Name : Rahul
Email : rahul@[Link]
Registration Successful
TEST PASS
--------------------
Name : Anita
Email : anita@[Link]
Registration Successful
TEST PASS
====================================================================================
Experiment 7(d): Data Driven Test – Through Excel
Step 1 Create Html file ([Link])
<!DOCTYPE html>
<html>
<head>
<title>Student Registration</title>
</head>
<body>
<h2>Student Registration Form</h2>
<label>Name :</label>
<input type="text" id="name"><br><br>
<label>Email :</label>
<input type="text" id="email"><br><br>
<button onclick="submitForm()">Submit</button>
<p id="result"></p>
<script>
function submitForm(){
var name=[Link]("name").value;
var email=[Link]("email").value;
if(name!="" && email!="")
{
[Link]("result").innerHTML=
"Registration Successful";
}
else
{
[Link]("result").innerHTML=
"Registration Failed";
}
}
</script>
</body>
</html>
Step 2 Create Excel file ([Link]) with Data
Name Email
Ajay ajay@[Link]
Rahul rahul@[Link]
Anita anita@[Link]
Priya priya@[Link]
Step 3: if the Apache POI JAR either by adding Maven Dependency or as external jars
For Maven
<dependency>
<groupId>[Link]</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
Step 4 :
package [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link].*;
import [Link];
public class DataDrivenExcel {
public static void main(String[] args) throws Exception {
// Open Excel File
File file =
new File("C:\\SeleniumFiles\\[Link]");
FileInputStream fis =
new FileInputStream(file);
Workbook workbook =
new XSSFWorkbook(fis);
Sheet sheet =
[Link](0);
WebDriver driver =
new ChromeDriver();
[Link]().window().maximize();
[Link]("[Link]
// Start from row 1 because row 0 contains headers
for(int i=1; i<=[Link](); i++) {
Row row = [Link](i);
String name =
[Link](0).getStringCellValue();
String email =
[Link](1).getStringCellValue();
WebElement txtName =
[Link]([Link]("name"));
WebElement txtEmail =
[Link]([Link]("email"));
[Link]();
[Link]();
[Link](name);
[Link](email);
[Link](
[Link]("button")).click();
String result =
[Link](
[Link]("result")).getText();
[Link]("------------------------");
[Link]("Test Case : " + i);
[Link]("Name : " + name);
[Link]("Email : " + email);
[Link]("Expected Result : Registration Successful");
[Link]("Actual Result : " + result);
if([Link]("Registration Successful"))
[Link]("TEST PASS");
else
[Link]("TEST FAIL");
[Link](1000);
[Link]();
[Link]();
[Link]();
}
Output :
Test Case : 1
Name : Ajay
Email : ajay@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
------------------------
Test Case : 2
Name : Rahul
Email : rahul@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
------------------------
Test Case : 3
Name : Anita
Email : anita@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
------------------------
Test Case : 4
Name : Priya
Email : priya@[Link]
Expected Result : Registration Successful
Actual Result : Registration Successful
TEST PASS
==================================================================================
For Experiments 7(e),7(f) ,8 Testng is required to install
For Testng jars update this Dependency in [Link]
<dependency>
<groupId>[Link]</groupId>
<artifactId>testng</artifactId>
<version>7.11.0</version>
</dependency>
For Testng launcher if not installed in eclipse
In help-àGo to marketplace-à search for Testng and install it
Experiment 7(e): Batch Testing – Without Parameter Passing (Suite Run)
Step 1 Create 3 Test Classes
Class 1
package [Link];
import [Link];
public class TestBing {
@Test
public void gmailTest()
{
[Link]("Bing test executed");
Class 2
package [Link];
import [Link];
public class TestGoogle {
@Test
public void googleTest() {
[Link]("Google Test Executed");
Class 3
package [Link];
import [Link];
public class TestYahoo {
@Test
public void youtubeTest() {
[Link]("Test yahoo executed");
Step 2 Create [Link] file
Right click on your java project --à new----à file----àgive file name ([Link]) --àfinish
Paste this in [Link]
<!DOCTYPE suite SYSTEM "[Link]
<suite name="BatchSuite">
<test name="WithoutParameterPassing">
<classes>
<class name="[Link]"/>
<class name="[Link]"/>
<class name="[Link]"/>
</classes>
</test>
</suite>
Now after saving this xml -à right click on [Link] in project explorer--àRun as Testng suite
Output
Bing test executed
Google Test Executed
Test yahoo executed
===============================================
BatchSuite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================
Experiment 7(f): Batch Testing – With Parameter Passing (Suite Parameters)
Step 1 Create java class [Link]
package [Link];
import [Link];
import [Link];
public class TestParameter {
@Parameters({"username","password"})
@Test
public void login(String user, String pass) {
[Link]("Username : " + user);
[Link]("Password : " + pass);
if([Link]("admin") && [Link]("admin123")) {
[Link]("TEST PASS");
} else {
[Link]("TEST FAIL");
}
}
Step 2 Create new xml file [Link]
Right click on your java project --à new----à file----àgive file name ([Link]) --àfinish
Paste this in [Link]
<!DOCTYPE suite SYSTEM "[Link]
<suite name="ParameterSuite">
<test name="LoginTest">
<parameter name="username" value="admin"/>
<parameter name="password" value="admin123"/>
<classes>
<class name="[Link]"/>
</classes>
</test>
</suite>
Now after saving this xml -à right click on [Link] in project explorer--àRun as Testng suite
Output:
Username : admin
Password : admin123
TEST PASS
===============================================
ParameterSuite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
===================================================================================
Experiment 8: Data Driven Batch (Batch + Multiple Data Sets)
Step 1 Create java class [Link]
package [Link];
import [Link];
import [Link];
public class LoginTest {
@DataProvider(name="LoginData")
public Object[][] getData() {
return new Object[][] {
{"admin","admin123"},
{"student","student123"},
{"guest","guest123"}
};
@Test(dataProvider="LoginData")
public void login(String user,String pass) {
[Link]("Username : " + user);
[Link]("Password : " + pass);
[Link]("Login Successful");
[Link]("---------------------");
Output:
Username : admin
Password : admin123
Login Successful
---------------------
Username : student
Password : student123
Login Successful
---------------------
Username : guest
Password : guest123
Login Successful
---------------------
PASSED: [Link]("admin", "admin123")
PASSED: [Link]("student", "student123")
PASSED: [Link]("guest", "guest123")
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================
=================================================================================
Experiment 9: Silent Mode Test Execution (Headless)
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SilentModeExecution {
public static void main(String[] args) {
// Create Chrome options
ChromeOptions options = new ChromeOptions();
// Enable Headless Mode
[Link]("--headless=new");
// Optional: Set browser window size
[Link]("--window-size=1920,1080");
// Launch Chrome in Headless Mode
WebDriver driver = new ChromeDriver(options);
// Open Google
[Link]("[Link]
// Find search box
WebElement searchBox = [Link]([Link]("q"));
// Enter text
[Link]("Selenium WebDriver");
// Get page title
String title = [Link]();
[Link]("Page Title : " + title);
// Checkpoint
if ([Link]("Google")) {
[Link]("TEST PASS");
} else {
[Link]("TEST FAIL");
// Close browser
[Link]();
}
}
OutPut
Page Title : Google
TEST PASS