SOFTWARE TESTING AND AUTOMATION LABORATORY Course Code L:T:P:S : 22ISL72 : 0:0:1:0 Credits CIE Marks : 1 : 50 Exam Hours : 3 SEE Marks : 50 Course Outcomes: At the end of the Course, the Student will be able to: 22ISL72.1 Derive the test cases for a given problem using testing approaches such as decision table approach, Equivalence class testing and Boundary Value Analysis method 22ISL72.2 Derive test cases for UI of web applications. 22ISL72.3 Illustrate automated testing of web applications using selenium automation framework 22ISL72.4 Illustrate excel file updated using Selenium Mapping of Course Outcomes to Program Outcomes and Program Specific Outcomes : CO/PO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 CO1 3 3 3 3 - - - - - - - 3 3 3 CO2 3 3 3 3 3 - - - - - - 3 3 3 CO3 3 3 3 3 3 - - - - - - 3 3 3 CO4 3 3 3 3 3 - - - - - - 3 3 3 Experiment No. Experiment PART - A 1 Design and develop a program in a language of your choice to solve the triangle problem defined as follows: Accept three integers which are supposed to be the three sides of a triangle and determine if the three values represent an equilateral triangle, isosceles triangle, scalene triangle, or they do not form a triangle at all. Assume that the upper limit for the size of any side is 10. Derive test cases for your program based on decision table approach, execute the test cases and discuss the results 2 Design, develop, code and run the program in any suitable language to solve the commission problem. Analyze it from the perspective of boundary value testing, derive different test cases, execute these test cases and discuss the test results. 3 Design, develop, code and run the program in any suitable Language to implement the Next Date function. Analyze it from the perspective of equivalence class value testing, derive different test cases, execute these test cases and discuss the test results. 4 Design front - end for any web application and derive the test cases as applicable. Validate the UI elements using JavaScript. 5 Write a program for matrix multiplication. “Introspect the causes for its failure and write down the possible reasons”. Analyze the Positive test cases and Negative Test cases. 6 Write a JUnit unit test for evaluating calculator Java class. PART - B 7 Write a Junit test case for checking the database connection. 8 Illustrate automated testing using selenium to perform tests on login web pages. 9 Write a program to perform cross - browser testing in Selenium and make use of TestNG to specify different browsers for your test execution. 10 Develop and test a program to count the number of check boxes on the page checked and unchecked count. 11. Write and test a program to provide a total number of different objects present on a web page using selenium. 12 Use selenium to test a program that updates 10 student records into a table from an Excel file. Program 1: Design and develop a program in a language of your choice to solve the triangle problem defined as follows. Accept 3 integers which are supposed to be 3 sides of a triangle and determine if the 3 values represent an equilateral triangle,isosceles,scalene or they do not form a triangle at all. Assume that the upper limit for the size of any side is 10. Derive test cases for your program based on the Decision Table approach, execute the test cases and discuss the test results. Solution: 1. Accept three integers (sides of a triangle). 2. Determine if they form: - Not a triangle (violates triangle property) - Equilateral triangle (all 3 sides equal) - Isosceles triangle (any 2 sides equal) - Scalene triangle (all sides different) 3. Constraint: Each side ≤ 10. 4. Use Decision Table Testing to derive test cases, execute them, and discuss results. import java.util.Scanner; public class TriangleType { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter side 1: "); int a = sc.nextInt(); System.out.print("Enter side 2: "); int b = sc.nextInt(); System.out.print("Enter side 3: "); int c = sc.nextInt(); // Check upper limit condition if (a > 10 || b > 10 || c > 10 || a <= 0 || b <= 0 || c <= 0) { System.out.println("Invalid input! Each side must be between 1 and 10."); return; } if (a + b > c && a + c > b && b + c > a) { if (a == b && b == c) { System.out.println("Equilateral Triangle"); } else if (a == b || b == c || a == c) { System.out.println("Isosceles Triangle"); } else { System.out.println("Scalene Triangle"); } } else { System.out.println("Not a Triangle"); } sc.close(); } } Output Program 2 : Design, develop, code and run the program in any suitable language to solve the commission problem. Analyze it from the perspective of boundary value testing, derive different test cases, execute these test cases and discuss the test results. Solution: 1. Accept sales amount (integer/float). 2. Calculate commission based on rules (a typical commission structure is used in software testing examples): ● If sales ≤ 1000 → 10% commission ● If 1001 ≤ sales ≤ 1800 → 15% commission ● If sales > 1800 → 20% commission 3. Apply Boundary Value Testing (BVA) to derive test cases. 4. Implement the program in Java. 5. Execute and discuss results. import java.util.Scanner; public class SalesCommission { public static void main(String[] args) { final double LOCK_PRICE = 45.0; final double STOCK_PRICE = 30.0; final double BARREL_PRICE = 25.0; int totalLocks = 0, totalStocks = 0, totalBarrels = 0; Scanner sc = new Scanner(System.in); System.out.println("Enter the number of locks (enter -1 to exit):"); int locks = sc.nextInt(); while (locks != -1) { System.out.println("Enter the number of stocks and barrels:"); int stocks = sc.nextInt(); int barrels = sc.nextInt(); // Validation for locks if (locks < 1 || locks > 70) { System.out.println("Value of locks not in the range 1 – 70"); } else if (totalLocks + locks > 70) { System.out.println("New total locks = " + (totalLocks + locks) + " not in the range 1 – 70"); } else { totalLocks += locks; } // Validation for stocks if (stocks < 1 || stocks > 80) { System.out.println("Value of stocks not in the range 1 – 80"); } else if (totalStocks + stocks > 80) { System.out.println("New total stocks = " + (totalStocks + stocks) + " not in the range 1 – 80"); } else { totalStocks += stocks; } // Validation for barrels if (barrels < 1 || barrels > 90) { System.out.println("Value of barrels not in the range 1 – 90"); } else if (totalBarrels + barrels > 90) { System.out.println("New total barrels = " + (totalBarrels + barrels) + " not in the range 1 – 90"); } else { totalBarrels += barrels; } System.out.println("Total locks = " + totalLocks); System.out.println("Total stocks = " + totalStocks); System.out.println("Total barrels = " + totalBarrels); System.out.println("\nEnter the number of locks (enter -1 to exit):"); locks = sc.nextInt(); } // Final totals System.out.println("\nFinal Totals:"); System.out.println("Locks = " + totalLocks); System.out.println("Stocks = " + totalStocks); System.out.println("Barrels = " + totalBarrels); // Calculate sales double lockSales = totalLocks * LOCK_PRICE; double stockSales = totalStocks * STOCK_PRICE; double barrelSales = totalBarrels * BARREL_PRICE; double sales = lockSales + stockSales + barrelSales; System.out.println("Total sales = " + sales); // Calculate commission double commission; if (sales > 1800) { commission = (0.10 * 1000) + (0.15 * 800) + (0.20 * (sales - 1800)); } else if (sales > 1000) { commission = (0.10 * 1000) + (0.15 * (sales - 1000)); } else { commission = 0.10 * sales; } System.out.println("Commission = " + commission); sc.close(); } } Output Problem 3: Design, develop, code, and run the program in any suitable Language to implement the Next Date function. Analyse it from the perspective of equivalence class value testing, derive different test cases, execute these test cases, and discuss the test results. Solution: Input - (Day, Month, Year) Output - (Day, Month, Year) of the next calendar date Must handle - Leap years, Month boundaries, Year change (Dec 31 → Jan 1 of next year), Invalid inputs Input - Year: 2000 – 2100 (Valid), outside this range (Invalid) - Month: 1 – 12 (Valid), otherwise (Invalid) - Day: Depends on month & leap year import java.util.Scanner; public class NextDate { // Check if a year is leap year private static boolean isLeap(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } // Get number of days in a given month of a year private static int getDaysInMonth(int month, int year) { switch (month) { case 4: case 6: case 9: case 11: return 30; case 2: return isLeap(year) ? 29 : 28; default: return 31; } } // Validate input date private static boolean isValidDate(int day, int month, int year) { if (year < 2000 || year > 2100) { System.out.println("Year not in range 2000 – 2100"); return false; } if (month < 1 || month > 12) { System.out.println("Month not in range 1 – 12"); return false; } int maxDays = getDaysInMonth(month, year); if (day < 1 || day > maxDays) { System.out.println("Day not in range 1 – " + maxDays); return false; } return true; } // Compute next date private static int[] getNextDate(int day, int month, int year) { int maxDays = getDaysInMonth(month, year); if (day < maxDays) { day++; } else { day = 1; if (month == 12) { month = 1; year++; } else { month++; } } return new int[]{day, month, year}; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int day, month, year; while (true) { System.out.println("Enter today's date (dd mm yyyy):"); day = sc.nextInt(); month = sc.nextInt(); year = sc.nextInt(); if (isValidDate(day, month, year)) { break; // exit loop only when input is valid } System.out.println("Invalid date. Try again.\n"); } // Calculate tomorrow’s date int[] tomorrow = getNextDate(day, month, year); // If year crosses 2100 boundary if (tomorrow[2] > 2100) { System.out.println("The next day is out of boundary value of year"); } else { System.out.printf("Next day is: %d %d %d\n", tomorrow[0], tomorrow[1], tomorrow[2]); } sc.close(); } } Identify Equivalence Classes (ECs) 1. Day (D) Valid : EC-D1: 1 ≤ D ≤ 28 (common to all months). EC- D2: 29 (valid in months with ≥29 days). EC- D3: 30 (valid in months with ≥30 days). EC-D4: 31 (valid in months with 31 days). Invalid : EC-D5: D < 1. EC-D6: D > 31. 2. Month (M) Valid : EC-M1: 1 – 12. Invalid : EC-M2: M < 1. EC-M3: M > 12. 3. Year (Y) Valid : EC-Y1: 2000 – 2100. Invalid : EC-Y2: Y < 2000. EC-Y3: Y > 2100. Weak Normal Equivalence Class Testing (Choose one valid value from each valid EC, no combinations of invalids.) Strong Normal Equivalence Class Testing (Choose all combinations of valid ECs — at least 1 per class.) Weak Robust Equivalence Class Testing (Choose one invalid value from each invalid EC, keep the others valid.) Strong Robust Equivalence Class Testing (Choose combinations of invalid ECs, multiple invalids at once.) Problem 4: Design a front-end for any web application and derive the test cases as applicable. Validate the UI elements using JavaScript. index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login Form Validation</title> <link rel="stylesheet" href="style.css"> <script src="login.js" defer></script> </head> <body> <div class="container"> <div class="main"> <h2>Login Form</h2> <form id="loginForm"> <label for="username">User Name:</label> <input type="text" id="username" required> <label for="password">Password:</label> <input type="password" id="password" required> <button type="submit" id="submit">Login</button> </form> <p class="note"> <strong>Note:</strong> For demo, use <br> <b>Username:</b> Form <br> <b>Password:</b> 123 </p> </div> </div> </body> </html> style.css body { font-family: Arial, sans-serif; background: #f4f4f9; margin: 0; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background: #fff; padding: 25px 30px; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); } .main h2 { text-align: center; margin-bottom: 20px; } label { display: block; margin: 10px 0 5px; font-weight: bold; } input { width: 100%; padding: 8px; margin-bottom: 12px; border: 1px solid #ccc; border-radius: 6px; } button { width: 100%; padding: 10px; background: #007bff; color: white; font-size: 16px; border: none; border-radius: 6px; cursor: pointer; } button:hover { background: #0056b3; } .note { margin-top: 15px; font-size: 14px; color: #555; } login.js let attempts = 3; // Maximum login attempts allowed document.getElementById("loginForm").addEventListener("submit", function(e) { e.preventDefault(); // Prevent form from submitting by default const username = document.getElementById("username").value.trim(); const password = document.getElementById("password").value.trim(); if (username === "Form" && password === "123") { alert("Login successful!"); window.location.href = "success.html"; } else { attempts--; alert(`Invalid login. You have ${attempts} attempt(s) left.`); if (attempts === 0) { document.getElementById("username").disabled = true; document.getElementById("password").disabled = true; document.getElementById("submit").disabled = true; alert("No attempts left. Login disabled."); } } }); success.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Login Success</title> </head> <body> <h2> Successful Login!</h2> </body> </html> Test case table Problem 5: Write a program for matrix multiplication. “Introspect the causes for its failure and write down the possible reasons”. Analyze the Positive test cases and Negative Test cases. import java.util.Scanner; public class MatrixMultiplication { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Input dimensions System.out.print("Enter number of rows in M1: "); int m = sc.nextInt(); System.out.print("Enter number of columns in M1: "); int n = sc.nextInt(); System.out.print("Enter number of rows in M2: "); int o = sc.nextInt(); System.out.print("Enter number of columns in M2: "); int p = sc.nextInt(); // Check multiplication condition if (n != o) { System.out.println("Matrix Multiplication is not possible (M1 columns ≠ M2 rows)."); return; } // Input Matrix A int[][] A = new int[m][n]; System.out.println("Enter elements of Matrix A:"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { System.out.print("A[" + i + "][" + j + "] : "); A[i][j] = sc.nextInt(); } } // Input Matrix B int[][] B = new int[o][p]; System.out.println("Enter elements of Matrix B:"); for (int i = 0; i < o; i++) { for (int j = 0; j < p; j++) { System.out.print("B[" + i + "][" + j + "] : "); B[i][j] = sc.nextInt(); } } // Result matrix m × p int[][] result = new int[m][p]; // Multiplication logic for (int i = 0; i < m; i++) { for (int j = 0; j < p; j++) { for (int k = 0; k < n; k++) { result[i][j] += A[i][k] * B[k][j]; } } } // Print Result System.out.println("Resultant Matrix:"); for (int i = 0; i < m; i++) { for (int j = 0; j < p; j++) { System.out.print(result[i][j] + " "); } System.out.println(); } sc.close(); } } Problem 6: Write a JUnit unit test for evaluating calculator Java class. Requirements ● Java JDK (version 8+ recommended) ● JUnit 5 library (or JUnit 4, but I showed JUnit 5) ● An IDE (Eclipse, IntelliJ IDEA, or NetBeans) public class Calculator { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } public int multiply(int a, int b) { return a * b; } public int divide(int a, int b) { if (b == 0) { throw new ArithmeticException("Division by zero not allowed"); } return a / b; }