Selenium 4 Grid Standalone Mode

Tutorial​​ 23​​ -​​ Selenium 4​​ Grid​​ Standalone mode

Let us now see the first mode viz Standalone Selenium 4 grid mode​​ (both hub and node on same machine)​​ 

Go to the official download page​​ https://www.selenium.dev/downloads/​​ 

Download the latest stable version of Selenium server

​​ 

 

Next, cd to the location where you have downloaded the jar and execute the command​​ java –jar <.jar filename>​​ as shown below. You would see a list of commands available

One of the commands that you see above is ‘standalone’.

To start the standalone grid server, execute the command​​ java –jar <.jar filename> standalone

Notice below that the grid server automatically detects the 2 browsers

Also notice that our standalone grid server starts at the url​​ http://192.168.33.1:4444

Launch this url.​​ 

Notice below the grid page that shows windows with chrome and windows with firefox browsers. None of the session is running right now

Click the​​ ​​ icon, we see a popup with grid server details


Click ‘Sessions’ on the left hand side, notice that there are no running sessions at this moment

Let us see how to execute our test script on this grid server. Before we see that, we have to first download the latest stable chrome browser executable

 

 

Click documentation, you will be redirected to below page

https://chromedriver.chromium.org/​​ 

 

Click stable release link that you see above​​ 

Download the zip file and extract it.​​ 

Place the chromedriver jar in the same location where you have kept the selenium grid jar​​ 

 

Open command prompt and cd to above location, start the standalone grid server

 

Create a new class file, see below.​​ 

This simple code will create a new session of remote webdriver and our script will be executed on grid ​​​​ 

 

Run the script

See below, 1 session is started​​ 

Notice below, session is started on chrome browser

 

Similarly, download the firefox executable

 

 

 

 

Comment chrome options line and add firefox options line

Run

 

Notice below, the capabilities column now shows that our test is running on firefox browser​​ 

Since our grid server is running on windows localhost, we can also change the url to​​ http://localhost:4444​​ as shown below

 

So this is how we can execute our test in a standalone grid server.

 

Code snippets

package​​ sel4scripts;

 

import​​ java.net.MalformedURLException;

import​​ java.net.URL;

 

import​​ org.openqa.selenium.By;

import​​ org.openqa.selenium.WebDriver;

import​​ org.openqa.selenium.firefox.FirefoxOptions;

import​​ org.openqa.selenium.remote.RemoteWebDriver;

 

public​​ class​​ GridStandaloneMode {

 

public​​ static​​ void​​ main(String[]​​ args)​​ throws​​ MalformedURLException, InterruptedException {

 

//ChromeOptions opt = new ChromeOptions();

 FirefoxOptions​​ opt​​ =​​ new​​ FirefoxOptions();

 WebDriver​​ driver​​ =​​ new​​ RemoteWebDriver(new​​ URL("http://192.168.33.1:4444"),opt);

driver.get("http://google.com");

driver.findElement(By.name("q")).sendKeys("Learning Standalone grid");

 Thread.sleep(3000);

 

 }

 

}

 

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 1st Nov 2024