πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Scenarios
Scenario 87 of 100
Selenium Grid & Docker
Intermediate

Executing Automation Suites on a Remote Selenium Grid

☁️Scenario Overview

Executing Automation Suites on a Remote Selenium Grid

Key Takeaways & Cheat Sheet

  • βœ“Build a URL connection pointing to the central remote hub endpoint
  • βœ“Use standard browser Options classes (like ChromeOptions) for capabilities
  • βœ“Instantiate RemoteWebDriver to send commands to the Selenium Grid
  • βœ“Manage session teardowns cleanly to release browser nodes

Short Direct Answer

To run tests on a remote machine or cloud provider (like SauceLabs or BrowserStack), use a `RemoteWebDriver` instance. Configure browser options (using W3C compliant options like `ChromeOptions`) and pass the remote hub URL along with the browser options to the `RemoteWebDriver` constructor.

⚠️ Senior Warning (Red Flag)

Do not use obsolete DesiredCapabilities configurations in modern code. Always use browser-specific Options classes (ChromeOptions, FirefoxOptions) to configure capabilities.

πŸ’‘ STAR Deep Dive Explanation & Pro Tip

Selenium Grid acts as a router. The hub receives commands from RemoteWebDriver and assigns them to the appropriate matching node browser session.

SeleniumAutomation.java
Selenium 4 + Java
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;

public class GridExecution {
    public static void main(String[] args) throws Exception {
        // 1. Define browser Options configuration
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--window-size=1920,1080");
        
        // 2. Specify Grid Hub url endpoint
        URL gridUrl = new URL("http://192.168.1.50:4444/wd/hub");
        
        // 3. Initialize RemoteWebDriver session
        WebDriver driver = new RemoteWebDriver(gridUrl, options);
        
        driver.get("https://careerraah.com");
        driver.quit();
    }
}