liveBook · Manning

UI automation

As explained in Software Testing with Generative AI

UI automation is the automated interaction with and evaluation of a software system through its user interface.

UI automation uses automated checks to interact with a software system through its user interface and evaluate expected results. AI tools can accelerate this work, but useful results depend on knowing which tasks to delegate and supplying system context. section 7.0

Build UI automation incrementally rather than requesting an entire test in one prompt:

  • Break the check into framework, setup, UI interaction, state creation, and assertion tasks. section 7.1
  • Provide product-specific context, such as HTML, selectors, test data, framework conventions, and existing driver handling. section 7.1 section 7.3
  • Review generated code and adapt it to the application, Page objects, assertions, current libraries, and automation framework. section 7.1 section 7.3

A generated login check

A prompt asking ChatGPT to create a Selenium and Java login test may produce compiling code, but integration still requires replacing driver setup, changing the application URL, moving element lookup into Page objects, updating selectors, and aligning assertions with product expectations. Supplying HTML and focused instructions can instead help generate a more useful Page object or check. section 7.1 section 7.3

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
 
public class LoginTest {
    public static void main(String[] args) {
        // Set the path to the chromedriver executable
        System.setProperty("webdriver.chrome.driver", "path/to/
        ➥ chromedriver");
 
        // Create an instance of ChromeDriver
        WebDriver driver = new ChromeDriver();
 
        // Open the application login page
        driver.get("https://example.com/login");
 
        // Find the username and password input fields
        WebElement usernameField =
        ➥ driver.findElement(By.id("username"));
        WebElement passwordField =
        ➥ driver.findElement(By.id("password"));
 
        // Enter the username and password
        usernameField.sendKeys("your-username");
        passwordField.sendKeys("your-password");
 
        // Submit the login form
        driver.findElement(By.id("login-button")).click();
 
        // Wait for the page to load
        // You can use an explicit wait here to ensure the page is 
        ➥ fully loaded
 
        // Verify the login success by checking for a specific 
        ➥ element on the next page
        WebElement welcomeMessage = driver.findElement(By.xpath("//
        ➥ h1[contains(text(),'Welcome')]"));
        if (welcomeMessage.isDisplayed()) {
            System.out.println("Login successful!");
        } else {
            System.out.println("Login failed!");
        }
 
        // Close the browser
        driver.quit();
    }
}

Inspect a representative Selenium and Java login-test listing before adapting its setup, locators, credentials, and assertions. section 7.1

How Software Testing with Generative AI covers it

How deep it goes
Breaks automated checks into guided components and adaptation steps, but stops short of reliable whole-test generation without product context.
Examples
Uses a Selenium Java login test, HTML-to-Page-object generation, and component-based automated-check construction.
What it assumes
Assumes an existing product, automation framework, driver strategy, selectors, test data, and assertions that generated code must fit.
What you can do after
Apply it via ChatGPT and Copilot to generate, improve, and maintain focused UI automation tasks while verifying their accuracy.
How it connects
Connects UI automation with Selenium, Java, Page objects, automated checks, ChatGPT, Copilot, and large language models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.