使用chromedriver让Win Jenkins奴隶还可以吗?
我的测试从Maven存储库中提取chromedriver和便携式chrome,然后执行它们。在本地和当构建用户在构建系统上执行相同操作时,工作正常。
当jenkins做同样的事情时,即使在前台运行(不是svc),它也会失败,并显示以下错误。我尝试传递参数来提高详细程度无济于事。
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 62.63 seconds Build info: version: ‘2.41.0’, revision: ‘3192d8a6c4449dc285928ba024779344f5423c58’, time: ‘2014-03-27 11:29:39’ System info: host: ‘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’ Driver info: org.openqa.selenium.chrome.ChromeDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240) at org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:181) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:160) at 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;
}
}
我们遇到了几个问题,关键似乎是Chrome的无沙箱选项。以下是在桌面和在前台或通过服务运行的jenkins从站上工作的解决方案。
第一部分:Chrome和驱动程序的Maven解压缩
<plugin>
结果 在测试执行时,我们有target / chromedriver.exe和target / GooglePortable / Google
… exe文件要使用
第二部分:Maven Surefire配置
我们为驱动程序和chrome exe的位置设置系统属性,以传递给所有单元测试
<systemPropertyVariables>
<webdriver.chrome.driver>${project.build.directory}/chromedriver.exe</webdriver.chrome.driver>
<win.google.chrome.bin>${win.chrome.exe}</win.google.chrome.bin>
</systemPropertyVariables>
第三部分:测试代码
我们使用chrome驱动程序服务构建器将详细程度设置为11,然后使用我们最喜欢的功能启动驱动程序
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 {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(getChromeExecutableLocation().getAbsolutePath());
chromeOptions.addArguments("no-sandbox");
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"));
} else {
// Use the standard locator option for all other operating systems
GoogleChromeLocator locator = new GoogleChromeLocator();
BrowserInstallation installation = locator.findBrowserLocationOrFail();
chromeExe = new File(installation.launcherFilePath());
}
System.out.println("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;
}
}
public class WebTest
{
static ChromeDriverService service = null;
static WebDriver driver = null;
@BeforeClass
static public void setupOnce() throws IOException {
// Setup ChromeDriver with Verbosity on - perhaps control via system property - off by default?
service = new ChromeDriverService.Builder()
.withVerbose(true)
.usingAnyFreePort()
.build();
service.start();
// Setup locator to find unpacked Portable chrome exe
ChromeLocator locator = new ChromeLocator();
// Use service + capabilities from locator to open driver with settings and chrome bin
driver = new RemoteWebDriver(service.getUrl(), locator.getCapabilities());
}
@AfterClass
static public void teardownOnce() {
if (null != service) {
service.stop();
service = null;
}
}
@Test
public void testGoogleSearch() throws InterruptedException, IOException {
driver.get("http://www.google.com/xhtml");
assertEquals("Google", driver.getTitle());
WebElement searchBox = driver.findElement(By.name("q"));
String searchString = "ChromeDriver";
searchBox.sendKeys(searchString);
searchBox.submit();
String source = driver.getPageSource().toString();
assertTrue("Expected DOCTYPE in\n" + source,
source.contains("DOCTYPE"));
driver.quit();
service.stop();
}
}
问题内容: 使用chromedriver让Win Jenkins奴隶还可以吗? 我的测试从Maven存储库中提取chromedriver和便携式chrome,然后执行它们。在本地以及当构建用户在构建系统上执行相同操作时,工作正常。 当jenkins做同样的事情时,即使在前台运行(不是svc),它也会失败,并显示以下错误。我尝试传递参数以提高详细程度无济于事。 org.openqa.selenium
问题内容: 我将Selenium与Java(1.8)中的Chromedriver结合使用来进行一些自动的网络爬网: 我正在尝试迁移到Ubuntu 16.04服务器。在服务器上,我安装了Ubuntu chromedriver版本2.37,chrome版本65。根据chromedriver文档,这些版本兼容。我已经更改了指定chromedriver在Ubuntu中的位置的代码: 在运行程序之前,我先启
问题内容: 我在CI和CD上创建了Jenkinsfile,Dockerfile,Dockerfile.test到CI和CD,在GitHub上构建了我的服务器API,我在Jenkins上构建了该构建,并且构建成功,并且我的docker在Jenkinsfile阶段也在容器上运行,我创建了用于测试和部署在服务器API上,并使用docker作为容器 我也使用docker-compose在docker上运行
我在Linux服务器上用chrome驱动程序版本74运行Selenium时遇到了异常(如下)。它在Windows上运行得很好 未知错误:Chrome启动失败:异常退出(未知错误:DevToolsActivePort文件不存在)(从Chrome位置/usr/bin/google-Chrome启动的进程不再运行,因此ChromeDriver假设Chrome已崩溃。) 我可以通过在ChromeOptio
5.12.1. 在Windows下运行多个服务器 5.12.2. 在Unix中运行多个服务器 5.12.3. 在多服务器环境中使用客户端程序 在一些情况下,你可能想要在同一台机器上运行多个mysqld服务器。你可能想要测试一个新的MySQL发布,同时不影响现有产品的设置。或者,你可能想使不同的用户访问来访问不同的mysqld服务器以便他们自己来管理。(例如,你可能是一个Internet服务提供商,
问题内容: 我正在尝试在pyinstaller的可执行文件中添加Chromedriver。虽然这是可能的,但似乎在尝试在另一台计算机上运行此错误消息。 我已经尝试了一些职位,包括本的一个,但不幸的是,这并没有提供预期的效果。最好的情况是,当chrome exe位于同一文件夹中时,我可以在自己的计算机上运行它,这无济于事。 代码1: 主程序 在另一台PC上运行时,我得到的是: 错误1: 找不到Chr