1

Beginner on selenium grid, I just created a small test that allows to navigate on the home page of stackoverflow For this I placed the selenium server on my disk, I opened 2 terminals as shown in the documentation here.

https://www.selenium.dev/documentation/grid/getting_started/#hub-and-nodes

The test starts well, and now I would like to run the same test under firefox while modifying the OS (for example: windows). How do I do this? Do I have to create another test file in my project? And then how to run the test with multiple configurations? I can’t find an answer to these questions.

My configuration:

-Linux Ubuntu 20.04

-Google and chrome 95

-the last version selenium server : 4.1.1

Here's the code of the test:

public class StepGoStackoverflow { RemoteWebDriver driver; String nodeUrl; @Given("I'm on google search page") public void i_m_on_google_search_page() { try { nodeUrl = "http://localhost:4444"; ChromeOptions options = new ChromeOptions(); // options.addArguments("--headless"); options.addArguments("start-maximized"); driver = new RemoteWebDriver(new URL(nodeUrl), options); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); driver.get("https://www.google.com"); } catch (MalformedURLException error) { error.printStackTrace(); } } @When("I enter the name of the site") public void i_enter_the_name_of_the_site() { WebElement webElementList = driver.findElement(By.id("L2AGLb")); webElementList.click(); driver.findElement(By.name("q")).sendKeys("stackoverflow", Keys.ENTER); } @Then("I'm navigated on the home page of stackoverflow") public void i_m_navigated_on_the_home_page_of_stackoverflow() { driver.findElement(By.xpath("//a[@href='https://stackoverflow.com/']")).click(); driver.close(); } } 

EDIT: I forgot to give the snipet of Gerkhin:

Feature: search the home page of stackoverflow Scenario: Go to the site stackoverflow Given I'm on google search page When I enter the name of the site Then I'm navigated on the home page of stackoverflow 

Thank you

1 Answer 1

1

I can see that you are using Cucumber so I edited your question to add corresponding tag (since that matters as we're taking about parameterization).

Grid part

The idea of the Selenium Grid is that you install Grid components at a cluster where the nodes represent different OSs and each runtime/OS has one or more drivers and browsers installed.

So you configure nodes so that they know where are drivers installed and how to run browsers (and what browser can each node execute: e.g. Chrome, Firefox) and each node registers at the grid component called hub.

On one side a hub knows which nodes are running at which OS and what browsers they can operate with. On another hand hub acts as remote web driver (it exposes webdriver protocol to external clients aka automated tests).

You can find an overview of the grid here and find configuration flags and aspects here.

Code part

On the code side you parameterize your tests so that each test is executed from scratch but with different capabilities set up. In your example you only use ChromeOptions which would make hub to dispatch your calls to a node that can run Chrome browser.

Your challenge is to make your code configure different capabilities each run so that Grid will look up appropriate node in the cluster for your test (like "ah-ha.. you want to run Firefox on Linux which means I'll dispatch your calls to node C")

Cucumber

Since you are using Cucumber in your example I assume that you tend to incorporate it into final solution. If so, you need to start from learning parameterization practices in cucumber: See here, here and here; setting up context in Cucumber, and sharing the state in Cucumber with Dependency Injection with Guice or PicoContainer.

Combine everything, add a handful of parallelization and you will gain the most value from your framework.

Sign up to request clarification or add additional context in comments.

5 Comments

It’s still confusing for me. However, thank you for your very complete answer, which helps me to see it more clearly. So, when you say: "So you configure nodes so that they know where are drivers installed and how to run browsers" Does it mean I have to use System.setProperty() method for each node ? Or should I use the web drivers class (FirefoxOptions, InternetexplorerOptions....) in order to set up capabilities for each node ? Or should I do both ? Thank you very much.
A node is a separate application that you cannot control directly from your code so you cannot use system properties. You configure all grid components (including nodes) when you start them either with environment variables or with command line parameters or from toml config file. For example you use this parameter to configure a driver that will be used by a particular node.
Thank you, I’m starting to understand. if I understood correctly, I have to configure the nodes by command line. For each selenium instance, I need a terminal where I configure the node (webdriver, version, OS...). Or I can use the TOML too options. Do you know where I can find an example of this? Thanks again
Yes. Basically if you do not need different OSs (say you need only different browsers) you can start from docker images that Selenium provides and compose/swarm tools. They will automatically bring everything up locally (in docker-compose case - you will get many isolated containers with different browsers locally) or distributed over several network hosts with swarm case. Regarding the examples, I believe there are numerous ones over the Internet.
Thank you for your patience and your explanations

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.