Tutorial 24 - Selenium 4 Grid Classic mode
Let us now see the second mode viz Classic mode (hub and node to be started separately)
Go to the official download page and download the latest stable version of Selenium server
https://www.selenium.dev/downloads/
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. Let us now start the hub by executing below command:
java –jar <jarfilename.jar> hub
Launch the hub url. Notice that the grid has no registered nodes yet
Next we will register a node. Open another terminal and execute below command: java –jar <jarfilename.jar> node
Notice that the node has been added
Refresh the hub session, see below. We can now see registered nodes (chrome and firefox browsers)
Now that we have registered node to a hub, create a script and import the Capabilities class as shown below
Run the script.
Notice below that the script is executed. If you don’t see the script getting executed, stop and restart the hub and node commands
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
So this is how we can execute our test in a classic grid server.
Code snippets
package sel4scripts;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
public class GridClassicMode {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
Capabilities cap = new FirefoxOptions();
//Capabilities cap = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"),cap);
driver.get("https://www.google.com/");
driver.findElement(By.name("q")).sendKeys("Hello Grid !!!");
Thread.sleep(3000);
}
}
Thank you for reading!