0% found this document useful (0 votes)
61 views

Sta Manual

Uploaded by

jerujef.2723
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Sta Manual

Uploaded by

jerujef.2723
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

REGISTER NO:411721104020

ExNo:1
Develop the test plan for testing an e-commerce
web/mobile application (www.amazon.in)
Date:

AIM:
To develop the test plan for testing an e-commerce web/ mobile application .
ALGORITHM:
1. Ensure Eclipse IDE is installed and configured on your system.
2. Create a new Java class in your Eclipse project.
3. Create a new instance of the WebDriver (ChromeDriver in this case) using
WebDriver driver = new ChromeDriver().
4. Use the WebDriver instance (driver) to navigate to www.amazon.in using
driver.get("https://www.amazon.in").
5. It locates the search box on the Amazon website using its ID ("twotabsearchtextbox")
and sends the search term "laptop" to it.
6. It locates the search button on the Amazon website using its ID ("nav-search-submit-
button") and clicks it to submit the search.
7. Thread.sleep() method to wait for the search results page to load.
8. If the test fails or behaves unexpectedly, use Eclipse's debugging features to
troubleshoot issues.

PROGRAM:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonWebTest {
public static void main(String[] args) {
// Set the path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
// Create a new instance of ChromeDriver
WebDriver driver = new ChromeDriver();
// Open Amazon website
driver.get("https://www.amazon.in");
// Example: Find search box and input a search term

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


1
REGISTER NO:411721104020

driver.findElement(By.id("twotabsearchtextbox")).sendKeys("laptop");
// Example: Find search button and click it
driver.findElement(By.id("nav-search-submit-button")).click();
// Wait for search results page to load (add proper waits in real scenarios)
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Close the browser
driver.quit();
}
}

OUTPUT:

VIVA QUESTIONS:
1. What is Software Testing?
Software testing is the process of evaluating and verifying if a software product does what it is
supposed to do. The process of software testing aims not only at finding faults in the existing
software but also at finding measures to improve the software in terms of efficiency, accuracy,
and usability. It mainly aims at measuring the specification, functionality, and performance of a
software program or application.
2. Why is software testing important?
Increase the quality, Reduce risks, Security, Satisfaction of the customer, Enhancing the
development process, Determine the performance of the software

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


2
REGISTER NO:411721104020

3.What is a test case?


A test case is a document specifying the test data, precondition, expected results, and post-
conditions that are developed for a particular test scenario to determine if it satisfies software
requirements and functions correctly.

4. What are the benefits of an effective test case ?


1. Good test coverage.
2. Reusable test cases.
3. Helps to avoid training for every new test engineer.
4. Improved quality of the software.
5. More satisfied customers.

5.What is test case parameters ?


1. Test Case Name/ ID
2. Test Case Type
3. Requirement Number
4. Module
5. Severity
6. Status
7. Release
8. Version
9. Pre-condition
10.Test Data
11.Summary

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED PO’s SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to develop the test plan for testing an e-commerce web/ mobile application
has been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


3
REGISTER NO:411721104020

ExNo:2
Design the test cases for testing the e-commerce
application
Date:

AIM:
To Design the test cases for testing the e-commerce application.
ALGORITHM:
1. Import necessary Selenium libraries to interact with web elements and perform actions
on a web page.
2. Set the system property to specify the path to the ChromeDriver executable.Create a
new instance of the ChromeDriver, which will open a new Chrome browser window.
3. Find the search box element on the Amazon website using its ID
("twotabsearchtextbox").
4. Enter the specified product (laptop) into the search box using the sendKeys() method.
5. Submit the search query by invoking the submit() method on the search box element.
6. Use WebDriverWait to wait for the search results to become visible on the page. This
ensures that the script waits for the search results to load before proceeding.
7. Print out the search results to the console using the getText() method of the search
results WebElement.
8. Inside the main method, call the searchProduct() method with the WebDriver instance
and the product to search for ("Laptop").
9. When the program is executed, it will open a Chrome browser, navigate to Amazon,
search for the specified product (laptop), wait for the search results to load, and then
print out the search results to the console.
PROGRAM:
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.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ECommerceTest {
public static void main(String[] args) {
// Set the path to chromedriver.exe
System.getProperty("webdriver.chrome.driver", "
C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe ");
// Create a new instance of ChromeDriver
WebDriver driver = new ChromeDriver();

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


4
REGISTER NO:411721104020

// Open the e-commerce website


driver.get("https://www.amazon.com");
// Test Case : Verify product search functionality
searchProduct(driver, "Laptop");
// Close the browser
driver.quit();
}
// Test Case : Verify product search functionality
public static void searchProduct(WebDriver driver, String laptop) {
WebElement searchBox = driver.findElement(By.id("twotabsearchtextbox "));
searchBox.sendKeys(laptop);
searchBox.submit();
// Wait for search results to load
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("search-
results")));
// Verify search results
WebElement searchResults = driver.findElement(By.className("search-results"));
System.out.println("Search results for '" + laptop + "': " + searchResults.getText());
}
}

OUTPUT
Search results for 'Laptop': Dell Inspiron 15 3000 Series 15.6" HD Laptop, Intel Core i3-
1005G1 Processor, 8GB RAM, 256GB SSD, Webcam, HDMI, Bluetooth, Wi-Fi, Windows 10
Home, Black

VIVA QUESTIONS:

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


5
REGISTER NO:411721104020

1.What is a Test Environment?


The test environment comprises hardware and software configuration that allows testing
teams to run test cases. It is set up according to the Application Under Test. The test bed
may be a mix of the test environment and the test data with which it interacts.

2.What is Cookie Testing?


Cookie testing is a form of software testing where cookies produced in the web browser are
examined. A cookie stores user information that can be used to track users’ website navigation
and can be used to communicate between different web pages.

3.What is Dynamic Testing?


Dynamic testing is a software testing technique where the dynamic behavior of the code is
checked. The purpose of this type of testing is to check and analyze the software behavior
with dynamic variables and find the weak areas in the software runtime environment.

4.What is Risk-Based Testing?


Risk-based testing is a software testing technique that is based on the probability of the risks
and involves assessing the risk based on factors like:
 Software complexity.
 Criticality of the businesses.
 Frequency of use.
 Possible areas of defects.

5. What is Test Harness?


Test Harness is a collection of stubs, drivers, and other supporting tools that are required to
automate test execution. It allows for the automation of tests.

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT: Thus the program for designing the test cases for testing the e-commerce application
has been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


6
REGISTER NO:411721104020

ExNo:3
Test the e-commerce application and report the
defects in it
Date:

AIM:
To Test the e-commerce application and report the defects in it.
ALGORITHM:
1. Open Eclipse IDE.
2. Create a new Java class or use an existing one to write your test code.
3. Set the path to the ChromeDriver executable using System.setProperty
4. Use the get method of the WebDriver to open the e-commerce website.
5. Find the search box element using findElement method of WebDriver with
By.id locator.
6. Use the sendKeys method on the search box element to enter the search
query (e.g., "laptop").
7. Submit the search query, typically by hitting the Enter key or using the
submit method on the search box element.
8. Implement an appropriate wait mechanism (e.g., implicit wait or explicit
wait) to ensure that search results are fully loaded before proceeding.
9. Find the search results element using findElement method of WebDriver
with By.className locator.
10. Check if the search results are displayed by using the isDisplayed method
on the search results element.

PROGRAM:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ECommerceSearchTest {
public static void main(String[] args) {
// Set the path to chromedriver.exe

System.getProperty("webdriver.chrome.driver","C:\\Users\\lenovo\\Downloads\\chromedriver
_win32\\chromedriver.exe\");

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


7
REGISTER NO:411721104020

// Create a new instance of ChromeDriver


WebDriver driver = new ChromeDriver();
// Open the e-commerce website
driver.get("https://www.amazon.com");
// Locate the search bar element
WebElement searchBox = driver.findElement(By.id("twotabsearchtextbox"));
// Enter the search query
searchBox.sendKeys("laptop");
// Submit the search query
searchBox.submit();

// Wait for search results to load (you might need to add explicit waits here)
try {
Thread.sleep(5000); // Wait for 5 seconds for demonstration purposes
} catch (InterruptedException e) {
e.printStackTrace();
}
// Verify if search results are displayed
WebElement searchResults = driver.findElement(By.id("nav-search-submit-button"));
if (searchResults.isDisplayed()) {
System.out.println("Search results found for 'laptop'");
} else {
System.out.println("No search results found for 'laptop'");
}
// Close the browser
driver.quit();
}
}

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


8
REGISTER NO:411721104020

OUTPUT:

VIVA QUESTIONS:
1.What is Defect Age?
Defect Age is defined as the time difference between the defect detected date and the current
date provided the defect is still in the open state. It is divided into two parameters Defect
phase, Defect Age Time.

2. What is a Test Script?


Test scripts are step-by-step instructions containing information about the system transactions
that should be performed to validate the application or system under test.

3. What is Test Bed?


Test Bed is a platform for conducting rigorous, transparent, and replicable testing that consists
of specific hardware, software, operating system, network configuration, software
configuration, etc.

4.What is Test Closure?


Test Closure is a document that provides a summary of all the tests that are covered in the
software development lifecycle.It includes various activities like test completion reports, test
completion matrix, a summary of test results, etc.

5.What is a Stub?
A stub is a small piece of code that is used during Top-down Integration Testing that takes
the place of another component during testing. These act as a temporary replacement for the
module and give the same output as that of the actual product

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


9
REGISTER NO:411721104020

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to test the defects in e-commerce website has been executed
successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


10
REGISTER NO:411721104020

ExNo:4
Develop the test plan and design the test cases for an
inventory control system
Date:

AIM:
To develop the test plan and design the test cases for an inventory control system.
ALGORITHM:
1.Import Required Libraries: Import the necessary Selenium libraries.
2.Main Class (OnlineInventoryControlSystemTest):
 Set the system property to specify the path to the ChromeDriver executable.
 Initialize the WebDriver by creating a new instance of the ChromeDriver.
 Launch the online inventory control system by navigating to the specified URL.
3.Test Plan:Define the test cases to be executed:
 Test Case 1: Verify login functionality
 Test Case 2: Add a new item to inventory
 Test Case 3: Search for an existing item in inventory
4.Test Case 1: Verify Login Functionality:
 Find the username, password, and login button elements on the login page.
 Input valid username and password.
 Click on the login button.
 Verify that the user is redirected to the dashboard by checking the current URL.
 Print out whether the login test passed or failed based on the URL comparison.
5.Test Case 2: Add New Item to Inventory:
 Find the "Add Item" button on the page and click it.
 Locate the item name and quantity input fields and the "Add" button on the form.
 Input the item details (name and quantity).
 Click on the "Add" button.
 Verify that the success message confirming the item addition is displayed.
 Print out whether the add item test passed or failed based on the visibility of the
success message.
6.Test Case 3: Search for an Existing Item in Inventory:
 Locate the search result element on the page.
 Verify that the search result is displayed.
 Print out whether the search test passed or failed based on the visibility of the search
result.
7.Close the Browser: Quit the WebDriver to close the browser window

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


11
REGISTER NO:411721104020

PROGRAM:
package seleniumtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class OnlineInventoryControlSystemTest {

public static void main(String[] args) {


// Set the path to chromedriver executable

System.getProperty("webdriver.chrome.driver","C:\\Users\\lenovo\\Downloads\\chromedriver_wi
n32\\chromedriver.exe");

// Initialize WebDriver
WebDriver driver = new ChromeDriver();

// Launch the online inventory control system


driver.get("https://app.sortly.com/");

// Test Plan:
// Test Case 1: Verify login functionality
// Test Case 2: Add new item to inventory
// Test Case 3: Search for an existing item in inventory

// Test Case 1: Verify login functionality


// Input: Valid username and password
WebElement usernameInput = driver.findElement(By.xpath("//input[@name='email']"));
WebElement passwordInput=driver.findElement(By.xpath("//input[@name='password']"));
WebElement loginButton = driver.findElement(By.xpath("//button[@type='submit']"));

usernameInput.sendKeys("[email protected]");
passwordInput.sendKeys("@aaranish2691");
loginButton.click();

// Expected: User should be redirected to dashboard


driver.get("https://app.sortly.com/items/");
String currentUrl = driver.getCurrentUrl();
System.out.println("Current URL: " + currentUrl);

if (currentUrl.equals("https://app.sortly.com/items/")) {
System.out.println("Login Test Passed");
} else {
System.out.println("Login Test Failed");
}

// Test Case 2: Add new item to inventory

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


12
REGISTER NO:411721104020

// Input: Item details

WebElement addItemButton =
driver.findElement(By.xpath("//button[@type='button']"));
addItemButton.click();

WebElement itemNameInput = driver.findElement(By.xpath("//input[@name='name']"));


WebElement quantityInput=driver.findElement(By.xpath("//input[@name='quantity']"));
WebElement addButton = driver.findElement(By.xpath("//button[@type='submit']"));

itemNameInput.sendKeys("paper");
quantityInput.sendKeys("1");
addButton.click();

// Expected: Item should be added to inventory


WebElement itemAddedMessage = driver.findElement(By.xpath("//span[contains(.,'paper
has been successfully created')]"));
if (itemAddedMessage.isDisplayed()) {
System.out.println("Add Item Test Passed");
} else {
System.out.println("Add Item Test Failed");
}
// Expected: Item should be found in inventory
WebElement searchResult = driver.findElement(By.xpath("//a[contains(text(),'All
Items')]"));
if (searchResult.isDisplayed()) {
System.out.println("Search Test Passed");
} else {
System.out.println("Search Test Failed");
}

// Close the browser


driver.quit();
}
}

OUTPUT:

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


13
REGISTER NO:411721104020

VIVA QUESTIONS:
1.What is Test Strategy?
Test Strategy is a document that outlines the testing technique that is used in the Software
Development Life Cycle and guides QA teams to define Test Coverage and Testing scope.

2.What is Test Scenario?


A test Scenario is a detailed document that covers end to end functionality of a software
application that can be tested. It is also known as Test Possibility or Test Condition.

3. Explain the role of testing in software development.


 Examine the code for discovering problems and errors early in the system.
 Testing evaluates the capabilities of the program over the entire product.
 Testing helps in reviewing requirements and design as well as executing the code.

4.What is a bug report?


During testing, the tester records all the observations, and other information useful for the
developers or the management. This test record is known as a bug report.

5.What is the purpose of risk-based testing?


Risk-based testing involves accessing the risk based on the software complexity, frequency
of use, and many other factors. It prioritizes testing of the functionality and features of the
system which are more impactful and are likely to have defects.

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program for developing the test plan and design the test cases for an
inventory control system has been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


14
REGISTER NO:411721104020

ExNo:5
Execute the test cases against a client server or
desktop application and identify the defects
Date:

AIM:
To Execute the test cases against a client server or desktop application and identify
the defects.

ALGORITHM:
1.Set ChromeDriver Path: Set the system property to specify the path to the ChromeDriver
executable.
2.Set Chrome Options (Optional): Optionally, configure Chrome options like running in
headless mode or setting other browser preferences.
3.Initialize WebDriver: Create a new instance of the ChromeDriver, optionally passing the
ChromeOptions if configured.
4.Maximize Browser Window: Maximize the browser window to ensure consistent testing
behavior.
5.Navigate to Application Under Test (AUT): Open the specified URL of the application
under test (Facebook in this case).
6.Test Case 1
 Find the username and password input fields using their respective IDs.
 Enter the username and password.
 Locate and click the login button.
7.Optionally, wait for the page to load or for a specific element to appear using a brief
sleep.Perform an assertion to check if the login was successful by verifying the presence of a
welcome message.
8.Print out a message indicating whether the test case passed or failed.
9.Handle Exceptions: Catch any exceptions that occur during test execution and log them.
10.Close the Browser: Quit the WebDriver to close the browser window after completing all
test cases.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


15
REGISTER NO:411721104020

PROGRAM:
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.chrome.ChromeOptions;
public class WebTest {
public static void main(String[] args) {
// Set path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe ");

// Optional: Set Chrome options


ChromeOptions options = new ChromeOptions();
// Add options if needed, such as headless mode: options.setHeadless(true);

// Initialize WebDriver
WebDriver driver = new ChromeDriver(options);
// Maximize the browser window
driver.manage().window().maximize();

// Navigate to the application under test


driver.get(("https://www.facebook.com ");

// Test case 1:
try {
// Find username and password fields
WebElement usernameField = driver.findElement(By.id("email"));
WebElement passwordField = driver.findElement(By.id("password"));

// Enter username and password

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


16
REGISTER NO:411721104020

usernameField.sendKeys("[email protected]");
passwordField.sendKeys("prince2024");

// Find and click login button


WebElement loginButton = driver.findElement(By.id("loginButton"));
loginButton.click();

// Wait for page to load or any specific element to appear


Thread.sleep(2000);

// Assertion to check if login was successful


WebElement welcomeMessage = driver.findElement(By.id("welcomeMessage"));
if (welcomeMessage.getText().contains("Welcome")) {
System.out.println("Test case 1 passed: Login successful");
} else {
System.out.println("Defect: Test case 1 failed - Login unsuccessful");
}
} catch (Exception e) {
// Log any exceptions or errors
System.out.println("Error in Test case 1: " + e.getMessage());
}

// Close the browser


driver.quit();
}
}
OUTPUT:

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


17
REGISTER NO:411721104020

VIVA QUESTIONS:
1.What is Process Metrics?
These metrics are essential for the improvement and maintenance of the process in SDLC.
These are used to improve the process efficiency of the SDLC.

2.What is Product Metrics?


These define the size, performance, quality, and complexity of the product. It deals with the
quality of the software product and thus can help developers to enhance the software product
quality

3.What is Project Metrics?


These define the overall quality of the project. These can be used to measure the efficiency
of the project team or any testing tools being used by the team members.

4.What do you mean by Defect Cascading?


Defect Cascading is when one defect leads to the discovery of another defect by software
testers. There are several reasons behind defect cascading but one of the main reasons is it
occurs because the original defect was not fixed properly.

5.What is Test-Driven Development?


Test-driven development is the software development approach in which test cases are created
for each functionality and tested first and if the test fails then a new code is written to pass
the test, thus making the code bug-free. It is an iterative approach that involves combining
the two processes, the creation of test cases, and refactoring

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program for executing the test cases against a client server or desktop
application and identify the defects has been executed successfully

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


18
REGISTER NO:411721104020

ExNo:6
Test the performance of the e-commerce application
Date:

AIM:
To Test the performance of the e-commerce application.
ALGORITHM:

1. Set the system property to specify the path to the ChromeDriver executable file.
2. Create a new instance of the ChromeDriver class, which represents the Chrome browser.
3. Record the current system time using System.currentTimeMillis() to mark the start
time before navigating to the webpage.
4. Use the get() method of the WebDriver instance to navigate to the home page of the
e-commerce application (in this case, Amazon).
5. Calculate the page load time by subtracting the start time recorded earlier from the
current time when the page has fully loaded.
6. Print the page load time to the console, indicating how long it took for the webpage to
load.
7. Close the browser using the quit() method of the WebDriver instance to release the
associated resources.

PROGRAM:
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ECommercePerformanceTest {
public static void main(String[] args) {
// Set the path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
// Create a new instance of ChromeDriver
WebDriver driver = new ChromeDriver();
// Start the timer
long startTime = System.currentTimeMillis();
// Navigate to the home page of the e-commerce application
driver.get("http://www.amazon.com/");

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


19
REGISTER NO:411721104020

// Calculate the page load time


long loadTime = System.currentTimeMillis() - startTime;
// Print the page load time
System.out.println("Page load time: " + loadTime + " milliseconds");
// Close the browser
driver.quit(); } }

OUTPUT:

VIVA QUESTIONS:
1.What is a bug?
It is a flaw in the software which means that the software is not working as per the
requirement. When there is a coding error, it leads to a program breakdown, which is known
as a bug.
2.What is a defect?
It occurs when an application is not working as per the requirements. It is the deviation or the
difference between the expected output and the actual output.
3. What is an error?
It is a mistake made in the code due to which the code cannot be executed.
4. What is a fault?
It can be termed as a condition that causes the software to fail to perform its required
function according to the specification.
5.What is a failure?
It is the inability of the software or system to perform the required function due to the
accumulation of several defects that ultimately results in the loss of information in critical
modules and thus make the system unresponsive.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


20
REGISTER NO:411721104020

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program for testing the performance of the e-commerce application has
been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


21
REGISTER NO:411721104020

ExNo:7
Automate the testing of e-commerce using selenium
Date:

AIM:
To Automate the testing of e-commerce applications using selenium.
ALGORITHM:
1. Set ChromeDriver Path: Set the system property to specify the path to the
ChromeDriver executable.
2. Initialize WebDriver: Create a new instance of the ChromeDriver.
3. Maximize Browser Window: Maximize the browser window to ensure consistent
testing behavior.
4. Navigate to E-commerce Website: Open the specified URL of the e-commerce website
(Amazon in this case).
5. Find Search Box Element: Locate the search box element on the webpage using its ID.
6. Enter Search Query: Send the search query "pen" to the search box element.
7. Find and Click Search Button: Locate the search button element and click it to initiate
the search.
8. Wait for Search Results to Load: Use a static sleep to pause the script execution for 3
seconds to wait for the search results to load. Note: Using dynamic waits like
WebDriverWait is preferred over static sleeps.
9. Verify Search Results: Find the search results element and verify if it is displayed.
Print a message indicating whether the search results are displayed successfully or not.
10. Close the Browser: Quit the WebDriver to close the browser window after completing
the test.

PROGRAM:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ECommerceTest {
public static void main(String[] args) {
// Set the path to chromedriver.exe

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


22
REGISTER NO:411721104020

System.getProperty("webdriver.chrome.driver", "
C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
// Create a new instance of the ChromeDriver
WebDriver driver = new ChromeDriver();
// Maximize the browser window
driver.manage().window().maximize();
// Navigate to the e-commerce website
driver.get("http://www.amazon.com");
// Find the search box element
WebElement searchBox = driver.findElement(By.id("twotabsearchtextbox"));
// Enter the search query
searchBox.sendKeys("pen");
// Find the search button element and click it
WebElement searchButton = driver.findElement(By.id("nav-search-submit-button"));
searchButton.click();
// Wait for search results to load
// Note: For simplicity, we're using a static sleep here. In practice, it's better to use
dynamic waits.
try {
Thread.sleep(3000); // 3 seconds
} catch (InterruptedException e) {
e.printStackTrace();
}
// Verify search results
WebElement searchResults = driver.findElement(By.
cssSelector(".widgetId\\=messaging-messages-results-header-builder-legal-disclaimer-and-
ranking-disclosure-builder .s-no-outline"));
if (searchResults.isDisplayed()) {
System.out.println("Search results displayed successfully.");
} else {
System.out.println("Search results not displayed.");
}

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


23
REGISTER NO:411721104020

// Close the browser


driver.quit();
}}
OUTPUT:

VIVA QUESTIONS:
1.What is the Role of Usability Testing?
Usability testing means determining the ease with which an end-user can easily access the
application with or without programming language knowledge. It is also known as User
Experience testing which is recommended during the initial design phase of SDLC.

2.Define Test Plan.


A document that outlines the testing approach, scope, and objectives for a software testing
project is known as a test plan. It has features that include test objectives, test schedules, testing
strategies, and resources required to conduct specific testing.

3. State the difference between validation and verification.


The process of evaluating an application to ensure that it meets the requirements and
specifications set by the stakeholders is known as verification. The process of evaluating an
application to ensure that it meets the needs of the end users is known as validation.

4.Define test case.


A set of instructions or steps that are used to test specific functionalities or features of an
application is known as a test case. It also includes details like input data, expected results or
output, and pre/post conditions.

5. State the difference between white-box testing and black-box testing.


A testing technique where the tester has no specific knowledge of the internal working of the
software application is known as black-box testing. A testing technique where the tester has all
the knowledge of the internal working of the software application is known as white-box
testing.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


24
REGISTER NO:411721104020

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to Automate the testing of e-commerce applications using
selenium has been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


25
REGISTER NO:411721104020

ExNo:8
Integrate TestNG with the above Test
Date: Automation

AIM:
To integrate TestNG with the test automation.

ALGORITHM:
1. Import necessary Selenium and TestNG packages.
2. Create a class named WebTestWithTestNG.
3. Declare a WebDriver instance variable.
4. Define a @BeforeClass method named setUp() with the @BeforeClass annotation.
 Set the system property for the Chrome WebDriver executable.
 Optionally, create a ChromeOptions instance for setting additional options.
 Initialize the WebDriver instance with ChromeDriver and the defined options.
 Maximize the browser window.
5. Define a @Test method named testLogin() with the @Test annotation.
 Navigate to the Facebook login page.
 Inside a try-catch block:
 Find the username and password input fields by their respective IDs.
 Enter the username and password.
 Find and click the login button.
 Wait for the page to load or for a specific element to appear.
 Get the current URL and assert that it contains "facebook.com" to
confirm successful login.
 If any exceptions occur during this process, fail the test with an
appropriate message.
6. Define a @AfterClass method named tearDown() with the @AfterClass annotation.
7. Close the browser using driver.quit() to clean up resources after all tests have run.
8. Execute the TestNG test suite, which will run the setUp() method before all tests, the
testLogin() method as the test case, and the tearDown() method after all tests.

PROGRAM:
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.chrome.ChromeOptions;

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


26
REGISTER NO:411721104020

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class WebTestWithTestNG {


WebDriver driver;

@BeforeClass
public void setUp() {
// Set path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");

// Optional: Set Chrome options


ChromeOptions options = new ChromeOptions();
// Add options if needed, such as headless mode: options.setHeadless(true);

// Initialize WebDriver
driver = new ChromeDriver(options);

// Maximize the browser window


driver.manage().window().maximize();
}

@Test
public void testLogin() {
// Navigate to the application under test
driver.get("https://www.facebook.com");

try {

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


27
REGISTER NO:411721104020

// Find username and password fields


WebElement usernameField = driver.findElement(By.id("email"));
WebElement passwordField = driver.findElement(By.id("pass"));

// Enter username and password


usernameField.sendKeys("[email protected]");
passwordField.sendKeys("prince2024");

// Find and click login button


WebElement loginButton = driver.findElement(By.name("login"));
loginButton.click();

// Wait for page to load or any specific element to appear


Thread.sleep(2000);

// Assertion to check if login was successful


String currentUrl = driver.getCurrentUrl();
Assert.assertTrue(currentUrl.contains("facebook.com"), "Login unsuccessful");
} catch (Exception e) {
// Log any exceptions or errors
Assert.fail("Error in Test case: " + e.getMessage());
}
}

@AfterClass
public void tearDown() {
// Close the browser
driver.quit();
}
}

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


28
REGISTER NO:411721104020

OUTPUT:

Scenario 1: Successful Login

Scenario 2: Unsuccessful Login

Scenario 3: Exception during Execution

VIVA QUESTIONS:
1.Define regression testing.
The process of re-testing an application after changes have been made to ensure that existing
functionality has not been affected is known as regression testing.

2.State the difference between a defect and a bug.


A flaw in the software that prevents it from functioning as intended is known as a defect.
Meanwhile, a defect that causes the software to produce incorrect or unexpected results is
known as a bug.

3.Define Test Report.


A document that includes a summary of activities, objectives, and results is known as a test
report. It helps track the status of the activities and if the product or service is ready for launch.
It is also required to reflect on the testing results

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


29
REGISTER NO:411721104020

4.What does a test report include?


 Test Objective
 Defect
 Product Information
 Test Summary
5.Explain Functional Testing.
It is a form of black-box testing and mainly focuses on the software’s functional requirements.
It looks after the required behavior in the system in terms of input and output. Its main purpose
is to validate the functional requirements of the software. Hence, it does not pay any heed to
performance, reliability, and usability.

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to integrate TestNG with the test automation has been executed
successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


30
REGISTER NO:411721104020

MINI PROJECT
ExNo:9a
DATA-DRIVEN FRAMEWORK USING
SELENIUM AND TestNG
Date:

AIM:
To Build a data-driven framework using selenium and TestNG.

ALGORITHM:
1. Import necessary Selenium and TestNG packages.
2. Create a class named DataDrivenTest.
3. Declare a WebDriver instance variable.
4. Define a @BeforeClass method named setUp() with the @BeforeClass annotation.
 Set the system property for the Chrome WebDriver executable.
 Initialize the WebDriver instance with ChromeDriver.
 Maximize the browser window.
5. Define a @DataProvider method named testData() with the @DataProvider
annotation.
 Read test data from a CSV file named "testdata.csv".
 Initialize a 2D array testData to hold the test data.
 Open the CSV file using a BufferedReader.
 Iterate over each line of the CSV file:
 Split the line by comma to separate username and password.
 Populate the testData array with username and password pairs.
 Close the CSV file reader.
 Return the testData array.
6. Define a @Test method named loginTest() with the @Test annotation and accepting
two parameters (email and password) from the data provider.
 Navigate to the Facebook login page.
 Find the username and password input fields by their respective IDs and enter
the credentials.
 Click on the login button.
 Print a message indicating the email and password being used for login.
7. Define a @AfterClass method named tearDown() with the @AfterClass annotation.
8. Close the browser using driver.quit() to clean up resources after all tests have run.
9. Execute the TestNG test suite, which will run the setUp() method before all tests, use
the data provider to provide test data to the loginTest() method, and then run the
tearDown() method after all tests have finished.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


31
REGISTER NO:411721104020

PROGRAM:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class DataDrivenTest {
WebDriver driver;
@BeforeClass
public void setUp() {
// Set the path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
// Create a new instance of the ChromeDriver
driver = new ChromeDriver();
// Maximize the browser window
driver.manage().window().maximize();
}

@DataProvider(name = "testData")
public Object[][] testData() throws IOException {
// Read test data from CSV file
String csvFile = "testdata.csv";
String line;

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


32
REGISTER NO:411721104020

String[] data;
Object[][] testData = new Object[2][2]; // Assuming 2 rows of data in the CSV file
BufferedReader br = new BufferedReader(new FileReader(csvFile));
int i = 0;
while ((line = br.readLine()) != null) {
data = line.split(",");
testData[i][0] = data[0]; // username
testData[i][1] = data[1]; // password
i++;
}
br.close();
return testData;
}

@Test(dataProvider = "testData")
public void loginTest(String email, String password) {
// Navigate to the login page
driver.get("http://www.facebook.com/login");

// Find username and password input fields by ID and enter credentials


driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(password);

// Click on the login button


driver.findElement(By.id("loginButton")).click();

System.out.println("Logging in with email: " + email + " and password: " + password);
}
@AfterClass
public void tearDown() {

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


33
REGISTER NO:411721104020

// Close the browser


driver.quit();
}
}
OUTPUT:

TestNG Results tab:

VIVA QUESTIONS:
1.Explain Selenium and list the benefits it provides.
Selenium is a web browser automation tool through which the test that you need to run on the
web is automated. The following are the benefits that it offers:

 It is open-source and does not require a license.


 It has the ability to support all the languages, such as Java, C, Python, and Ruby.
 It also supports all the web browsers, such as Google Chrome and Firefox.

2.Key Features of TestNG


Annotation Support: TestNG provides a rich set of annotations such as @Test, @BeforeSuite,
@AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass, @BeforeMethod, and

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


34
REGISTER NO:411721104020

@AfterMethod. These annotations allow developers to define test methods, set up and tear
down methods, configure test dependencies, and more.
Test Configuration: TestNG allows parameterization of test methods, grouping of test
methods, parallel execution of tests, setting dependencies between test methods, and defining
test priorities. This flexibility enables developers to create comprehensive test suites tailored
to their specific testing needs.
3.Explain Beta Testing.
A type of software testing conducted by end-users or a group of individuals outside of the
development team before the software is released to the public is known as beta testing. It
involves releasing a pre-release version of the software, known as a beta version to selected
users who represent the target audience.

4.State the difference between Test Matrix and Traceability Matrix.


A document that is used to track the testing progress and results of a particular testing activity
is known as a test matrix. It usually lists all the test cases and their corresponding results.

A document that maps requirements to the test cases that verify them is known as a traceability
matrix. It provides a comprehensive view of the testing process.

5.What is TestNG
TestNG is a testing framework for the Java programming language inspired by JUnit and NUnit.
It is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.
TestNG stands for "Test Next Generation." It provides additional features and flexibility
compared to JUnit, making it popular among Java developers for writing and running tests.

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to Build a data-driven framework using selenium and TestNG has
been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


35
REGISTER NO:411721104020

ExNo:9b
BUILD A PAGE OBJECT MODEL USING
SELENIUM AND TestNG
Date:

AIM:
To Build page object model using Selenium and TestNG .

ALGORITHM:
1. Define the LoginPage Class:
 Define a class named LoginPage.
 Include private fields to store WebDriver instance and locators for username,
password, and login button elements.
 Define a constructor to initialize the WebDriver instance.
 Include methods to interact with the login page elements:
 enterUsername(String username): Enter the username into the username field.
 enterPassword(String password): Enter the password into the password field.
 clickLoginButton(): Click on the login button.
2. Define the TestNG Test Class (LoginTest.java):
 Import necessary Selenium and TestNG libraries.
 Define a class named LoginTest.
 Include private fields for WebDriver instance and LoginPage instance.
 Define a method annotated with @BeforeClass to set up the WebDriver
instance:
 Set the path to chromedriver.exe.
 Create a new instance of the ChromeDriver.
 Maximize the browser window.
 Initialize the LoginPage object.
 Define a test method annotated with @Test to perform the login test:
 Navigate to the Instagram login page.
3. Use the methods of the LoginPage object to enter username and password.
4. Click on the login button.
5. Add assertions or validation steps as needed.
6. Define a method annotated with @AfterClass to perform cleanup:
7. Close the browser by quitting the WebDriver instance.
8. Execution:
9. TestNG framework will execute the setUp() method before running the test method
and tearDown() method after the test method.
10. The test method loginTest() will execute the login test steps defined using the methods
of the LoginPage class.
11. Assertions or validation steps can be added within the test method to verify the login
functionality.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


36
REGISTER NO:411721104020

PROGRAM:
Page Object Class (LoginPage.java):
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class LoginPage {
private WebDriver driver;
// Locators
private By usernameField = By.id("username");
private By passwordField = By.id("password");
private By loginButton = By.id("loginBtn");
// Constructor
public LoginPage(WebDriver driver) {
this.driver = driver;
}
// Methods to interact with elements
public void enterUsername(String username) {
driver.findElement(usernameField).sendKeys(username);
}
public void enterPassword(String password) {
driver.findElement(passwordField).sendKeys(password);
}
public void clickLoginButton() {
driver.findElement(loginButton).click();
}
}

TestNG Test Class (LoginTest.java):


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


37
REGISTER NO:411721104020

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class LoginTest {


private WebDriver driver;
private LoginPage loginPage;

@BeforeClass
public void setUp() {
// Set the path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
// Create a new instance of the ChromeDriver
driver = new ChromeDriver();
// Maximize the browser window
driver.manage().window().maximize();
// Initialize LoginPage object
loginPage = new LoginPage(driver);
}

@Test
public void loginTest() {
// Navigate to the login page
driver.get("http://www.instagram.com/");
// Enter username and password
loginPage.enterUsername("alextelax");
loginPage.enterPassword("prince2024");
// Click on login button
loginPage.clickLoginButton();
// Add assertions or validation steps

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


38
REGISTER NO:411721104020

@AfterClass
public void tearDown() {
// Close the browser
driver.quit();
}
}

OUTPUT:

VIVA QUESTIONS:
1.What is Page Object Model?
The Page Object Model (POM) is a design pattern used in test automation to create an
abstraction of the user interface of a web application. It aims to enhance test maintenance and
reduce code duplication by encapsulating the details of the UI components within separate
classes called Page Objects.
2.Explain static software testing.
A technique used to evaluate the software without actually executing the code that involves
reviewing the software code, requirements, and design documents to identify errors, is known
as status software testing. It helps detect errors early in the process of development, which
reduces the cost of fixing them later.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


39
REGISTER NO:411721104020

3.Explain dynamic software testing.


The process of testing software applications, while they are running, is known as dynamic
software testing. This process involves executing the software with different inputs and
verifying the output against expected behavior. It is an important part of the software
development process.

4.Explain the Test Script.


A test case automated in any programming language is known as a test script. It is helpful for
collecting instructions for the evaluation of an application’s functionality.

5.Define Test Bed.


It is an environment set up for testing an application before it is made available to the customers.
It is done for a smooth user experience, reliability, and better performance.

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to build page object model using Selenium and TestNG has been
executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


40
REGISTER NO:411721104020

ExNo:9c
BUILD BDD FRAMEWORK WITH SELENIUM
,TestNG AND CUCUMBER.
Date:

AIM:
To Build BDD framework with Selenium ,TestNg and Cucumber.

ALGORITHM:
1.Given I am on the login page:
 This step initializes the WebDriver and navigates to the login page.
2.When I enter username "user" and password "password":
 This step enters the provided username and password into the respective input fields
on the login page.
3.When I click on the login button:
 This step clicks on the login button to attempt the login process.
4.Then I should be logged in successfully:
 This step verifies whether the login was successful.
 It can be extended with assertions to check for the presence of elements that indicate a
successful login, such as a dashboard or welcome message.
 Finally, it closes the WebDriver instance after completing the test.

PROGRAM:
Step Definitions (LoginSteps.java):
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginSteps {
private WebDriver driver;

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


41
REGISTER NO:411721104020

@Given("I am on the login page")


public void i_am_on_the_login_page() {
// Initialize WebDriver
System.setProperty("webdriver.chrome.driver", "
C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe ");
driver = new ChromeDriver();
// Navigate to the login page
driver.get("http://www.instagram.com/login");
}

@When("I enter username {string} and password {string}")


public void i_enter_username_and_password(String username, String password) {
// Enter username and password
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
}

@When("I click on the login button")


public void i_click_on_the_login_button() {
// Click on the login button
driver.findElement(By.id("loginBtn")).click();
}

@Then("I should be logged in successfully")


public void i_should_be_logged_in_successfully() {
// Assert login success
// You can add assertions here to verify if the login was successful
// For example, you can check for the presence of a welcome message or a dashboard
element
// Example: assertTrue(driver.findElement(By.id("welcomeMessage")).isDisplayed());

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


42
REGISTER NO:411721104020

// Close the WebDriver instance


driver.quit();
}
}
Test Runner (TestRunner.java):

import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions"
)
public class TestRunner extends AbstractTestNGCucumberTests {
}

Feature File (login.feature):

Feature: Login functionality


Scenario: Successful login with valid credentials
Given I am on the login page
When I enter username "user" and password "password"
And I click on the login button
Then I should be logged in successfully

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


43
REGISTER NO:411721104020

OUTPUT :

VIVA QUESTIONS:

1.What is Cucumber?
Cucumber is a testing framework that supports behavior-driven development (BDD), allowing
for the creation of executable specifications written in plain text. It facilitates collaboration
among developers, testers, and non-technical stakeholders by enabling them to define and
automate acceptance criteria in a human-readable format.
2. How Cucumber typically works?
Parsing Feature Files: Cucumber parses feature files written in Gherkin, a plain-text language
with structured keywords.
Executing Step Definitions: Cucumber matches each step in the feature files to its
corresponding step definition, written in a programming language. It then executes these step
definitions to automate the test scenarios described in the feature files.
3.what is a feature file?
A feature file in Cucumber is a text file written in the Gherkin syntax, which serves as the
starting point for defining and organizing test scenarios.
4.What is Automation Testing?
Testing any software according to the client’s needs using an automation tool is called
Automation Testing.
5.What is Functional testing and Non-Functional Testing?
In functional testing, the software system is validated against the functional requirements.
In non-functional testing, the non-functional parameters like reliability, load test,
performance, and accountability of the software are tested.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


44
REGISTER NO:411721104020

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to Build BDD framework with selenium ,TestNg and Cucumber has
been executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


45
REGISTER NO:411721104020

EX.NO.10
DATE: NAVIGATE THROUGH WEB PAGES

AIM:
To demonstrate basic navigation between web pages using the WebDriver API
ALGORITHM
1. Create Class NavigatePages.
2. Instantiate a new ChromeDriver object, creating a new Chrome browser instance.
3. Use the get() method to navigate to the Flipkart homepage.
4. Use navigate().to() method to navigate to a specific grocery store page on Flipkart.
5. Use navigate().back() method to navigate back to the previous page (Flipkart
homepage).
6. Use navigate().forward() method to navigate forward to the grocery store page again.
7. Close the browser using quit() method of WebDriver.

PROGRAM
package seleniumtest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class NavigatePages {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\User\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.flipkart.com");
// Print the title of the current page
System.out.println("Title of the current page: " + driver.getTitle());
// Navigate to another page
driver.navigate().to("https://www.flipkart.com/grocery-supermart-
store?marketplace=GROCERY&fm=neo%2Fmerchandising&iid=M_b6a9537b-d688-442e-bc05-
a8faf11d8a67_1_372UD5BXDFYS_MC.CBUR1Q46W5F1&otracker=hp_rich_navigation_1_1.navi
gationCard.RICH_NAVIGATION_Grocery_CBUR1Q46W5F1&otracker1=hp_rich_navigation_PIN
NED_neo%2Fmerchandising_NA_NAV_EXPANDABLE_navigationCard_cc_1_L0_view-
all&cid=CBUR1Q46W5F1");

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


46
REGISTER NO:411721104020

// Print the title of the new page


System.out.println("Title of the new page: " + driver.getTitle());
// Navigate back to the previous page
driver.navigate().back();
// Print the title after navigating back
System.out.println("Title after navigating back: " + driver.getTitle());
// Navigate forward
driver.navigate().forward();
// Print the title after navigating forward
System.out.println("Title after navigating forward: " + driver.getTitle());
driver.quit();
}
}
OUTPUT
Title of the current page: Online Shopping Site for Mobiles, Electronics, Furniture, Grocery,
Lifestyle, Books & More. Best Offers!
Title of the new page: Flipkart Grocery Store - Buy Groceries Online & Get Rs.1 Deals at
Flipkart.com
Title after navigating back: Online Shopping Site for Mobiles, Electronics, Furniture,
Grocery, Lifestyle, Books & More. Best Offers!
Title after navigating forward: Flipkart Grocery Store - Buy Groceries Online & Get Rs.1
Deals at Flipkart.com

VIVA QUESTIONS

1.What is Selenium?
Selenium is a popular open-source tool used for automating web browsers. It allows testers to
interact with web elements and automate various tasks on web applications.
2.What is WebDriver in Selenium?
WebDriver is a part of the Selenium framework that provides a programming interface for
automating web browsers. It enables testers to write scripts to automate interactions with web
elements.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


47
REGISTER NO:411721104020

3.What is the significance of driver.get() method?


The driver.get() method is used to navigate to a specific URL in the browser controlled by
WebDriver. It directs the browser to the specified web page.
4.What is the difference between driver.get() and driver.navigate().to()?
Both methods navigate to a URL, but driver.get() is more straightforward and waits for the page
to load completely, while driver.navigate().to() is used for navigation within the same session
and doesn't guarantee waiting for the page to load fully.
5.Explain the purpose of driver.navigate().back() and driver.navigate().forward() in your
code.
driver.navigate().back() is used to navigate the browser back to the previous page in the
browsing history, while driver.navigate().forward() is used to navigate the browser forward in
the browsing history.

AIM& PROGRAM OUTPUT& VIVA TOTAL(A1) DISSEMINATION TIMELY GRAND


ALGORITHM EXECUTION RESULT VOCE (30M) OF LEARNED SUBMISSION TOTAL(A1+B1)
(5M) AND (10M) (5M) PO’s / PSO’s OF (40M)
DEBUGGING RECORD(B1)
(10M) (10M)

RESULT:
Thus the program to demonstrate basic navigation between web pages using the
WebDriver API is executed successfully.

PSVPEC/CSE/CCS366/SOFTWARE TESTING AND AUTOMATION LABORATORY


48

You might also like