<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Selenium Grid]]></title><description><![CDATA[Selenium Grid]]></description><link>https://selenium-grid.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 06:39:10 GMT</lastBuildDate><atom:link href="https://selenium-grid.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Selenium GRID]]></title><description><![CDATA[What is Selenium Grid?Selenium Grid is a tool that enables you to run Selenium tests simultaneously on multiple machines, operating systems, and browsers. It allows you to run tests in parallel across various environments.It consists of:

Hub: The ce...]]></description><link>https://selenium-grid.hashnode.dev/selenium-grid</link><guid isPermaLink="true">https://selenium-grid.hashnode.dev/selenium-grid</guid><category><![CDATA[selenium]]></category><category><![CDATA[Selenium Grid]]></category><category><![CDATA[Selenium java]]></category><category><![CDATA[selenium-webdriver]]></category><dc:creator><![CDATA[Prashant Dhotre]]></dc:creator><pubDate>Sun, 27 Jul 2025 11:36:56 GMT</pubDate><content:encoded><![CDATA[<p><strong>What is Selenium Grid?</strong><br /><strong>Selenium Grid</strong> is a tool that enables you to run Selenium tests simultaneously on multiple machines, operating systems, and browsers. It allows you to run tests in parallel across various environments.<br />It consists of:</p>
<ul>
<li><p><strong>Hub</strong>: The central point that receives test requests and directs them to nodes.</p>
</li>
<li><p><strong>Nodes</strong>: Machines (or containers) where browsers are launched and tests are executed.</p>
</li>
</ul>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li><p>Java JDK 8+</p>
</li>
<li><p>Maven</p>
</li>
<li><p>Docker (for Grid setup)</p>
</li>
<li><p>Eclipse</p>
</li>
<li><p>Basic understanding of Selenium</p>
</li>
</ul>
<p><strong>Step 1: Set up Selenium Grid using Docker</strong><br />Using Docker CLI</p>
<pre><code class="lang-bash">docker network create grid
docker run -d -p 4444:4444 --net grid --name selenium-hub selenium/hub
docker run -d --net grid --name chrome-node -e HUB_HOST=selenium-hub selenium/node-chrome
docker run -d --net grid --name firefox-node -e HUB_HOST=selenium-hub selenium/node-firefox
</code></pre>
<p><strong>Verify Grid UI to see if the Hub and Nodes are working</strong><br />Visit <a target="_blank" href="http://localhost:4444/grid"><code>http://localhost:4444/grid</code></a> in your browser to check if the Hub and Nodes are running.</p>
<p><strong>Step 2: Create a Java Selenium Test</strong><br />Set up a Maven project with the following dependency</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.seleniumhq.selenium<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>selenium-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.34.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>
</code></pre>
<p><strong>Step 3: Write Test Code to Run on the Grid</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> org.openqa.selenium.WebDriver;
<span class="hljs-keyword">import</span> org.openqa.selenium.remote.RemoteWebDriver;
<span class="hljs-keyword">import</span> org.openqa.selenium.remote.DesiredCapabilities;

<span class="hljs-keyword">import</span> java.net.URL;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GridTest</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception </span>{
        <span class="hljs-comment">// URL of the Grid Hub</span>
        URL gridUrl = <span class="hljs-keyword">new</span> URL(<span class="hljs-string">"http://localhost:4444/wd/hub"</span>);

        <span class="hljs-comment">// Browser capability (can be "chrome" or "firefox")</span>
        DesiredCapabilities capabilities = <span class="hljs-keyword">new</span> DesiredCapabilities();
        capabilities.setBrowserName(<span class="hljs-string">"chrome"</span>);

        <span class="hljs-comment">// Create RemoteWebDriver</span>
        WebDriver driver = <span class="hljs-keyword">new</span> RemoteWebDriver(gridUrl, capabilities);

        <span class="hljs-comment">// Run test</span>
        driver.get(<span class="hljs-string">"https://example.com"</span>);
        System.out.println(<span class="hljs-string">"Title: "</span> + driver.getTitle());

        driver.quit();
    }
}
</code></pre>
<p><strong>Step 4: Run Tests in Parallel</strong><br />You can use a test framework like <strong>TestNG</strong> to run multiple tests in parallel.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">suite</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"GridSuite"</span> <span class="hljs-attr">parallel</span>=<span class="hljs-string">"tests"</span> <span class="hljs-attr">thread-count</span>=<span class="hljs-string">"2"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">test</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"ChromeTest"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">parameter</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"browser"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"chrome"</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">classes</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">class</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"tests.GridTest"</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">classes</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">test</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">test</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"FirefoxTest"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">parameter</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"browser"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"firefox"</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">classes</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">class</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"tests.GridTest"</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">classes</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">test</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">suite</span>&gt;</span>
</code></pre>
]]></content:encoded></item></channel></rss>