Reputation: 33
I can't seem to get Selenium Grid2 to abide by the maxSession parameter, no matter whether I set it as a command line option or in a JSON config, whether I set it on the hub or node or both. Grid ignores it completely. Before I open a bug ticket for it, I want to make sure I'm doing this right.
This is a node.js application utilizing the selenium-server-standalone-jar and selenium-webdriver NPM modules, both up to date. The process breaks down roughly as follows:
var jar = require("selenium-server-standalone-jar"),
hub = require("selenium-webdriver/remote").SeleniumServer(jar.path, {
loopback: true,
port: 4444,
args: [ "-role hub", "-hubConfig " + config_path ]
});
That hub config file looks like this:
{
"host": null,
"port": 4444,
"newSessionWaitTimeout": -1,
"throwOnCapabilityNotPresent": true,
"nodePolling": 5000,
"cleanUpCycle": 5000,
"timeout": 300000,
"browserTimeout": 0,
"maxSession": 1
}
var hub = require("selenium-webdriver/remote").SeleniumServer(jar.path, {
loopback: true,
port: 5555,
args: [ "-role node", "-nodeConfig " + config_path ]
});
The node config looks like this:
{
"capabilities": [
{
"browserName": "firefox",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration": {
"maxSession": 1,
"port": 5555,
"host": "127.0.0.1",
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": "127.0.0.1"
}
}
So at this point I have a hub running with maxSession=1 and a node running with maxSession=1 and maxInstances=1 (for Firefox). This isn't how the application will function long term, I'm just trying to get Selenium Grid to demonstrate that it CAN limit sessions.
Each proceeds to run through its browser actions and then closes the webdriver before terminating.
What I would expect to see: the grid should limit the number of browsers that those child processes can open. Whether that should result in the child processes queuing up for their turn.
What I actually see: A succession of firefox windows open (I've let it climb to ~30 before killing it) and start running through their steps in parallel, totally ignoring the maxSession and maxInstance configuration.
I have isolated this problem in the SeleniumServer class. It appears that the "args" option I supply to its constructor is being ignored. This explains my inability to reach localhost:4444/grid/console while tests are running; the standalone server jar isn't running with a "hub" role.
I have verified that if I use child_process.exec to run the jar directly (with its role and JSON config) that everything starts working more or less correctly, but there's a problem with this approach in that a race condition exists between hub readiness and cucumber tests' attempts to connect a webdriver to it. Ideally, I'd like to use SeleniumServer like I planned. Any advice on what I might be doing wrong with it, or how I can make it behave, would be greatly appreciated.
Upvotes: 1
Views: 1266
Reputation: 359
What you are missing here is, Se Grid does not have the capability to initiate test scripts in parallel. If you're framework (I did it using TestNG) is capable of generating multi threads, then Se Grid will happily consume it and run them for you.
Se Grid is just an executor, it just consumes what you feed into it. You need to create and feed multiple parallel tests to it via your framework.
Upvotes: 0
Reputation: 33
It turns out it was just a problem with the way I was forming the args array. It expects param names and values to be separate items, so [ "-role hub", "-hubConfig " + config_path ]
doesn't work, but [ "-role", "hub", "-hubConfig", config_path ]
probably does.
I say probably because now I have a new problem where the hub start() times out after 30 seconds, but at least I can load up grid/console during those 30 seconds and see that the configuration is correct. Thanks @djangofan and @nash for your help.
Upvotes: 1
Reputation: 359
Update your testNG.xml file with thread-count="10" (or how many ever instance you want to run Ex: 2, 3, 4 etc)
I use testNG to run my tests in parallel. @Factory and @DataProvider generate my tests programatically. I was running into the same problem. After trying various workarounds I updated my testng.xml file with thread-count="10" and it worked.
I still wasn't able to get it to sync with .JSON file settings used as the hub config, but it did help me achieve what I was trying to. Here's my complete testNG.xml file (I do parallel="methods" as that's how @Factory works)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteMain" parallel="methods" thread-count="10">
<test name="maintest">
<classes>
<class name="test.java.MainDriverScript"></class>
</classes>
</test>
</suite>
Upvotes: 0