Test Overview
This test verifies that Selenium Grid is correctly set up by connecting to the Grid hub, launching a browser node, navigating to a web page, and checking the page title.
This test verifies that Selenium Grid is correctly set up by connecting to the Grid hub, launching a browser node, navigating to a web page, and checking the page title.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.junit.jupiter.api.*; import java.net.URL; public class SeleniumGridSetupTest { 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 testOpenPageAndCheckTitle() { driver.get("https://example.com"); String title = driver.getTitle(); Assertions.assertEquals("Example Domain", title); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and DesiredCapabilities for Chrome browser are set | Test environment ready to connect to Selenium Grid hub | - | PASS |
| 2 | RemoteWebDriver connects to Selenium Grid hub at http://localhost:4444/wd/hub with Chrome capabilities | Browser node is launched by Selenium Grid | - | PASS |
| 3 | Driver navigates to https://example.com | Browser displays the Example Domain page | - | PASS |
| 4 | Test retrieves the page title | Page title is 'Example Domain' | Assert that page title equals 'Example Domain' | PASS |
| 5 | Driver quits and browser node closes | Browser closed, resources released | - | PASS |