0
0
Selenium Javatesting~10 mins

Docker Selenium Grid in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses Docker Selenium Grid to run a browser test remotely. It opens a browser on the grid, navigates to a website, clicks a button, and checks if the page title is correct.

Test Code - JUnit 5
Selenium Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.junit.jupiter.api.*;
import java.net.URL;

public class DockerSeleniumGridTest {
    private WebDriver driver;

    @BeforeEach
    public void setUp() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("chrome");
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
    }

    @Test
    public void testButtonClickChangesTitle() {
        driver.get("https://example.com");
        WebElement button = driver.findElement(By.id("changeTitleButton"));
        button.click();
        String title = driver.getTitle();
        Assertions.assertEquals("Title Changed", title);
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and sets up RemoteWebDriver with Docker Selenium Grid URL and Chrome capabilitiesDocker Selenium Grid is running locally on port 4444, ready to accept sessions-PASS
2RemoteWebDriver opens Chrome browser on Selenium Grid nodeChrome browser instance launched remotely inside Docker container-PASS
3Browser navigates to https://example.comPage loads with expected content including button with id 'changeTitleButton'-PASS
4Finds button element by id 'changeTitleButton'Button element is present and interactable-PASS
5Clicks the button to trigger title changePage reacts and changes title to 'Title Changed'-PASS
6Gets the page title after clickTitle is 'Title Changed'Assert that page title equals 'Title Changed'PASS
7Test ends and browser session is closedRemote browser instance is terminated and resources freed-PASS
Failure Scenario
Failing Condition: Button with id 'changeTitleButton' is not found or page title does not change as expected
Execution Trace Quiz - 3 Questions
Test your understanding
What does the RemoteWebDriver connect to in this test?
AA cloud testing service like Sauce Labs
BDocker Selenium Grid hub at http://localhost:4444/wd/hub
CLocal Chrome browser on the test machine
DA local Selenium standalone server
Key Result
Using Docker Selenium Grid allows running tests on remote browsers in containers, enabling parallel and cross-browser testing without needing local browser installations.