Open In App

Automation Testing - Practical Example

Last Updated : 24 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Here, we explain the Automation Testing Process in a real-world example. We’ll use Java with Selenium WebDriver and TestNG to show how it tests an e-commerce website,

which is https://ecommerce.artoftesting.com/

Here’s how each step in the Automation Testing Process would work:

1. Test Tool Selection

The first step is to select appropriate tools based on project needs, budget, and team expertise.

Tools Selected:

  • Selenium WebDriver: Used for browser automation.
  • TestNG: A testing framework for organizing and executing test cases.
  • Maven: For managing dependencies.

2. Define the Scope of Automation

Here we will test:

  • Login and Logout: Automate the process of logging in and logging out of the eCommerce website.
  • Add to Cart: Test adding items to the cart and verifying the cart's functionality.
  • Filter Test: Ensure the correct application of filters when browsing products.

The automation tests should cover UI tests and can be integrated into the CI/CD pipeline for continuous testing.

3. Planning, Design, and Development

The tests are designed to perform the following tasks:

  • LoginPageTest: Logs in with given credentials.
  • LogoutPageTest: Logs out after successful login.
  • AddCart: Adds an item to the cart.
  • FilterTest: Tests if the correct filter is applied to product listings.

Test Framework Design:

A BaseTestMain class is created to handle browser setup and teardown for all the test classes. This ensures that all tests can run on a fresh browser instance.

Java
package AutomationTesting;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public class BaseTestMain {

    protected WebDriver driver;
    protected String Url = "https://ecommerce.artoftesting.com/";

    // Set up the ChromeDriver
    @BeforeMethod
    public void setup() {
        // Set the path to your chromedriver executable
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\p\\path of chromedriver\\chromedriver.exe");
        
        
        // Initialize the ChromeDriver
        driver = new ChromeDriver();
    }

    // Close the browser after each test
    @AfterMethod
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }
}

4. Test Execution

The tests are executed using TestNG. Each test follows a structured flow with setup and teardown, ensuring tests run independently.

LoginPageTest.java

Java
package AutomationTesting;

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

import Test.BaseTestMain;

public class LoginPageTest extends BaseTestMain {

    @Test
    public void TestLogin() {
        driver.get(Url);
        driver.findElement(By.name("uname")).clear();
        driver.findElement(By.name("uname")).sendKeys("auth_user");

        Assert.assertEquals(driver.getCurrentUrl(), "https://ecommerce.artoftesting.com/");
        
        driver.findElement(By.name("pass")).clear();
        driver.findElement(By.name("pass")).sendKeys("auth_password");
        
        driver.findElement(By.className("Login_btn__pALc8")).click();
        System.out.println("Login Successful");
    }
}

LogoutPageTest.java

Java
package ArtOfTesting;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import Test.BaseTestMain;

public class LogoutPageTest extends BaseTestMain {
    
    @Test
    public void TestLogout() {
        driver.get(Url);
        driver.findElement(By.name("uname")).sendKeys("auth_user");
        driver.findElement(By.name("pass")).sendKeys("auth_password");
        driver.findElement(By.className("Login_btn__pALc8")).click();

        // Logout
        WebElement logout = driver.findElement(By.xpath("/html/body/div/div/div[1]/div/div[2]/button/div/span"));
        Actions actions = new Actions(driver);
        actions.doubleClick(logout).perform();
    }
}

AddCart.java

Java
package AutomationTesting;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import Test.BaseTestMain;

public class AddCart extends BaseTestMain {
    
    @Test
    public void Testcart() {
        driver.get(Url);
        driver.findElement(By.className("Login_btn__pALc8")).click();
        
        driver.findElement(By.xpath("/html/body/div/div/div[3]/div/div/select")).click();
        WebElement filterOption = driver.findElement(By.className("Header_select__8rhX+"));
        Actions action = new Actions(driver);    
        action.sendKeys(filterOption, "Down").perform();
        action.sendKeys("ENTER").perform();
        
        // Add book to the cart
        WebElement bookAddition = driver.findElement(By.cssSelector("#root > div > div.Products_body__ifIXG > div > div:nth-child(1) > div.Products_quantity__54gJ2 > svg:nth-child(3) > path"));
        action.doubleClick(bookAddition);
        driver.findElement(By.cssSelector("#root > div > div.Products_body__ifIXG > div > div:nth-child(1) > div.Products_priceSection__j7qrQ > button")).click();
        
        // Verify cart URL
        String cartURL = "https://ecommerce.artoftesting.com/cart";
        String currentURL = driver.getCurrentUrl();
        System.out.println("Current Cart URL: " + currentURL);
        if(cartURL.equals(currentURL)) {
            System.out.println("The URLs match, item added successfully.");
        }
    }
}

FilterTest.java

Java
package AutomationTesting;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import Test.BaseTestMain;

public class FilterTest extends BaseTestMain {
    
    @Test
    public void TestFilter() {
        driver.get(Url);
        driver.findElement(By.className("Login_btn__pALc8")).click();
        
        driver.findElement(By.xpath("/html/body/div/div/div[3]/div/div/select")).click();
        WebElement filterOption = driver.findElement(By.className("Header_select__8rhX+"));
        
        Actions action = new Actions(driver);
        action.sendKeys(filterOption, "Down").perform();
        action.sendKeys("ENTER").perform();
        
        String pageSource = driver.getPageSource();
        if(pageSource.contains("Thank you For Shopping With Us")) {
            System.out.println("Filter applied successfully!");
        }
    }
}

Create Test Automation suit class:

Java
package AutomationTesting;

import org.testng.TestNG;
import org.testng.annotations.Test;

import ArtOfTesting.AddCart;
import ArtOfTesting.FilterTest;
import ArtOfTesting.LoginPageTest;
import ArtOfTesting.LogoutPageTest;

public class AutomationTestSuite {

    @Test
    public void runAutomationTests() {
        TestNG testng = new TestNG();

        // Add the tests you want to include in the suite
        testng.setTestClasses(new Class[] {
            LoginPageTest.class,     // Login functionality test
            AddCart.class,           // Add to cart functionality test
            LogoutPageTest.class,    // Logout functionality test
            FilterTest.class         // Filter functionality test
        });

        // Run the suite
        testng.run();
    }
}

Output:

Output-of-Test-Automation-Example-In-suit
Output of Test Automation Example In suit

5. Maintenance

Maintenance involves updating the scripts as the application evolves. This includes updating locators, fixing broken tests, and handling any changes in the UI.

  • Updating Test Scripts: Whenever the UI or functionality changes (e.g., class names, button placements), the test scripts should be updated to reflect those changes.
  • Test Reports: After execution, TestNG generates reports that display which tests passed or failed. This is useful for continuous monitoring of the application’s stability.


This automation testing process is a complete cycle from tool selection to execution and maintenance. In this practical example, Selenium WebDriver is used to automate an eCommerce site’s login, logout, cart management, and filter features. TestNG integrates with Selenium to help run and organize tests, and the results are analyzed through TestNG’s reports.


Article Tags :

Explore