node.jsseleniumselenium-grid2

Selenium Grid maxSession ignored


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:

1) Start a selenium grid hub running locally:

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
}

2) Start a selenium grid node running locally:

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.

3) Start 5 child processes, each with its own webdriver using the hub server

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.

UPDATE 2016-04-14

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.


Solution

  • 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.