【问题标题】:How to run chrome browser in grid using MAC as hub and Windows as Nod?如何使用 MAC 作为集线器和 Windows 作为 Nod 在网格中运行 chrome 浏览器?
【发布时间】:2013-07-07 04:55:12
【问题描述】:

集线器:MAC 64 位 点头:Windows 32 位

无法使用 Selinum 网格 MAC 作为集线器和 Windows 作为节点运行 chrome 浏览器?

使用下面的代码我收到一个错误(驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置;有关更多信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver。可以从http://code.google.com/p/chromedriver/downloads/list 下载最新版本命令持续时间或超时:668 毫秒)

public void chromeWindows() throws MalformedURLException{

System.setProperty("webdriver.chrome.driver", "/Users/vinayakkhatate/Desktop/jar/chromedriver2");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:/Users/user/AppData/Local/Google/Chrome/Application/chrome.exe");


DesiredCapabilities capabilies = DesiredCapabilities.chrome();
capabilies.setBrowserName("chrome");
capabilies.setPlatform(Platform.VISTA);


driver = new RemoteWebDriver(new URL("http://10.0.11.118:5566/wd/hub"), capabilies);
driver.get(baseUrl);
System.out.println(driver.getTitle());

driver.close();
driver.quit();

}

【问题讨论】:

    标签: selenium selenium-webdriver selenium-grid


    【解决方案1】:

    我有从 Mac 机器运行 Chrome 浏览器到 Windows Vista 的解决方案 (在windows vista机器上下载chromedriver并保存)

    使用以下命令在 Mac 中启动集线器

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

    使用以下命令在 windows 中启动节点

    java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver=pathtochromedriver\chromedriver.exe
    

    现在在Mac机上用eclipse写代码

    DesiredCapabilities capabilies = DesiredCapabilities.chrome();
    capabilies.setBrowserName("chrome");
    capabilies.setPlatform(Platform.ANY);
    
    driver = new RemoteWebDriver(new URL("http://<ip address of windows machine>:5555/wd/hub"), capabilies); 
    

    【讨论】:

      【解决方案2】:

      实际上,chromedriver.exe 必须存储在 Windows 节点上。我通过在我的测试文件夹中创建子文件夹 /lib 来实现,我在其中存储 chromedriver 和所有其他与硒网格相关的东西。稍后,在运行节点时,这样做:

      java -jar lib/selenium-server-standalone-2.28.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe 
      

      特别注意 -D 开关:

      -Dwebdriver.chrome.driver=lib\chromedriver.exe 
      

      这就是我设置 chromedriver.exe 路径的方式。注意相对路径,所以我不必真正关心工具在绝对路径中运行的位置。希望对你有帮助

      编辑 显然,集线器和节点计算机应该可以通过 IP 访问。例如,我的工作 PC 在我们的内部网络中有 IP 10.131.7.11,所以如果这将是 集线器 计算机,那么节点设置将是这样的:

      java -jar lib/selenium-server-standalone-2.28.0.jar -role node -hub http://10.131.7.11:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe
      

      请注意,本地主机已更改为集线器的 IP。所以接下来的步骤是:

      • 将集线器和节点设置在同一网络上,并可由 IP 地址访问
      • 在 mac 机器上运行 hub
      • 在 vista 上运行节点,指向集线器的 IP 地址
      • 交叉手指 :)
      • 然后尝试再次运行 chrome

      EDIT2 这就是我运行 chrome 的方式:

        if (System.getProperty("os.name").contains("Windows")) {
              System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
          } else {
              System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver");
          }
      
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
      
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
      

      【讨论】:

      • 仍然出现同样的错误。请提供用 MAC 机器编写的代码,以便在 VISTA 中运行 chrome。
      • 您是否相应地更改了集线器地址?是在节点机器上存储chromedriver.exe吗? chromedriver 需要在节点上而不是在集线器上
      • 是的,我已经在 windows 中下载了 chromedriver 并使用 "java -jar lib/selenium-server-standalone-2.28.0.jar -role node -hub localhost:4444/grid/register -maxSession 15 -browser 设置节点browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe"
      • 我的 MAC 端代码似乎有问题,但无法解决,
      • 查看编辑。您正在针对本地主机运行节点 - 同一台机器。这可能是根本原因
      【解决方案3】:

      使用以下命令在 Mac 中启动集线器

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

      使用以下命令在 windows 中启动节点

      java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=pathtochromedriver\chromedriver.exe 
      

      从下面的位置下载 chromedriver

      https://code.google.com/p/chromedriver/downloads/list

      现在用以下逻辑初始化驱动程序实例

      System.setProperty("webdriver.chrome.driver", "/Users/test/chromedriver");
      DesiredCapabilities dc=new DesiredCapabilities();
      dc.setBrowserName("chrome");
      dc.setPlatform(Platform.WINDOWS);
      driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
      driver.get(Constants.SERVER_URL_NAME);
      

      【讨论】:

      • 我已经像你上面所说的那样声明了集线器和节点,并在mac机器中编写了与上面相同的逻辑,但仍然出现错误。我已经下载了适用于 windows 和 mac 的 chrome 驱动程序。 System.setProperty("webdriver.chrome.driver", "/Users/test/chromedriver"); --这里需要提供mac的chrome驱动路径对吗?
      • 你需要在 windows 机器而不是 mac 中启动节点。正如我提到的,在 windows 机器中下载 chromedriver 并从 windows 机器启动节点。
      猜你喜欢
      • 2018-06-12
      • 2011-01-09
      • 2021-05-19
      • 2021-04-07
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多