Selenium Grid 2在Windows上设置

时间:2011-07-29 19:06:41

标签: selenium-webdriver selenium-grid

我在Windows 7上设置了Selenium Grid 2(selenium-server-standalone-2.1.0)(我也尝试过Windows Server 2008)64位。我在本地测试WebDriver,一切都很顺利。

我用以下方式启动集线器:

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

为FireFox添加webDriver节点有效,但Google Chrome等其他任何内容都会引发IllegalOperation异常。

例如:

我尝试为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

当您转到http://localhost:4444/grid/console

时,这将显示为集线器上的节点

我添加代码来调用webDriver,例如:

            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);

我几乎立即得到一个例外:

{“找不到:{platform = windows,browserName = chrome,version = 12}”}

似乎甚至没有找到节点。我是新手,这是我在设置中遗漏的东西? (互联网资源管理器做同样的事情,不断变化的版本似乎没有帮助。)

我已经搜索了几个小时和几个小时但没有任何与例外相符的内容似乎与我的问题一样通用。

5 个答案:

答案 0 :(得分:2)

IllegalOperation Exception {“找不到:{platform = windows,browserName ...是由没有匹配功能引起的(它永远不会到达节点)。

如果我在启动明确声明平台和浏览器的节点时使用配置文件,例如:

{
"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",

        }
}

并使用此行启动集线器:
java -jar selenium-server-standalone-2.2.0.jar -role webdriver -nodeConfig myconfig.json -hub http:// [myIP]:4444 / grid / register

并创建如下功能:

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

然后测试工作(您必须将IE中的所有区域设置为受保护的方式) 注:我注意到Windows在WINDOWS中是大写的,否则你会收到错误。

答案 1 :(得分:2)

文档确实以不明确的方式记录了这一点。

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

需要:

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

您在中心网址中缺少grid/register。除此之外,如果要将多个参数传递给-browser,则需要将它们括在引号中,并用逗号分隔,不能有空格。您还需要以与我的方式类似的方式传递webdriver.chrome.driver属性。

您可以通过访问浏览器并点击:

来检查它是否已成功注册
http://localhost:4444/grid/console

作为旁注,这是宣布所需能力的另一种方式:

DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setVersion("12");
dc.setPlatform(Platform.WINDOWS);

答案 2 :(得分:0)

尝试降低有关chrome版本和操作系统的条件:

您注册节点的代码如下

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

创建浏览器:

DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.BrowserName, "chrome");

DesiredCapabilities capability = DesiredCapabilities.chrome();

可能是您的Chrome更新时没有注意到,或者版本号“12”与您安装的版本不完全相符。 如果它在这些条件下运行,请尝试使用新组合添加“Platform = WINDOWS”和“Version”CapabilityTypes。

答案 3 :(得分:0)

您可以设置

driver.quit();

在脚本的末尾

答案 4 :(得分:0)

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("aavinashpande@gmail.com");

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

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

        Thread.sleep(6000);
    }

}