集线器:MAC 64位 Nod:Windows 32位
无法使用Selinum网格MAC作为集线器和Windows作为点头运行Chrome浏览器吗?
使用下面的代码我收到错误(驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;有关更多信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver。最新版本可以从{下载{3}}命令持续时间或超时: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();
}
答案 0 :(得分:4)
我有从Mac机器到Windows Vista运行Chrome浏览器的解决方案 (在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);
答案 1 :(得分:1)
实际上,chromedriver.exe必须存储在Windows节点上。我是通过在我的测试文件夹中创建子文件夹/lib
来实现的,我在其中存储了chromedriver和所有其他与selenium网格相关的内容。稍后,在运行节点时,请执行以下操作:
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
,所以如果这是 hub 计算机,那么节点设置将是这样的:
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
请注意,localhost已更改为集线器的IP。所以接下来的步骤是:
<强> 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);
答案 2 :(得分:0)
使用以下命令在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);