【发布时间】:2016-12-22 04:08:26
【问题描述】:
有没有什么技巧可以让 Win Jenkins slave 使用 chromedriver?
我的测试从 maven 存储库中提取 chromedriver 和便携式 chrome,然后执行它们。在我的本地以及当我的构建用户在我的构建系统上执行相同操作时工作正常。
当 jenkins 做同样的事情时,即使在前台(不是 svc)运行时,它也会失败并出现以下错误。我尝试通过参数来提高详细程度,但无济于事。
org.openqa.selenium.WebDriverException:未知错误:Chrome 启动失败:正常退出 (驱动程序信息:chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.1.7601 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:62.63 秒 构建信息:版本:'2.41.0',修订:'3192d8a6c4449dc285928ba024779344f5423c58',时间:'2014-03-27 11:29:39' 系统信息:主机:'winengbld15',ip:'10.2.2.105',os.name:'Windows Server 2008 R2',os.arch:'amd64',os.version:'6.1',java.version:'1.8 .0_40' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:422) 在 org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) 在 org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240) 在 org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:181) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:160) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:128)
我是这样设置 Chrome 驱动的:
defaultPath = "target/drivers/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", defaultPath);
ChromeLocator locator = new ChromeLocator();
driver = new ChromeDriver(locator.getCapabilities());
public class ChromeLocator {
private static final Logger log = Logger.getLogger(ChromeLocator.class);
/**
* Obtain Chrome Configuration with location of binary
* @return
* @throws IOException
*/
public DesiredCapabilities getCapabilities() throws IOException {
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("binary", getChromeExecutableLocation().getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
return capabilities;
}
// Windows defaults to unpacked location
private File getChromeExecutableLocation() throws IOException {
File chromeExe;
if (SystemUtils.IS_OS_WINDOWS) {
chromeExe = new File(System.getProperty("win.google.chrome.bin"));
log.info("*** win.google.chrome.bin: " + System.getProperty("win.google.chrome.bin"));
} else {
// Use the standard locator option for all other operating systems
GoogleChromeLocator locator = new GoogleChromeLocator();
BrowserInstallation installation = locator.findBrowserLocationOrFail();
chromeExe = new File(installation.launcherFilePath());
}
log.info("Chrome Exe: " + chromeExe.getAbsolutePath() + " Is File: " + chromeExe.isFile());
if (! chromeExe.exists() || ! chromeExe.isFile()) {
throw new IOException("Cannot locate Chrome Executable. Expected Location: " + chromeExe.getAbsolutePath());
}
return chromeExe;
}
}
【问题讨论】:
标签: java maven selenium jenkins selenium-chromedriver