Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Grid 2 set up on Windows

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.

like image 410
idsweb Avatar asked Jul 29 '11 19:07

idsweb


People also ask

Can there be multiple hubs in Selenium grid?

There is only one hub in the selenium grid. Hub distributes the test cases across each node. Node: There can be multiple nodes in Grid.

How can I use two browsers at once in Selenium?

To execute test cases with different browsers in the same machine at the same time we can integrate Testng framework with Selenium WebDriver. Here because the testing. xml has two Test tags ('ChromeTest','FirefoxTest'),this test case will execute two times for 2 different browsers.


3 Answers

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.

like image 150
idsweb Avatar answered Dec 02 '22 05:12

idsweb


The docs do actually document this but in an unclear way.

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

Needs to be:

java -Dwebdriver.chrome.driver="C:\Users\Mike\Documents\Java Libraries\Selenium\chromedriver\chromedriver.exe" -jar selenium-server-standalone-2.1.0.jar -role webDriver -hub http://127.0.0.1:4444/grid/register -browser "browserName=chrome,platform=WINDOWS,version=12" -port 5556

You are missing grid/register from the hub URL. On top of this, if you are passing multiple arguments to -browser they need to be enclosed in quotes and separated by commas without spaces. You also need to pass in the webdriver.chrome.driver property in a similar way to how I did it.

You can check that it has successfully registered by going to your browser and hitting:

http://localhost:4444/grid/console

And as a sidenote, this is another way you could declare the desired capabilities:

DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setVersion("12");
dc.setPlatform(Platform.WINDOWS);
like image 22
Mike Kwan Avatar answered Dec 02 '22 04:12

Mike Kwan


Lets consider Hub running on Machine-A whose IPAddress is = 192.168.10.10 default port no. 4444.
Lets Node running on Machine-B whose IPAddress is = 192.168.10.20.
Lets consider operating System on HUB and Node is installed on drive C:\ (C-Drive). 
create a folder named selenium on c:\ as c:\selenium.
keep binaries of IExplorer.exe, chromeDriver.exe and Selenium-Standalone-server2.10.0.jar. (on both machine A and B).

configuring HUB on Machine-A
1- open Command prompt 
2- go to folder selenium using 
         i type cd\ then enter
         ii  type c:  then enter
         iii c:> cd selenium then enter
3- java -jar selenium-server-standalone-2.20.0.jar -role hub

Configuring NOde on Machine - B
1- open Command prompt 
2- go to folder selenium using 
         i type cd\ then enter
         ii  type c:  then enter
         iii c:> cd selenium then enter
3- java -jar selenium-server-standalone-2.20.0.jar -role node -hub http://192.168.10.10:4444/grid/register  -port 5560 -browser  browserName=chrome,maxInstance=4,platform=WIN8_1 -Dwebdriver.ie.driver=c:\selenium\ChromeDriver.exe

your node will get register with Hub on port 5560.

Test Case will become as- 

package testCase;

import static org.junit.Assert.*;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class Avinash_Google_Chrome 
{

    WebDriver driver;
    String baseUrl , nodeUrl;

    @Before
    public void setUp() throws Exception 
    {
        nodeUrl = "http://192.168.10.20:5560/wd/hub"; //Machine-A IPAdress  
                                                     with Port No.          

        DesiredCapabilities capability = DesiredCapabilities.chrome();

        driver = new RemoteWebDriver(new URL(nodeUrl),capability);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
    }

    @After
    public void tearDown() throws Exception 
    {
        driver.quit();
    }

    @Test
    public void test() throws InterruptedException
    {

        driver.get("https://www.google.co.in");     
        Thread.sleep(3000);     
        driver.findElement(By.linkText("Gmail")).click();
        Thread.sleep(3000); 
        driver.findElement(By.id("Email")).sendKeys("[email protected]");

        driver.findElement(By.id("Passwd")).sendKeys("********");

        driver.findElement(By.id("signIn")).click();

        Thread.sleep(6000);
    }

}
like image 37
Avinash Pande Avatar answered Dec 02 '22 04:12

Avinash Pande