0
0
Selenium Javatesting~10 mins

GitHub Actions configuration in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - JUnit 5 with Selenium WebDriver
Selenium Java
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();
        }
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts - JUnit initializes test class and calls setUp()ChromeDriver instance created, browser window opens-PASS
2Browser navigates to https://example.com/testpagePage loads with a button having id 'show-message-btn' and hidden message element with id 'message'-PASS
3Finds button element by id 'show-message-btn'Button element is located on the page-PASS
4Clicks the buttonMessage element with id 'message' becomes visible with text 'Hello, GitHub Actions!'-PASS
5Finds message element by id 'message' and reads textMessage element text is 'Hello, GitHub Actions!'Assert that message text equals 'Hello, GitHub Actions!'PASS
6Test completes, tearDown() called to quit browserBrowser closes, WebDriver quits-PASS
Failure Scenario
Failing Condition: Button with id 'show-message-btn' is not found or message text does not match expected
Execution Trace Quiz - 3 Questions
Test your understanding
What is the first action performed by the test after starting?
AOpen browser and navigate to the test page
BClick the button with id 'show-message-btn'
CAssert the message text
DClose the browser
Key Result
Always verify that element locators are correct and that the page is fully loaded before interacting. This ensures stable tests especially in CI environments like GitHub Actions.