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.
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.
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(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and sets up RemoteWebDriver with Docker Selenium Grid URL and Chrome capabilities | Docker Selenium Grid is running locally on port 4444, ready to accept sessions | - | PASS |
| 2 | RemoteWebDriver opens Chrome browser on Selenium Grid node | Chrome browser instance launched remotely inside Docker container | - | PASS |
| 3 | Browser navigates to https://example.com | Page loads with expected content including button with id 'changeTitleButton' | - | PASS |
| 4 | Finds button element by id 'changeTitleButton' | Button element is present and interactable | - | PASS |
| 5 | Clicks the button to trigger title change | Page reacts and changes title to 'Title Changed' | - | PASS |
| 6 | Gets the page title after click | Title is 'Title Changed' | Assert that page title equals 'Title Changed' | PASS |
| 7 | Test ends and browser session is closed | Remote browser instance is terminated and resources freed | - | PASS |