Sta Manual
Sta Manual
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
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
RESULT:
Thus the program to develop the test plan for testing an e-commerce web/ mobile application
has been executed successfully.
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();
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:
RESULT: Thus the program for designing the test cases for testing the e-commerce application
has been executed successfully.
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\");
// 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();
}
}
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.
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
RESULT:
Thus the program to test the defects in e-commerce website has been executed
successfully.
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
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 {
System.getProperty("webdriver.chrome.driver","C:\\Users\\lenovo\\Downloads\\chromedriver_wi
n32\\chromedriver.exe");
// Initialize WebDriver
WebDriver driver = new ChromeDriver();
// 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
usernameInput.sendKeys("[email protected]");
passwordInput.sendKeys("@aaranish2691");
loginButton.click();
if (currentUrl.equals("https://app.sortly.com/items/")) {
System.out.println("Login Test Passed");
} else {
System.out.println("Login Test Failed");
}
WebElement addItemButton =
driver.findElement(By.xpath("//button[@type='button']"));
addItemButton.click();
itemNameInput.sendKeys("paper");
quantityInput.sendKeys("1");
addButton.click();
OUTPUT:
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.
RESULT:
Thus the program for developing the test plan and design the test cases for an
inventory control system has been executed successfully.
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.
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 ");
// Initialize WebDriver
WebDriver driver = new ChromeDriver(options);
// Maximize the browser window
driver.manage().window().maximize();
// Test case 1:
try {
// Find username and password fields
WebElement usernameField = driver.findElement(By.id("email"));
WebElement passwordField = driver.findElement(By.id("password"));
usernameField.sendKeys("[email protected]");
passwordField.sendKeys("prince2024");
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.
RESULT:
Thus the program for executing the test cases against a client server or desktop
application and identify the defects has been executed successfully
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/");
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.
RESULT:
Thus the program for testing the performance of the e-commerce application has
been executed successfully.
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
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.");
}
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.
RESULT:
Thus the program to Automate the testing of e-commerce applications using
selenium has been executed successfully.
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;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@BeforeClass
public void setUp() {
// Set path to chromedriver.exe
System.getProperty("webdriver.chrome.driver",
"C:\\Users\\lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");
// Initialize WebDriver
driver = new ChromeDriver(options);
@Test
public void testLogin() {
// Navigate to the application under test
driver.get("https://www.facebook.com");
try {
@AfterClass
public void tearDown() {
// Close the browser
driver.quit();
}
}
OUTPUT:
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.
RESULT:
Thus the program to integrate TestNG with the test automation has been executed
successfully.
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.
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;
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");
System.out.println("Logging in with email: " + email + " and password: " + password);
}
@AfterClass
public void tearDown() {
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:
@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.
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.
RESULT:
Thus the program to Build a data-driven framework using selenium and TestNG has
been executed successfully.
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.
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();
}
}
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@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
@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.
RESULT:
Thus the program to build page object model using Selenium and TestNG has been
executed successfully.
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;
import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions"
)
public class TestRunner extends AbstractTestNGCucumberTests {
}
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.
RESULT:
Thus the program to Build BDD framework with selenium ,TestNg and Cucumber has
been executed successfully.
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");
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.
RESULT:
Thus the program to demonstrate basic navigation between web pages using the
WebDriver API is executed successfully.