将硒测试指向网格上的各种平台并不起作用?

时间:2014-03-12 18:50:52

标签: selenium grid

Selenium 2.38.0,Grid2,Java 1.7,TestNG Framework,Firefox 27.0,Chrome 33.0,Windows 7,Windows 8

  1. 总结 - 我在实验室的5个VMshares上安装了Selenium Grid2,节点如下:
  2. Hub - Win7 节点1 - Win7 / Firefox 节点2 - Win7 / Chrome 节点3 - Win8 / Firefox 节点4 - Win8 / Chrome

    1. 问题,我将平台作为XML参数传递给TestNG,以便在Selenium驱动程序启动时设置platformName和平台功能,以便集线器将其引导到正确的节点。这似乎不起作用,测试总是似乎从第一个节点开始,只有Win7 / Firefox。以下是我为Firefox设置的驱动程序代码示例:

       public void setDriver(String browser,String environment,String platform) throws MalformedURLException, IOException {      
       switch (browser) {
       case "firefox":
       FirefoxProfile ffProfile = new FirefoxProfile();
       ffProfile = new ProfilesIni().getProfile(Constants.FF_PROFILE_PATH);
      
       caps =  DesiredCapabilities.firefox();
       caps.setCapability(FirefoxDriver.PROFILE,ffProfile); // RemoteWebDriver must use DesiredCapabilities, WebDriver can use same or Options...
      
       // this directs what remote grid node to run on...
       if ( environment.equalsIgnoreCase("remote") ) {
          switch(platform) {
          case "Window 7":
             caps.setCapability("platform","WINDOWS");
             caps.setCapability("platformName","WIN7-firefox");
             break;
          case "Window 8":
             caps.setCapability("platform","WIN8");
             caps.setCapability("platformName","WIN8-firefox");
             break;
          default:
             break;
          }
      
          this.driver = new RemoteWebDriver(new URL(Constants.REMOTE_HUB_URL),caps);
       }
      
       else
          this.driver = new FirefoxDriver(caps);
      
       break;
      
    2. 如果我将XML参数更改为“Windows 8”,有时它会在Windows 7节点上启动,有时它会在Windows 8节点上启动,如果其他人忙。任何人都知道为什么这不起作用,我通过JSON配置文件配置节点如下:

    3. 节点1:

      {
         "capabilities":
         [
            {
               "platformName": "WIN7-firefox",
               "browserName": "firefox",
               "browser-version": "",
               "maxInstances": 1,
               "platform": "WINDOWS",
               "seleniumProtocol": "WebDriver",
               "acceptSslCerts": true,
               "javascriptEnabled": true,
               "takesScreenshot": true
            }
         ],
      

      节点2:

      "capabilities":
         [
            {
               "platformName": "WIN8-firefox",
               "browserName": "firefox",
               "browser-version": "",
               "maxInstances": 1,
               "platform": "WIN8",
               "seleniumProtocol": "WebDriver",
               "acceptSslCerts": true,
               "javascriptEnabled": true,
               "takesScreenshot": true
            }
         ],
      

1 个答案:

答案 0 :(得分:0)

这是因为你的win7节点使用平台“WINDOWS”,这意味着它可以接受包括windows 8在内的任何Windows执行请求。

虽然看起来不太好,但您可以使用“VISTA”而不是“WINDOWS”来分隔两个平台组。我想知道为什么他们不添加“WIN7”选项或自定义条件。

显然,platformName在这里不起作用。