Selenium Grid 4, How to match a particular pattern capability in ruby 3.x.x

681 views Asked by At

I'm unable to match the custom capabilities in ruby code for selenium grid 4 nodes.

As per this documentation: https://www.selenium.dev/documentation/grid/configuration/cli_options/#matching-node-a

I've tried to do the same thing in ruby like below:

  1. Started the selenium grid with this command:
java -jar ./selenium-server-4.1.2.jar  hub --session-request-timeout 500 --port 4444 --tracing false

  1. Started Running nodes with the below commands:
node a) java -jar selenium-server-4.1.2.jar node --max-sessions 74 --log-level "fine" --port 5555  --driver-implementation "chrome" --override-max-sessions true --max-threads 55 --driver-configuration display-name="$(hostname)" stereotype='{"browserName":"chrome","custom_key1":"custom_value1"}'

node b) java -jar selenium-server-4.1.2.jar node --max-sessions 74 --log-level "fine" --port 5556  --driver-implementation "chrome" --override-max-sessions true --max-threads 55 --driver-configuration display-name="$(hostname)" stereotype='{"browserName":"chrome","custom_key2":"custom_value2"}'

Then From My Ruby Code, I've tried to connect to the node 'a' which uses custom_key1 and custom_value1 like below:



options = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized'])

caps = {"custom_key1":"custom_value1"}

options.add_option("my_options",caps)

And finally trying to initialize the browser:

driver = Selenium::WebDriver.for(:remote, :url => "http://192.168.29.141:4444", :capabilities => options)

So here Im able to get the driver but its getting randomly from the above nodes. If I pass custom_key1 and custom_value1 then I should get the browser from that node 'a' only. But However browser session is getting created in node 'b' too. Im getting browser from node 'b' even after I pass custom_key1 from my code.

Could someone please help me to match this particular nodes with some pattern

1

There are 1 answers

0
student On

The correct command to create the nodes :

A)
java -jar selenium-server-4.1.2.jar node --detect-drivers false --log-level "fine" --port 5555   --override-max-sessions true --max-threads 55 --driver-configuration display-name="$(hostname)" max-sessions=74 stereotype='{"browserName":"chrome","cluster:pcgeo":"hetzner"}'
B)
java -jar selenium-server-4.1.2.jar node --detect-drivers false --log-level "fine" --port 5556   --override-max-sessions true --max-threads 55 --driver-configuration display-name="$(hostname)" max-sessions=74 stereotype='{"browserName":"chrome","cluster:pcgeo":"aws"}'

Correct code to add ruby options:

opt = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized'])
opt.add_option("cluster:pcgeo","aws_india")
driver = Selenium::WebDriver.for(:remote, :url => "http://192.168.29.141:4444" , :capabilities => opt)