Why CI integration enables continuous testing in Selenium Java - Automation Benefits in Action
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; public class LoginTest { private WebDriver driver; private WebDriverWait wait; @BeforeEach public void setUp() { driver = new ChromeDriver(); wait = new WebDriverWait(driver, Duration.ofSeconds(10)); driver.get("https://example.com/login"); } @Test public void testSuccessfulLogin() { WebElement usernameField = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username"))); WebElement passwordField = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password"))); WebElement loginButton = wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn"))); usernameField.sendKeys("testuser"); passwordField.sendKeys("Test@123"); loginButton.click(); wait.until(ExpectedConditions.urlContains("/dashboard")); String currentUrl = driver.getCurrentUrl(); assertTrue(currentUrl.contains("/dashboard"), "URL should contain '/dashboard' after login"); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
This test script uses Selenium WebDriver with JUnit 5 to automate the login test.
Setup: We open the browser and navigate to the login page before each test.
Test: We wait explicitly for username, password fields, and login button to be visible and clickable. Then we enter the credentials and click login.
We wait until the URL contains '/dashboard' to confirm successful login and assert this condition.
Teardown: We close the browser after the test to clean up.
This approach uses explicit waits to avoid timing issues and meaningful locators (id). It follows best practices for maintainable and reliable tests.
Now add data-driven testing with 3 different sets of user credentials (valid and invalid) to verify login behavior.
Practice
Solution
Step 1: Understand CI integration purpose
CI integration automates running tests whenever code changes are made.Step 2: Identify the benefit of automation
This automation helps find bugs early and reduces manual testing effort.Final Answer:
Tests run automatically on every code change to catch bugs early -> Option BQuick Check:
CI automation = early bug detection [OK]
- Thinking tests run only at the end
- Believing CI slows development
- Assuming manual testing is always needed
Solution
Step 1: Identify standard Java test execution in CI
Maven commandmvn testruns Java Selenium tests automatically.Step 2: Eliminate incorrect options
Manual browser opening is not automated; running selenium-server alone doesn't run tests; Python command is unrelated to Java tests.Final Answer:
Run the test class withmvn testcommand -> Option CQuick Check:
Java tests run with mvn test [OK]
- Confusing manual and automated test runs
- Using wrong commands for Java tests
- Mixing languages in CI commands
stage('Test') {
steps {
sh 'mvn test'
}
}Solution
Step 1: Understand Maven test behavior in CI
If any test fails,mvn testreturns a failure exit code.Step 2: Effect on CI pipeline
CI pipelines stop on failure exit codes and mark the build as failed to alert developers.Final Answer:
The pipeline will stop and mark the build as failed -> Option AQuick Check:
Test failure = pipeline failure [OK]
- Assuming tests auto-retry on failure
- Thinking pipeline ignores test failures
- Believing tests run without stopping pipeline
Solution
Step 1: Check CI pipeline configuration
If the test stage is missing or misconfigured, tests won't run after commits.Step 2: Rule out other causes
Passing tests still run; outdated WebDriver causes failures, not silence; commits usually trigger builds unless disabled.Final Answer:
The test stage is missing or not configured in the CI pipeline -> Option DQuick Check:
Missing test stage = no tests run [OK]
- Ignoring pipeline config errors
- Assuming tests run without pipeline setup
- Blaming WebDriver without errors
Solution
Step 1: Understand CI and Selenium test integration
Automated tests run on every commit, providing quick feedback on code quality.Step 2: Benefits of early bug detection and automation
This reduces delays from manual testing and prevents bugs from reaching production.Final Answer:
By running tests automatically on every commit, catching bugs early and reducing manual testing delays -> Option AQuick Check:
Auto tests + early bugs = faster, better delivery [OK]
- Thinking tests run only at release
- Believing manual triggers are needed
- Assuming automation removes all human checks
Ready to prove it?
Pass the test and this pattern moves unknown
