Selenium Grid 2 set up on Windows

idsweb picture idsweb · Jul 29, 2011 · Viewed 16.2k times · Source

I am setting up Selenium Grid 2 (selenium-server-standalone-2.1.0) on Windows 7 (I have also tried Windows Server 2008) both 64 bit. I test the WebDriver locally and all is well.

I launch the hub with:

java -jar selenium-server-standalone-2.1.0.jar -role hub

Adding a webDriver node for FireFox works, but anything else such as Google Chrome throws an IllegalOperation Exception.

For example:

I try adding a node for Chrome:

java -jar selenium-server-standalone-2.1.0.jar -role webDriver -hub http://127.0.0.1:4444 -browser browserName=chrome platform=windows version=12 -port 5556

This shows as a node on the hub when you go to http://localhost:4444/grid/console

I add code to call the webDriver such as:

            DesiredCapabilities capability = new DesiredCapabilities();
            capability.SetCapability(CapabilityType.Platform, "windows");
            capability.SetCapability(CapabilityType.Version, "12");
            capability.SetCapability(CapabilityType.BrowserName, "chrome");

            IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), capability);

I get an exception almost immediately:

{"cannot find : {platform=windows, browserName=chrome, version=12}"}

It seems as if the node isn't even being found. I am new to this is it something I have missed in the set up? (internet explorer does the same and changing versions doesn't seem to help).

I have searched for hours and hours but nothing that matches the exception seems as generic as my problem.

Answer

idsweb picture idsweb · Jul 31, 2011

The IllegalOperation Exception {"cannot find : {platform=windows, browserName... is caused by there being no matching capability (it never gets as far as a Node).

If I use a config file when I launch the node that explicitly states the platform and browser such as:

{
"capabilities":
        [
                {
                        "browserName":"firefox",
                        "maxInstances":1
                },
                {
                        "browserName":"chrome",
            "platform":"WINDOWS",
                        "maxInstances":1
                },
                {
                        "browserName":"internet explorer",
                        "version":"9",
                        "platform":"WINDOWS",
                        "maxInstances":1
                }
        ],
"configuration":
        {
                "cleanUpCycle":2000,
                "timeout":30000,
                "proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
                "maxSession":5,
                "url":"http://[myIP]/wd/hub",

        }
}

and launch the hub with this line:
java -jar selenium-server-standalone-2.2.0.jar -role webdriver -nodeConfig myconfig.json -hub http://[myIP]:4444/grid/register

and create the capabilities like so:

DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.Platform, "WINDOWS");
capability.SetCapability(CapabilityType.BrowserName, "internet explorer");

Then the test works (you have to set all Zones in IE to protected by the way).
N.B. I did notice that windows is UPPERCASE as in WINDOWS or you get an error.