STA - Final Lab Record
STA - Final Lab Record
An Autonomous Institution
V.S.B. ENGINEERING COLLEGE, KARUR
(AN AUTONOMOUS INSTITUTION)
DEPARTMENT OF INFORMATION TECHNOLOGY
ACADEMIC YEAR: 2024-2025 (ODD Semester)
VISION, MISSION, PEOs, POs and PSOs
COURSE OUTCOMES
CO-PO-PSO MATRIX
CO-PO MATRIX
AIM
To develop the test plan for testing an e-commerce web/mobile application
(www.amazon.com)
PROCEDURE
1. Test Objectives:
Verify that users can browse and search for products.
Confirm that products are displayed accurately with correct details.
Test the user registration and login process.
Validate the shopping cart and checkout process.
Test payment processing and order placement.
Check for responsiveness and usability on mobile devices.
Verify security aspects such as data encryption and session management.
2. Test Environment:
Web Browsers: Chrome, Firefox, Safari, Edge.
Mobile Devices: iOS and Android devices.
Testing Framework: Selenium WebDriver with Java.
Load Testing: Apache JMeter for performance testing.
Security Testing: OWASP ZAP or similar tool.
3. Test Cases:
Test cases should cover registration, login, product browsing, cart management,
paymentprocessing, etc.
Include positive and negative scenarios, edge cases, and stress tests.
4. Test Execution:
Automate test cases using Selenium WebDriver.
Execute tests across different browsers and mobile devices.
Use load testing tools to simulate high user traffic and monitor performance.
Perform security testing to identify vulnerabilities.
5. Test Data:
Use real and dummy data for testing.
Test accounts, products, payment methods, addresses, etc.
6. Risks and Assumptions:
Risk: Changes in the website's structure might break automation scripts.
1
Risk: Mobile app updates might affect test scripts and compatibility.
Assumption: Test data in the environment matches real-world scenarios.
7. Deliverables:
Test reports summarizing test results, defects found, and performance analysis.
Documentation of test cases, procedures, and configurations.
Recommendations for improvements and fixes.
PROGRAM
Test Plan: User
RegistrationTest Cases:
TC-UR-01: Verify successful registration with valid information.
TC-UR-02: Verify registration failure with invalid email format.
TC-UR-03: Verify registration failure with existing email.
TC-UR-04: Verify appropriate error messages for failed registration attempts.
Selenium WebDriver Test Case Code: User Registration
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonUserRegistrationTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Navigate to Amazon registration page
driver.get("https://www.amazon.com/");
// Step 2: Click on "Hello, Sign in" button
WebElement signInButton = driver.findElement(By.id("nav-signin-tooltip"));
signInButton.click();
// Step 3: Click on "Create your Amazon account"
WebElement createAccountButton =driver.findElement(By.id("createAccountSubmit"));
createAccountButton.click();
// Step 4: Fill in registration details
WebElement nameInput = driver.findElement(By.id("ap_customer_name"));
nameInput.sendKeys("John Doe");
2
WebElement emailInput = driver.findElement(By.id("ap_email"));
emailInput.sendKeys("[email protected]");
WebElement passwordInput = driver.findElement(By.id("ap_password"));
passwordInput.sendKeys("password123");
WebElement confirmPasswordInput = driver.findElement(By.id("ap_password_check"));
confirmPasswordInput.sendKeys("password123");
// Step 5: Click on "Create your Amazon account"
WebElement finalCreateAccountButton =driver.findElement(By.id("continue"));
finalCreateAccountButton.click();
// Step 6: Verification (based on success or failure)
WebElement successMessage = driver.findElement(By.className("a-alert- heading"));
if (successMessage.isDisplayed()) {
System.out.println("User registration successful");
}
else
{
System.out.println("User registration failed");
}
// Close the browser driver.quit();
}
}
OUTPUT
User registration successful
3
Selenium WebDriver Test Case Code: User Login
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonUserLoginTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Navigate to Amazon login page
driver.get("https://www.amazon.com/ ");
// Step 2: Click on "Sign in" or "Hello, Sign in" button WebElement signInButton =
driver.findElement(By.id("nav-signin- tooltip"));
signInButton.click();
// Step 3: Fill in login credentials
WebElement emailInput = driver.findElement(By.id("ap_email"));
emailInput.sendKeys("[email protected]");
WebElement passwordInput = driver.findElement(By.id("ap_password"));
passwordInput.sendKeys("password123");
// Step 4: Click on "Sign-In"
WebElement signInSubmitButton =driver.findElement(By.id("signInSubmit"));
signInSubmitButton.click();
// Step 5: Verification (based on success or failure)
WebElement accountLink = driver.findElement(By.id("nav-link- accountList"));
if (accountLink.isDisplayed()) {
System.out.println("User login successful");
}
else
{
System.out.println("User login failed");
}
// Close the browser driver.quit();
}}
4
OUTPUT
User Login Successful
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonProductBrowsingTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Navigate to Amazon product listing page driver.get("https://www.amazon.com/products ");
// Step 2: Verify access to the product listing page
WebElement pageTitle = driver.findElement(By.tagName("h1"));
if (pageTitle.getText().contains("Products"))
{
System.out.println("Product listing page accessed successfully");
}
else
{
System.out.println("Product listing page access failed");
}
// Step 3: Verify accurate display of products' names and prices
WebElement firstProductName = driver.findElement(By.cssSelector(".product-item:first- child.product-
name"));
5
WebElement firstProductPrice = driver.findElement(By.cssSelector(".product-item:first-child.product-
price"));
// Step 4: Click on the first product to view details
WebElement firstProductLink = driver.findElement(By.cssSelector(".product-item:first-child.product-
link")); firstProductLink.click();
// Expected Output for this step:
// The browser should navigate to the product details page.
// Close the browser driver.quit();
}
}
OUTPUT
TC-PD-02: Verify product images and thumbnails are visible and clickable.
TC-PD-04: Verify user can navigate back to product listing from details page.
6
// Step 1: Navigate to Amazon product listing page
driver.get("https://www.amazon.com/products");
// Step 2: Select a product from the list
WebElement product = driver.findElement(By.cssSelector(".product-item:first- child"));
product.click();
// Step 3: Verify product details
WebElement productName = driver.findElement(By.cssSelector(".product-name"));
WebElement productPrice = driver.findElement(By.cssSelector(".product-price"));
WebElement productDescription = driver.findElement(By.cssSelector(".product- description"));
// Step 4: Verify product images and thumbnails
WebElement productImage = driver.findElement(By.cssSelector(".product- image"));
productImage.click();
// Clicking on the image to view full size
// Step 5: Verify navigation back to product listing
driver.navigate().back();
// Close the browser
driver.quit();
}
}
OUTPUT
Navigated to Amazon product listing
pageProduct selected from the list
Product details verified
Product images and thumbnails
verifiedNavigated back to product
listing
7
Selenium WebDriver Test Case Code: Shopping Cart
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonShoppingCartTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Navigate to Amazon product listing page
driver.get("https://www.amazon.com/products ");
// Step 2: Click on the "Add to Cart" button of a product
WebElement addToCartButton = driver.findElement(By.cssSelector(".product-item:first- child .add-to-
cart-button"));
addToCartButton.click();
// Step 3: Navigate to the shopping cart
WebElement cartLink = driver.findElement(By.id("nav- cart"));cartLink.click();
// Step 4: Verify accurate display of product details and quantities in the cart
WebElement productNameInCart = driver.findElement(By.cssSelector(".cart-item:first-child.product-
name"));
WebElement productQuantityInCart = driver.findElement(By.cssSelector(".cart-item:first- child.product-
quantity"));
// Step 5: Update product quantity
WebElement quantityInput = driver.findElement(By.cssSelector(".cart-item:first-child.quantity-input"));
quantityInput.clear();
quantityInput.sendKeys("2 ");
quantityInput.submit();
// Step 6: Remove product from the cart
WebElement removeButton = driver.findElement(By.cssSelector(".cart-item:first-child.remove-button"));
removeButton.click();
// Verification based on success or failure is not included due to the complexity of the shopping cartpage.
// Close the browser
driver.quit();
}}
8
Output
Product added to cart successfully
Product details and quantities in cart
verifiedProduct quantity updated
successfully Product removed from cart
successfully
OUTPUT
// Depending on the specific scenario:
Payment submitted successfully and user receives
confirmationOR
Payment submission failed due to invalid payment information
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonOrderHistoryTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Log in to Amazon account (assuming already logged in)
// Step 2: Navigate to order history page
driver.get("https://www.amazon.com/order- history");
// Step 3: Verify access to the order history page
10
WebElement pageTitle = driver.findElement(By.tagName("h1"));
if (pageTitle.getText().contains("Order History"))
{
System.out.println("Order history page accessed successfully");
}
else
{
System.out.println("Order history page access failed");
}
// Step 4: Verify accurate display of order details
WebElement firstOrderNumber = driver.findElement(By.cssSelector(".order-item:first- child .order-number"));
WebElement firstOrderDate = driver.findElement(By.cssSelector(".order-item:first- child .order-date"));
WebElement firstOrderTotal = driver.findElement(By.cssSelector(".order-item:first- child .order-total"));
// Step 5: Click on the first order to view specific details
WebElement firstOrderLink = driver.findElement(By.cssSelector(".order-item:first- child .order-link"));
firstOrderLink.click();
// Expected Output for this step:
// The browser should navigate to the specific order details page.
// Close the browser driver.quit();
}
}
OUTPUT
Order history page accessed successfully
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
11
EX.NO: 2 DESIGN THE TEST CASE FOR TESTING THE
DATE: E-COMMERCE APPLICATION
AIM
To develop the test case for testing an e-commerce application.
PROCEDURE
1. Test Objectives:
Verify that users can browse and search for products.
Confirm that products are displayed accurately with correct details.
Test the user registration and login process.
Validate the shopping cart and checkout process.
Test payment processing and order placement.
Check for responsiveness and usability on mobile devices.
Verify security aspects such as data encryption and session management.
2. Test Environment:
Web Browsers: Chrome, Firefox, Safari, Edge.
Mobile Devices: iOS and Android devices.
Testing Framework: Selenium WebDriver with Java.
Load Testing: Apache JMeter for performance testing.
Security Testing: OWASP ZAP or similar tool.
3. Test Cases:
Test cases should cover registration, login, product browsing, cart management,
paymentprocessing, etc.
Include positive and negative scenarios, edge cases, and stress tests.
4. Test Execution:
Automate test cases using Selenium WebDriver.
Execute tests across different browsers and mobile devices.
Use load testing tools to simulate high user traffic and monitor performance.
Perform security testing to identify vulnerabilities.
5. Test Data:
Use real and dummy data for testing.
Test accounts, products, payment methods, addresses, etc.
6. Risks and Assumptions:
Risk: Changes in the website's structure might break automation scripts.
Risk: Mobile app updates might affect test scripts and compatibility.
12
Assumption: Test data in the environment matches real-world scenarios.
7. Deliverables:
Test reports summarizing test results, defects found, and performance analysis.
Documentation of test cases, procedures, and configurations.
Recommendations for improvements and fixes.
PROGRAM
Test Plan: User
RegistrationTest Cases:
TC-UR-01: Verify successful registration with valid information.
TC-UR-02: Verify registration failure with invalid email format.
TC-UR-03: Verify registration failure with existing email.
TC-UR-04: Verify appropriate error messages for failed registration attempts.
13
WebElement emailInput = driver.findElement(By.id("ap_email"));
emailInput.sendKeys("[email protected]");
WebElement passwordInput = driver.findElement(By.id("ap_password"));
passwordInput.sendKeys("password123");
WebElement confirmPasswordInput = driver.findElement(By.id("ap_password_check"));
confirmPasswordInput.sendKeys("password123");
// Step 5: Click on "Create your Amazon account"
WebElement finalCreateAccountButton = driver.findElement(By.id("continue"));
finalCreateAccountButton.click();
// Step 6: Verification (based on success or failure)
WebElement successMessage = driver.findElement(By.className("a-alert- heading"));
if (successMessage.isDisplayed())
{
System.out.println("User registration successful");
}
else
{
System.out.println("User registration failed");
}
// Close the browser
driver.quit();
}
}
OUTPUT
User registration successful
14
Selenium WebDriver Test Case Code: User Registration
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonUserLoginTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Navigate to Amazon login page
driver.get("https://www.amazon.com/ ");
// Step 2: Click on "Sign in" or "Hello, Sign in" button
WebElement signInButton = driver.findElement(By.id("nav-signin- tooltip"));
signInButton.click();
// Step 3: Fill in login credentials
WebElement emailInput = driver.findElement(By.id("ap_email"));
emailInput.sendKeys("[email protected]");
WebElement passwordInput = driver.findElement(By.id("ap_password"));
passwordInput.sendKeys("password123");
// Step 4: Click on "Sign-In"
WebElement signInSubmitButton =driver.findElement(By.id("signInSubmit"));
signInSubmitButton.click();
// Step 5: Verification (based on success or failure)
WebElement accountLink = driver.findElement(By.id("nav-link- accountList"));
if (accountLink.isDisplayed())
{
System.out.println("User login successful");
}
else
{
System.out.println("User login failed");
}
// Close the browser driver.quit();
}}
15
OUTPUT
User Login Successful
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonProductDetailsTest
{
public static void main(String[] args)
{
// Set up the WebDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Step 1: Navigate to Amazon product listing page
driver.get("https://www.amazon.com/products ");
// Step 2: Select a product from the list
WebElement product = driver.findElement(By.cssSelector(".product-item:first- child"));
product.click();
// Step 3: Verify product details
WebElement productName = driver.findElement(By.cssSelector(".product-name"));
WebElement productPrice = driver.findElement(By.cssSelector(".product-price"));
WebElement productDescription = driver.findElement(By.cssSelector(".product- description"));
// Step 4: Verify product images and thumbnails
WebElement productImage = driver.findElement(By.cssSelector(".product- image"));
productImage.click();
// Clicking on the image to view full size
// Step 5: Verify navigation back to product listing
driver.navigate().back();
16
// Close the browser
driver.quit();
}
}
OUTPUT
Navigated to Amazon product listing
pageProduct selected from the list
Product details verified
Product images and thumbnails
verifiedNavigated back to product
listing
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
17
EX.NO: 3 TEST THE E-COMMERCE APPLICATION AND REPORT
DATE: THE DEFECTS IN IT
AIM:
To test the e-commerce application and report the defects in it.
PROCEDURE:
Defect 1: Incorrect Product Search
Defect Aim: Verify that the product search functionality returns correct results.
Correct Test Procedure:
Navigate to the e-commerce website's homepage.
Enter "Laptop" in the search bar.
Click the search button.
Verify that the search results list includes relevant products.
DEFECT OUTPUT
Defect: Search results not displayed.
18
Correct Test Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ProductSearchTest
{
public static void main(String[] args)
{
WebDriver driver = new ChromeDriver();
driver.get("https://www.example-ecommerce.com");
// Perform the correct search
WebElement searchInput = driver.findElement(By.id("search- input"));
searchInput.sendKeys("Laptop");
WebElement searchButton = driver.findElement(By.id("search- button"));
searchButton.click();
// Verify search results
WebElement searchResults = driver.findElement(By.id("search- results"));
if (searchResults.isDisplayed())
{
System.out.println("Search results displayed.");
}
else
{
System.out.println("Defect: Search results not displayed.");
}
driver.quit();
}
}
OUTPUT
Search results displayed.
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
19
EX.NO:4 DEVELOP THE TEST PLAN AND DESIGN THE TEST CASES
DATE: FOR AN INVENTORY CONTROL SYSTEM
AIM:
To develop the test plan and design the test cases for an inventory control system
PROCEDURE
Test Plan Scenarios:
Scenario 1: Add New Item
Launch the Chrome browser.
Navigate to the inventory control system's homepage.
Log in as an administrator.
Click on the "Add New Item" button.
Fill in the item details and submit the form.
Verify that the new item is listed in the inventory.
Expected Result: The new item should be added to the inventory and listed correctly.
Scenario 2: Update Item Details
Launch the Chrome browser.
Navigate to the inventory control system's homepage.
Log in as an administrator.
Search for an existing item by name or ID.
Click on the item to edit its details.
Update the item's details and save the changes.
Verify that the updated details are correctly reflected in the inventory.
Expected Result: The item's details should be updated as per the changes made and displayed
accuratelyin the inventory.
Scenario 3: Delete Item
Launch the Chrome browser.
Navigate to the inventory control system's homepage.
Log in as an administrator.
Search for an existing item by name or ID.
Select the item and click the "Delete" button.
Confirm the deletion.
Verify that the item is removed from the inventory.
Expected Result: The item should be successfully deleted from the inventory and no longer
listed.
20
Scenario 4: Defect - Incorrect Item Quantity Calculation
Launch the Chrome browser.
Navigate to the inventory control system's homepage.
Log in as an administrator.
Search for an existing item by name or ID.
Observe the current quantity of the item.
Perform transactions (additions/subtractions) to change the quantity.
Verify that the calculated quantity matches the actual quantity.
Expected Result: A defect should be identified if the calculated quantity does not match
the actualquantity due to incorrect quantity calculation logic.
Defect Report: Defect Aim: Verify the accuracy of item quantity calculation. Procedure:
Navigate to the inventory control system's homepage.
Log in as an administrator.
Search for an existing item by name or ID.
Observe the current quantity of the item.
Perform transactions (additions/subtractions) to change the quantity.
Verify that the calculated quantity does not match the actual quantity. Output:
Calculatedquantity is incorrect. Severity: Major Priority: High
Test Case Design: Add New Item
Test Case Name: Add New Item
Description: Verify that a new item can be successfully added to the inventory.
Preconditions: Logged in as an administrator.
Test Steps:
Click on the "Add New Item" button.
Fill in the item details: name, ID, category, quantity, etc.
Click the "Submit" button.
Expected Result: The new item should be added to the inventory and listed correctly.
PROGRAM :
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class InventoryControlTest
{
public static void main(String[] args)
{
21
WebDriver driver = new ChromeDriver();
driver.get("https://www.inventory-control-system.com");
// Login as administrator (Assuming login code)
// Test Case: Add New Item
WebElement addNewItemButton = driver.findElement(By.id("add-item- button"));
addNewItemButton.click();
WebElement itemNameField = driver.findElement(By.id("item- name"));
itemNameField.sendKeys("New Product");
// Fill in other fields...
WebElement submitButton = driver.findElement(By.id("submit- button"));
submitButton.click();
// Verify item added to inventory (Assertion code)
driver.quit();
}
}
OUTPUT
No errors encountered. New item "New Product" added to the inventory.
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
22
EX.NO: 5 EXECUTE THE TEST CASES AGAINST A CLIENT SERVER OR
DATE: DESKTOP APPLICATION AND IDENTIFY THE DEFECTS
AIM
To execute the test cases against a client server or desktop application and identify the
defects
PROCEDURE:
Test Environment:
Appium
Android Emulator or iOS Simulator
Mobile Application: YourMobileApp.apk (Android) or YourMobileApp.ipa (iOS)
Test Scenarios:
23
Scenario 4: Defect - Slow Response
Launch the Appium server.
Set desired capabilities to connect to the mobile device/emulator.
Automate the login process with valid credentials.
Introduce a delay in the application's response.
Verify that the user is not logged in within a reasonable time.
Expected Result: A defect should be identified if the login process takes an unreasonably
long time tocomplete.
Defect Report: Defect Aim: Verify the responsiveness of the login process. Procedure:
Launch the Appium server.
Set desired capabilities to connect to the mobile device/emulator.
Automate the login process with valid credentials.
Introduce a delay in the application's response.
Verify that the user is not logged in within a reasonable time. Output: Login process
takes longerthan expected. Severity: Major Priority: High
Test Case Design: Successful Login
Test Case Name: Successful Login
Description: Verify that a user can successfully log in with valid credentials.
Preconditions: Appium server is running; Mobile app installed on emulator/simulator.
Test Steps:
Set desired capabilities for the mobile device/emulator.
Automate the login process with valid credentials.
Expected Result: The user should be logged in, and the welcome message with the
usernameshould be displayed.
25
OUTPUT(EXPECTED)
Login successful.
OUTPUT(DEFECT)
Defect: Login failed.
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
26
EX NO: 6 TEST THE PERFORMANCE OF THE E-COMMERCE
DATE: APPLICATION
AIM:
To test the performance of the e-commerce application
PROCEDURE
Test Environment:
Web browser: Chrome
Selenium WebDriver with Java
E-commerce website URL: https://www.example-ecommerce.com
Page to Test: ProductCatalogPage
Test Scenarios:
Scenario 1: Measure Page Load Time
Launch the Chrome browser.
Navigate to the ProductCatalogPage.
Measure the time it takes for the page to fully load.
Expected Result: The page load time should be measured accurately and within an acceptable
range.
Test Case Design: Measure Page Load Time
Test Case Name: Measure Page Load Time
Test Case ID: TC-PERF-001
Description: Measure the page load time of a specific page on the e-commerce
application.
Preconditions: None
Test Steps:
Launch the Chrome browser.
Navigate to the ProductCatalogPage.
Measure the time it takes for the page to fully load.
Expected Result: The page load time should be measured accurately and within an
acceptablerange.
27
PROGRAM:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class PageLoadTimeTest
{
WebDriver driver = new ChromeDriver();
long startTime, endTime, pageLoadTime;
// Step 1: Launch the browser and navigate to the page
driver.get("https://www.example-ecommerce.com/product- catalog");
// Step 2: Measure page load time
startTime = System.currentTimeMillis();
// Wait for an element on the page to indicate page load completion (e.g., a product list)
driver.findElement(By.className("product-list"));
endTime = System.currentTimeMillis();
pageLoadTime = endTime - startTime;
System.out.println("Page Load Time: " + pageLoadTime + " milliseconds");
driver.quit();
}
}
OUTPUT:
Page Load Time: <Some Value> milliseconds
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
28
EX NO: 7 AUTOMATE THE TESTING OF E-COMMERCE
AIM
To automate the testing of an e-commerce application using selenium.
PROCEDURE
Login Module:
o Verify that a user can log in with valid credentials.
o Verify that an error is displayed when logging in with invalid credentials.
o Verify the "Forgot Password" functionality.
Product Browsing:
o Verify that products are displayed on the homepage.
o Verify that a user can search for products.
o Verify that a user can filter products based on different criteria.
Shopping Cart:
o Verify that a user can add products to the shopping cart.
o Verify that the shopping cart displays the correct items and quantities.
o Verify that a user can update the quantity of items in the cart.
Checkout Process:
o Verify that a user can proceed to checkout.
o Verify that the correct shipping information is displayed.
o Verify that the order total is calculated correctly.
29
Checkout Process:
o Test Case 10: Verify the ability to proceed to checkout.
o Test Case 11: Verify the display of correct shipping information.
o Test Case 12: Verify the correctness of the order total.
30
}
if (userLogin.isDisplayed())
{
System.out.println("Test Case 3 Passed: User LOgin Successful");
}
else
{
System.out.println("Test Case 3 Failed: Login Successful");
}
usernameInput.sendKeys("valid_usernam e");
passwordInput.sendKeys("valid_passwor d");
loginButton.click();
// Add more test cases and actions here...
// Close the browser
driver.quit();
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ProductBrowsingTest
{
public static void main(String[] args)
{
// Set the path to your ChromeDriver executable
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
// Initialize WebDriver
WebDriver driver = new ChromeDriver();
// Test Case 4: Verify that products are displayed on the homepage.
driver.get("url_of_your_ecommerce_application");
WebElement homePageProducts = driver.findElement(By.id("homePageProducts"));
if (homePageProducts.isDisplayed()) {
System.out.println("Test Case 4 Passed: Products are displayed on the homepage.");
31
}
else
{
System.out.println("Test Case 4 Failed: Products are not displayed on the homepage.");
}
// Test Case 5: Verify the search functionality.
WebElement searchInput = driver.findElement(By.id("searchInput"));
searchInput.sendKeys("product_name");
searchInput.sendKeys(Keys.RETURN);
// Wait for search results to load (you might want to use WebDriverWait in a real-world scenario)
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
WebElement searchResults = driver.findElement(By.id("searchResults"));
if (searchResults.isDisplayed() && searchResults.getText().contains("product_name"))
{
System.out.println("Test Case 5 Passed: Search results are displayed for the product.");
}
else
{
System.out.println("Test Case 5 Failed: Search results are not displayed for the product.");
}
// Add more test cases and actions here...
// Close the browser
driver.quit();
}
}
34
WebElement shippingInfo = driver.findElement(By.id("shippingInfo"));
if (shippingInfo.isDisplayed() && shippingInfo.getText().contains("Shipping Address:")) {
System.out.println("Test Case 11 Passed: Shipping information is displayed correctly.");
}
else
{
System.out.println("Test Case 11 Failed: Shipping information is not displayed correctly.");
}
// Test Case 12: Verify the correctness of the order total.
WebElement orderTotal = driver.findElement(By.id("orderTotal"));
if (orderTotal.isDisplayed() && orderTotal.getText().equals("Total:$100.00"))
{
System.out.println("Test Case 12 Passed: Order total is correct.");
}
else
{
System.out.println("Test Case 12 Failed: Order total is not correct.");
}
// Close the browser
driver.quit();
}
}
OUTPUT:
Test Case 1 Passed: Valid
UsernameTest Case 2 Passed:
Valid Password
Test Case 3 Passed: User Login successful
Test Case 4 Passed: Products are displayed on the
homepage. Test Case 5 Passed: Search results are
displayed for the productTest Case 9 Passed: Quantity of
Product 1 is updated to 2.
Test Case 11 Passed: Shipping information is displayed
correctly.Test Case 12 Passed: Order total is correct.
35
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT
36
EX NO: 8 INTEGRATE TESTNG WITH ABOVE TEST
DATE: AUTOMATION
AIM:
To integrate TestNG for testing an e-commerce application with test automation
PROCEDURE:
Login Module:
o Test Case 1: Verify successful login with valid credentials.
o Test Case 2: Verify error message for login with invalid credentials.
o Test Case 3: Verify the functionality of the "Forgot Password" link.
Product Browsing:
o Test Case 4: Verify that products are displayed on the homepage.
o Test Case 5: Verify the search functionality.
o Test Case 6: Verify product filtering options.
Shopping Cart:
o Test Case 7: Verify the addition of products to the shopping cart.
o Test Case 8: Verify the correctness of the items and quantities in the shopping cart.
o Test Case 9: Verify the ability to update the quantity of items in the cart.
Checkout Process:
o Test Case 10: Verify the ability to proceed to checkout.
o Test Case 11: Verify the display of correct shipping information.
o Test Case 12: Verify the correctness of the order total.
PROGRAM
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ECommerceTestSuite
{
public static void main(String[] args)
{
// Set the path to your ChromeDriver executable
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
// Initialize WebDriver
WebDriver driver = new ChromeDriver();
// Run test cases
37
runLoginModuleTests(driver);
runProductBrowsingTests(driver);
runShoppingCartTests(driver);
runCheckoutProcessTests(driver);
// Close the browser
driver.quit();
}
private static void runLoginModuleTests(WebDriver driver)
{
// Test Case 1: Verify successful login with valid credentials.
driver.get("url_of_your_ecommerce_application");
WebElement usernameInput = driver.findElement(By.id("username"));
WebElement passwordInput = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginButton"));
usernameInput.sendKeys("valid_username");
passwordInput.sendKeys("valid_password");
loginButton.click();
// Add more login module test cases...
}
private static void runProductBrowsingTests(WebDriver driver)
{
// Test Case 4: Verify that products are displayed on the homepage.
WebElement homePageProducts = driver.findElement(By.id("homePageProducts"));
if (homePageProducts.isDisplayed())
{
System.out.println("Test Case 4 Passed: Products are displayed on the homepage.");
}
else
{
System.out.println("Test Case 4 Failed: Products are not displayed on the homepage.");
}
// Test Case 5: Verify the search functionality.
WebElement searchInput = driver.findElement(By.id("searchInput"));
searchInput.sendKeys("product_name"); searchInput.sendKeys(Keys.RETURN);
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
38
{
e.printStackTrace();
}
WebElement searchResults = driver.findElement(By.id("searchResults"));
if (searchResults.isDisplayed() && searchResults.getText().contains("product_name"))
{
System.out.println("Test Case 5 Passed: Search results are displayed for the product.");
}
else
{
System.out.println("Test Case 5 Failed: Search results are not displayed for the product.");
}
}
private static void runShoppingCartTests(WebDriver driver)
{
// Test Case 7: Verify the addition of products to the shopping cart.
WebElement product = driver.findElement(By.xpath("//div[@class='product'][1]"));
product.click();
// Test Case 8: Verify the correctness of the items and quantities in the shopping cart.
WebElement cartIcon = driver.findElement(By.id("cartIcon"));
cartIcon.click();
WebElement cartItems = driver.findElement(By.id("cartItems"));
if (cartItems.isDisplayed() && cartItems.getText().contains("Product 1"))
{
System.out.println("Test Case 8 Passed: Product 1 is in the shopping cart.");
}
else
{
System.out.println("Test Case 8 Failed: Product 1 is not in the shopping cart.");
}
// Test Case 9: Verify the ability to update the quantity of items in the cart.
WebElement quantityInput = driver.findElement(By.id("quantityInput"));
quantityInput.clear(); quantityInput.sendKeys("2");
WebElement updateButton = driver.findElement(By.id("updateButton"));
updateButton.click();
// Wait for the cart to update (you might want to use WebDriverWait in a real-world scenario)
try
{
Thread.sleep(2000);
39
}
catch (InterruptedException e) {
e.printStackTrace();
}
// Check if the quantity is updated
WebElement updatedQuantity = driver.findElement(By.id("updatedQuantity"));
if (updatedQuantity.getText().equals("2"))
{
System.out.println("Test Case 9 Passed: Quantity of Product 1 is updated to 2.");
}
else
{
System.out.println("Test Case 9 Failed: Quantity of Product 1 is not updated to 2.");
}
}
private static void runCheckoutProcessTests(WebDriver driver)
{
// Test Case 10: Verify the ability to proceed to checkout.
WebElement product = driver.findElement(By.xpath("//div[@class='product'][1]"));
product.click();
WebElement cartIcon = driver.findElement(By.id("cartIcon"));
cartIcon.click();
WebElement checkoutButton = driver.findElement(By.id("checkoutButton"));
checkoutButton.click();
// Test Case 11: Verify the display of correct shipping information.
WebElement shippingInfo = driver.findElement(By.id("shippingInfo"));
if (shippingInfo.isDisplayed() && shippingInfo.getText().contains("Shipping Address:"))
{
System.out.println("Test Case 11 Passed: Shipping information is displayed correctly.");
}
else
{
System.out.println("Test Case 11 Failed: Shipping information is not displayed correctly.");
}
// Test Case 12: Verify the correctness of the order total.
WebElement orderTotal = driver.findElement(By.id("orderTotal"));
if (orderTotal.isDisplayed() && orderTotal.getText().equals("Total:$100.00"))
{
System.out.println("Test Case 12 Passed: Order total is correct.");
40
}
else
{
System.out.println("Test Case 12 Failed: Order total is not correct.");
}
}
}
OUTPUT:
Test Case 1 Passed: Valid
UsernameTest Case 2 Passed:
Valid Password
Test Case 3 Passed: User Login successful
Test Case 4 Passed: Products are displayed on the homepage.
Test Case 5 Passed: Search results are displayed for the
productTest Case 9 Passed: Quantity of Product 1 is
updated to 2.
Test Case 11 Passed: Shipping information is displayed
correctly.Test Case 12 Passed: Order total is correct.
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
41
EX NO:9. a BUILD A DATA-DRIVEN FRAMEWORK USING
DATE: SELENIUM AND TESTNG
AIM
To Build a data-driven framework using selenium and TestNG.
PROCEDURE
Create a CSV file (testdata.csv):
Create a CSV file with columns "Username" and "Password" containing test data.
Create a TestNG Test Class (LoginTest.java):
Use TestNG annotations to define the test methods.
Use @DataProvider to read test data from the CSV file.
Configure TestNG XML File (testng.xml):
Create a TestNG XML file to configure the execution of your test class.
Run the Test:
Execute the TestNG XML file to run your data-driven test.
Test Cases:
Login with valid credentials:
Login with invalid credentials:
PROGRAM
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class LoginTest
{
@Test(dataProvider = "loginData")
public void testLoginWithValidCredentials(String username, String password)
42
{
// Initialize WebDriver
WebDriver driver = new ChromeDriver();
// Open the login page driver.get("url_of_your_application_login_page");
// Locate username and password fields
WebElement usernameField = driver.findElement(By.id("username"));
WebElement passwordField = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginButton"));
//Enter valid username and password
usernameField.sendKeys(usernam e);
passwordField.sendKeys(passwor d);
// Click on the login button
loginButton.click();
// Verify successful login
WebElement welcomeMessage = driver.findElement(By.id("welcomeMessage"));
Assert.assertTrue(welcomeMessage.isDisplayed(), "Login failed for user: " + username);
// Close the browser driver.quit();
}
@Test(dataProvider = "loginData")
public void testLoginWithInvalidCredentials(String username, String password)
{
// Initialize WebDriver
WebDriver driver = new ChromeDriver();
// Open the login page driver.get("url_of_your_application_login_page");
// Locate username and password fields
WebElement usernameField = driver.findElement(By.id("username"));
WebElement passwordField = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginButton"));
// Enter invalid username and password
usernameField.sendKeys(username);
passwordField.sendKeys(password);
// Click on the login button
loginButton.click();
// Verify error message
WebElement errorMessage = driver.findElement(By.id("errorMessage"));
Assert.assertTrue(errorMessage.isDisplayed(), "Error message not displayed for user: " +username);
// Close the browser
driver.quit();
}
43
@DataProvider(name = "loginData")
public Object[][] readData() {
List<Object[]> testData = new ArrayList<>();
String csvFile = "path/to/testdata.csv";
try (BufferedReader br = new BufferedReader(new FileReader(csvFile)))
{
String line;
while ((line = br.readLine()) != null)
{
String[] data = line.split(","); testData.add(data);
}
}
catch (IOException e)
{
e.printStackTrace();
}
Object[][] result = new Object[testData.size()][2];
for (int i = 0; i < testData.size(); i++)
{
result[i] = testData.get(i);
}
return result;
}
}
44
OUTPUT
Username :
JohnPassword :
123 Login
Successful
Marks Marks
Particulars
allocated obtained
Performance 50
Viva-voce 10
Record 15
Total 75
RESULT:
45
EX NO:9. b BUILD PAGE OBJECT MODEL USING SELENIUM AND
DATE: TESTNG
AIM
To build a page object model using Selenium and TestNG.
PROCEDURE
Create Page Object Classes:
Create a class for each web page. Include web elements and methods representing the
actions onthat page.
Create a Test Class using TestNG:
Use TestNG annotations to define the test methods.
Instantiate the Page Object classes and use them in your test methods.
Run the Test:
Execute the TestNG XML file or run the test class directly to run your tests.
PROGRAM
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class LoginPage
{
private final WebDriver driver;
public LoginPage(WebDriver driver)
{
this.driver = driver;
}
public void openLoginPage(String url)
{
driver.get(url);
}
public void enterUsername(String username)
{
WebElement usernameField = driver.findElement(By.id("username"));
usernameField.sendKeys(username);
46
}
public void enterPassword(String password)
{
WebElement passwordField = driver.findElement(By.id("password"));
passwordField.sendKeys(password);
}
public void clickLoginButton()
{
WebElement loginButton =
driver.findElement(By.id("loginButton"));
loginButton.click();
}
public boolean isErrorMessageDisplayed()
{
WebElement errorMessage = driver.findElement(By.id("errorMessage"));
return errorMessage.isDisplayed();
}
}
RESULT
48
EX NO:9.c BUILD A BDD FRAMEWORK USING SELENIUM,
DATE: TESTNG AND CUCUMBER
AIM
To build a BDD framework using selenium, TestNG and Cucumber.
PROCEDURE:
1. Create a Maven Project:
Use your IDE (Eclipse, IntelliJ, etc.) to create a new Maven project.
2. Add Dependencies:
Add dependencies for Selenium, TestNG, and Cucumber in the `pom.xml` file.
3. Create Page Object Classes:
Create a `pages` package and implement the `LoginPage` class for the login page.
4. Create Feature Files:
Create a `resources` directory and a `features` sub-directory.
Write Gherkin-style scenarios in a `login.feature` file.
5. Create Step Definition Classes:
Create a `step_definitions` directory.
Implement the `StepDefinitions` class with step definition methods.
6. Set Up TestNG XML File:
Create a TestNG XML file (e.g., `testng.xml`) and configure the Cucumber runner class.
7. Write Selenium Code in Step Definitions:
Use Selenium code in the `StepDefinitions` class to interact with web elements.
Utilize methods from the `LoginPage` class.
8. Run the Tests:
Run the TestNG XML file to execute the Cucumber tests.
9. Adjust Paths and Locators:
Adapt paths, element locators, and assertions based on your application's structure.
10. Enhance the Framework:
Add features like reporting, parallel execution, and additional steps.
Install Cucumber plugins for your IDE to aid in feature file writing.
49
CODE Dependencies (Maven):
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
51
StepDefinitions.java (Cucumber Step Definitions):
package step_definitions;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import pages.LoginPage;
public class StepDefinitions
{
private WebDriver driver;
private LoginPage loginPage;
@Given("User is on the login page")
public void user_is_on_the_login_page()
{
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");driver = new ChromeDriver();
loginPage = new LoginPage(driver);
loginPage.openLoginPage("url_of_your_application_login_page");
}
@When("User enters valid username and password")
public void user_enters_valid_username_and_password()
{
loginPage.enterUsername("valid_userna me");
loginPage.enterPassword("valid_passwor d");
loginPage.clickLoginButton();
}
@When("User enters invalid username and password")
Public void user_enters_invalid_username_and_password()
{
loginPage.enterUsername("invalid_userna me");
loginPage.enterPassword("invalid_passwor d");
loginPage.clickLoginButton();
}
@Then("User should be logged in successfully")
public void user_should_be_logged_in_successfully()
52
{
// Add assertions based on your application behavior
// For example, assert that a welcome message is displayed
}
@Then("User should see an error message")
public void user_should_see_an_error_message()
{
Assert.assertTrue(loginPage.isErrorMessageDisplayed(), "Error message not displayed for invalidlogin");
}
@After
public void tearDown()
{
driver.quit();
}
}
RESULT
53