0
0
Selenium Javatesting~10 mins

Selenium Grid setup in Selenium Java - Test Execution Trace

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

Test Code - JUnit 5
Selenium Java
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();
        }
    }
}
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and DesiredCapabilities for Chrome browser are setTest environment ready to connect to Selenium Grid hub-PASS
2RemoteWebDriver connects to Selenium Grid hub at http://localhost:4444/wd/hub with Chrome capabilitiesBrowser node is launched by Selenium Grid-PASS
3Driver navigates to https://example.comBrowser displays the Example Domain page-PASS
4Test retrieves the page titlePage title is 'Example Domain'Assert that page title equals 'Example Domain'PASS
5Driver quits and browser node closesBrowser closed, resources released-PASS
Failure Scenario
Failing Condition: Selenium Grid hub is not running or unreachable at http://localhost:4444/wd/hub
Execution Trace Quiz - 3 Questions
Test your understanding
What does the RemoteWebDriver do in this test?
AStarts the Selenium Grid hub
BRuns tests locally without Grid
CConnects to Selenium Grid hub and launches a browser node
DChecks the page title
Key Result
Always verify that the Selenium Grid hub URL is correct and the hub is running before running tests that use RemoteWebDriver.