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
