0
0
Selenium Javatesting~10 mins

Why CI integration enables continuous testing in Selenium Java - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks that a simple web login page works correctly when run automatically in a Continuous Integration (CI) environment. It verifies that the login button is clickable and the login form is present, demonstrating how CI integration allows tests to run continuously and catch issues early.

Test Code - JUnit 5 with Selenium WebDriver
Selenium Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class LoginPageCITest {
    private WebDriver driver;

    @BeforeEach
    public void setUp() {
        // Assuming chromedriver is in system PATH
        driver = new ChromeDriver();
    }

    @Test
    public void testLoginButtonIsClickable() {
        driver.get("https://example.com/login");
        WebElement loginForm = driver.findElement(By.id("login-form"));
        assertNotNull(loginForm, "Login form should be present on the page");

        WebElement loginButton = driver.findElement(By.id("login-button"));
        assertTrue(loginButton.isDisplayed() && loginButton.isEnabled(), "Login button should be visible and enabled");

        loginButton.click();
        // Additional assertions could be added here for post-click behavior
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and ChromeDriver is initializedChrome browser window opens controlled by Selenium WebDriver-PASS
2Browser navigates to https://example.com/loginLogin page loads with login form and login button visible-PASS
3Find login form element by id 'login-form'Login form element is located in the DOMAssert login form is not nullPASS
4Find login button element by id 'login-button'Login button element is located and visibleAssert login button is displayed and enabledPASS
5Click the login buttonLogin button is clicked, triggering any client-side or server-side login action-PASS
6Test ends and browser closesBrowser window closes, WebDriver quits-PASS
Failure Scenario
Failing Condition: Login button element is not found or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the login button?
AThat it changes color on hover
BThat it is visible and enabled for clicking
CThat it automatically logs in the user
DThat it is disabled initially
Key Result
Integrating UI tests into CI pipelines ensures tests run automatically on every code change, catching UI problems early and improving software quality.