Test Overview
This test runs a Selenium Java test case in a Continuous Integration (CI) environment and verifies that the test report is generated and published successfully after test execution.
This test runs a Selenium Java test case in a Continuous Integration (CI) environment and verifies that the test report is generated and published successfully after test execution.
import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.io.File; public class ReportPublishingCITest { private static WebDriver driver; private static final String REPORT_PATH = "target/surefire-reports/index.html"; @BeforeClass public static void setUp() { // Set path to chromedriver executable if needed driver = new ChromeDriver(); } @Test public void testGoogleSearch() { driver.get("https://www.google.com"); WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys("Selenium testing"); searchBox.submit(); WebElement results = driver.findElement(By.id("search")); Assert.assertTrue(results.isDisplayed()); } @AfterClass public static void tearDown() { if (driver != null) { driver.quit(); } // Verify report file exists after tests File reportFile = new File(REPORT_PATH); Assert.assertTrue("Test report should be generated", reportFile.exists()); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts - JUnit initializes and runs setUp method | ChromeDriver instance is created, browser window opens | - | PASS |
| 2 | Browser navigates to https://www.google.com | Google homepage is loaded in browser | - | PASS |
| 3 | Finds search input box by name 'q' | Search input box is located on the page | - | PASS |
| 4 | Types 'Selenium testing' into search box and submits form | Search results page loads with query results | - | PASS |
| 5 | Finds search results container by id 'search' | Search results container is present and visible | Assert that search results container is displayed | PASS |
| 6 | Test finishes, tearDown method runs and browser closes | Browser window is closed, WebDriver quits | - | PASS |
| 7 | Check if test report file 'target/surefire-reports/index.html' exists | CI environment file system contains test report file | Assert that test report file exists | PASS |