Java 无法启动 Chrome,即在使用 Selenium 网格的节点上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20262096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to launch chrome, ie on node using Selenium grid
提问by TDHM
I've hub and node running and I'm trying to run test on node for chrome browser, but it's failing with error: The path to the driver executable must be set by the webdriver.chrome.driver system property;
我已经在运行集线器和节点,我正在尝试在节点上为 chrome 浏览器运行测试,但它失败并出现错误: The path to the driver executable must be set by the webdriver.chrome.driver system property;
But I've set it. Following is the code which I'm using:
但是我已经设置了。以下是我正在使用的代码:
package seleniumgridpackage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SeleniumGridTest {
WebDriver driver;
String baseUrl = "http://www.google.com";
String expectedTitle = "Google";
@BeforeTest
public void setUp() throws MalformedURLException {
File file = new File("C://Drivers//chromedriver.exe");
//File file = new File("C://Drivers//IEDriverServer.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.VISTA);
driver = new RemoteWebDriver(new URL("http://x.x.x.x:5566/wd/hub"), cap);
}
@Test
public void test(){
driver.get(baseUrl);
Assert.assertEquals(driver.getTitle(), expectedTitle);
}
@AfterTest
public void tearDown(){
driver.quit();
}
}
Note:I've put chromedriver.exe
in C://Drivers
folder of both node and hub. Sams happens when I try with IE
注:我已经把chromedriver.exe
在C://Drivers
这两个节点和枢纽的文件夹中。当我尝试使用 IE 时发生 Sams
Please help me understand what I'm doing wrong.
请帮助我理解我做错了什么。
采纳答案by Pavel Janicek
Everything is in how do you start the node. So First, do the usual:
一切都在你如何启动节点。所以首先,做通常的:
java -jar -jar selenium-server-standalone-2.20.0.jar -role hub
Then start the node like this:
然后像这样启动节点:
java -jar lib/selenium-server-standalone-2.20.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver=lib\chromedriver.exe
more specifically: You have to start up the NODE with parameter browser
and add -D
parameter specifying the full path to the chromedriver
更具体地说:您必须使用参数启动 NODEbrowser
并添加-D
指定 chromedriver 完整路径的参数
My huge thanks goes to John Naegle who answered similar question here on SO regarding the internet explorer - see here
我非常感谢 John Naegle,他在 SO 上回答了关于 Internet Explorer 的类似问题 - 见这里
回答by Ajith Moni
I tried various combinations and finally found that the property needs be set at runtime.
尝试了各种组合,最后发现需要在运行时设置属性。
To Start the node use : This will work for firefox
启动节点使用:这适用于 Firefox
java -jar sel2.40.jar -role node -hub http://locahost:4443/grid/register -port 5556
To Start the node for IE, we need to specify the webdriver.ie.driver system property while starting the node :
要为 IE 启动节点,我们需要在启动节点时指定 webdriver.ie.driver 系统属性:
java -Dwebdriver.ie.driver="D:\IEDriverServer.exe" -jar sel2.40.jar -role node -hub http://locahost:4443/grid/register -port 5556