Test Overview
This test runs a Selenium Java test on GitHub Actions. It opens a browser, navigates to a page, clicks a button, and verifies the expected text appears. It checks that the GitHub Actions workflow correctly executes the Selenium test.
This test runs a Selenium Java test on GitHub Actions. It opens a browser, navigates to a page, clicks a button, and verifies the expected text appears. It checks that the GitHub Actions workflow correctly executes the Selenium test.
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 static org.junit.jupiter.api.Assertions.assertEquals; public class GitHubActionsSeleniumTest { private WebDriver driver; @BeforeEach public void setUp() { // Assuming ChromeDriver is set in PATH or via WebDriverManager driver = new ChromeDriver(); } @Test public void testButtonClickShowsMessage() { driver.get("https://example.com/testpage"); WebElement button = driver.findElement(By.id("show-message-btn")); button.click(); WebElement message = driver.findElement(By.id("message")); assertEquals("Hello, GitHub Actions!", message.getText()); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts - JUnit initializes test class and calls setUp() | ChromeDriver instance created, browser window opens | - | PASS |
| 2 | Browser navigates to https://example.com/testpage | Page loads with a button having id 'show-message-btn' and hidden message element with id 'message' | - | PASS |
| 3 | Finds button element by id 'show-message-btn' | Button element is located on the page | - | PASS |
| 4 | Clicks the button | Message element with id 'message' becomes visible with text 'Hello, GitHub Actions!' | - | PASS |
| 5 | Finds message element by id 'message' and reads text | Message element text is 'Hello, GitHub Actions!' | Assert that message text equals 'Hello, GitHub Actions!' | PASS |
| 6 | Test completes, tearDown() called to quit browser | Browser closes, WebDriver quits | - | PASS |