Test Overview
This test opens a browser remotely using RemoteWebDriver, navigates to a website, clicks a button, and verifies the page title.
This test opens a browser remotely using RemoteWebDriver, navigates to a website, clicks a button, and verifies the page title.
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.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; import java.net.URL; import java.time.Duration; import static org.junit.Assert.assertEquals; public class RemoteWebDriverTest { public static void main(String[] args) throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName("chrome"); WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); try { driver.get("https://example.com"); WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement moreInfoLink = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.more-info"))); moreInfoLink.click(); wait.until(ExpectedConditions.titleContains("More Information")); String title = driver.getTitle(); assertEquals("More Information - Example Domain", title); } finally { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Create DesiredCapabilities for Chrome browser | Capabilities object set to use Chrome | - | PASS |
| 2 | Instantiate RemoteWebDriver with Selenium Grid URL and capabilities | Remote browser session started on Selenium Grid | - | PASS |
| 3 | Navigate to https://example.com | Browser opened with example.com loaded | Page URL is https://example.com | PASS |
| 4 | Wait until the 'More Info' link is clickable | 'More Info' link is visible and clickable | Element located by CSS selector 'a.more-info' is clickable | PASS |
| 5 | Click the 'More Info' link | Browser navigates to the More Information page | - | PASS |
| 6 | Wait until page title contains 'More Information' | Page title updated to include 'More Information' | Title contains 'More Information' | PASS |
| 7 | Get page title and assert it equals 'More Information - Example Domain' | Page title is 'More Information - Example Domain' | assertEquals passes confirming correct page title | PASS |
| 8 | Quit the RemoteWebDriver session | Browser session closed | - | PASS |