Selenium Grid Tutorial: Test on Multiple Devices from One Laptop

Written by Manoj  »  Updated on: June 06th, 2025

Selenium Grid Tutorial: Test on Multiple Devices from One Laptop

Running one test at a time is fine. But what if your website needs to work on Chrome, Firefox, Edge, Android, and iOS? You’ll spend hours testing the same script over and over. That’s where Selenium Grid helps. It lets you run tests in parallel across devices from one laptop. You just need to set it up the right way. This is now a key part of what learners practice in Selenium Online Training courses that focus on real-world testing.

Let’s understand how it works from a technical but beginner-friendly angle.

How Selenium Grid Works?

Selenium Grid uses a hub-node model. One system becomes the hub. The hub gets your test commands. Then it sends the test to one of the connected nodes. Nodes are devices or browsers where tests actually run.

For example, you write a test on your laptop. That test gets sent to a Chrome node or an Android node, depending on your setup. All this happens over the network.

The major parts are:

Hub: Controls the test flow

Nodes: Run tests on specific browsers/devices

WebDriver: Talks to the hub

DesiredCapabilities: Tells the hub which browser or OS is needed

This setup is very useful for teams who want to save time and get results faster.

Docker Setup for Local Grid

You don’t need many machines. You can simulate multiple devices using Docker containers. Here's a sample docker-compose.yml file to run one hub and two nodes (Chrome and Firefox):

version: "3"

services:

  selenium-hub:

    image: selenium/hub:4.12.0

    ports:

      - "4442:4442"

      - "4443:4443"

      - "4444:4444"

  chrome:

    image: selenium/node-chrome:4.12.0

    depends_on:

      - selenium-hub

    environment:

      - SE_EVENT_BUS_HOST=selenium-hub

      - SE_EVENT_BUS_PUBLISH_PORT=4442

      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  firefox:

    image: selenium/node-firefox:4.12.0

    depends_on:

      - selenium-hub

    environment:

      - SE_EVENT_BUS_HOST=selenium-hub

      - SE_EVENT_BUS_PUBLISH_PORT=4442

      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

To run this:

docker-compose up -d

This will set up the hub and two browser nodes. The Selenium Grid dashboard will be available at http://localhost:4444/ui.

Now your tests can run on different browsers from one place.

Writing a Test for Selenium Grid

Here’s a simple Java example:

DesiredCapabilities caps = new DesiredCapabilities();

caps.setBrowserName("chrome");

WebDriver driver = new RemoteWebDriver(

  new URL("http://localhost:4444/wd/hub"), caps);

driver.get("https://example.com");

System.out.println(driver.getTitle());

driver.quit();

Just change setBrowserName() to the browser you want.

Use frameworks like TestNG or PyTest to run multiple tests in parallel. It will reduce test time and improve efficiency.

Comparing Local vs Cloud Selenium Grids

Let’s compare local Grid (using your laptop) with cloud-based Grid options like BrowserStack or Sauce Labs:

Feature Local Grid Cloud-Based Grid

Setup Time Manual setup Ready-to-use

Device Coverage Limited (laptop only) Many real devices

Speed Network dependent Optimized infrastructure

Debug Tools Browser logs only Screenshots, videos

Cost Free Paid service

For basic testing or training, local Grid works well. For enterprise-level testing, cloud Grids are better.

Challenges and Tips

Running Grid is useful but not always simple. Here are common mistakes:

● Forgetting to match browser version with WebDriver

● Hardcoding paths or IPs

● Not using dynamic test data

● Running too many tests at once and crashing the node

To fix this:

● Always use version-matched drivers

● Parameterize test inputs

● Monitor container CPU/memory

● Use tools like Jenkins to control test jobs

Learners in Selenium Online Training From India often face these issues.

Sum up,

Selenium Grid lets you run tests on multiple devices from one system. Docker makes it easy to simulate Chrome and Firefox nodes locally. DesiredCapabilities help choose which node runs each test. Use CI tools like Jenkins for automated Grid testing. Learners in Selenium Testing Training in Pune benefit from hands-on Grid labs and real project use. In Pune, Grid skills are expected in real automation jobs due to rising cross-platform app demand.



Note: IndiBlogHub features both user-submitted and editorial content. We do not verify third-party contributions. Read our Disclaimer and Privacy Policyfor details.


Related Posts

Sponsored Ad Partners
ad4 ad2 ad1 Daman Game 82 Lottery Game Daman Game