5

Notes: This is cross-posted on SO - https://stackoverflow.com/questions/48169961/tagging-selenium-nodes-and-requesting-nodes-without-that-tag

We have an internal selenium grid that currently has 20 nodes (FF and CH) with the capacity for scaling if/when needed. All of these nodes are configured exactly the same, therefore when we run tests, we don't really care which node gets allocated.

Now we have a need to have a couple of nodes configured differently. We then need to allocate those nodes only when a test specifically requests one. So far so good - we can use capabilities to "tag" nodes and then use DesiredCapabilities to request one of these "special" nodes (e.g. we can use platform description, etc.)

The question is how do we avoid getting these nodes allocated unless specifically requested? What I am looking for is this behaviour, essentially:

  • if a specific capability is requested, then allocate one of the nodes matching that capability
  • if a specific capability is not requested, then allocate any other node other than these special ones

We need to avoid having to change existing tens of thousands of selenium tests so that the default behaviour will result in a "standard" node.

Making any changes to the node config or hub config is ok.

Of course, we can always set up a separate hub and attach these special nodes to this special hub - but that feels like an overkill to me to manage two hubs.

Any other suggestions?

1
  • All the nodes should be tagged, so just tag the baseline node appropriately, base/standard/normal whatever is appropriate. Jun 16, 2021 at 14:05

1 Answer 1

0

The Selenium Grid allows you to run tests on multiple nodes, which can be either a local machine or a remote machine. To tag nodes and request nodes without a specific tag, you can use the -role option.

Here's an example:

  1. To tag a node, you can use the following command when starting the node:

    java -jar selenium-server-standalone.jar -role node -hub http://hub-host:4444/grid/register -browser browserName=firefox,version=48,maxInstances=1,platform=LINUX -browser browserName=chrome,version=48,maxInstances=1,platform=LINUX -maxSession 1 -port 5555 -registerCycle 5000 -nodeConfig nodeConfig.json -debug

In the above example, we're starting the node and registering it with the hub at http://hub-host:4444/grid/register. The node is tagged as a "node" with a -role node option.

  1. To request a node without a specific tag, you can use the following code in your test script:

    DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("browserName", "firefox"); capabilities.setCapability("version", "48"); capabilities.setCapability("platform", "LINUX"); capabilities.setCapability("seleniumProtocol", "WebDriver"); capabilities.setCapability("maxInstances", "1"); capabilities.setCapability("-role", "node");

    WebDriver driver = new RemoteWebDriver(new URL("http://hub-host:4444/wd/hub"), capabilities);

In the above example, we're requesting a node without a "node" tag by setting the -role capability to "node".

This is how you can tag nodes and request nodes without a specific tag in Selenium Grid.

2
  • How would that work? When you start selenium, you need to specify either "node" or "hub". If you request capabilities of "not node", what are you going to get? I think you're confusing "role" with "tag". Tags are additional tags that you can add to each node (e.g. "firefox", "windows 10", etc) - I can have dozens of nodes with "firefox" tag, and dozens of nodes without it. I need to get any node without "firefox" tag.
    – Aleks G
    Feb 1 at 15:41
  • You're correct. My apologies for the confusion. -role option in Selenium Grid is used to specify if the instance should act as hub or node, not to tag the node. To tag nodes, you can use -extraCapabilities option when starting a node, & then specify the tag in your test script when requesting node. To request node without specific tag, you can use capabilities.setCapability() method in your test script to set desired capabilities, but not include the tag as one of the capabilities. The hub will then assign the next available node that matches the desired capabilities to run the test on. Feb 3 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.