- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有什么技巧可以让 Win Jenkins 从机与 chromedriver 兼容?
我的测试从 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 & Driver 的 Maven 解压
设置要解压的 maven-dependency-plugin 执行
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>extract portable google chrome</id>
<phase>process-test-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<skip>${skipWinChromeUnpack}</skip>
<markersDirectory>${project.build.directory}/dependency-maven-plugin-markers/googlechrome</markersDirectory>
<overWriteIfNewer>false</overWriteIfNewer>
<artifactItems>
<artifactItem>
<groupId>com.google.chromium</groupId>
<artifactId>chromedriver</artifactId>
<version>${win.chromedriver.version}</version>
<classifier>win32</classifier>
<type>zip</type>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>com.portableapps</groupId>
<artifactId>googlechrome</artifactId>
<version>${win.chrome.version}</version>
<classifier>win64</classifier>
<type>zip</type>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
结果在测试执行时,我们有 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();
}
}
关于java - chromedriver 在前台运行的 windows jenkins 从设备上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38963784/
昨天我更新了我的旧 chromedriver(v2.0.204324.dyu) 并在 https://code.google.com/p/chromedriver/downloads/list 上传了
我在使用 Selenium WebDriver.chromedriver 获取 json 结果数据时遇到问题,服务器将响应 http 状态代码 429 太多请求。 但是当我直接使用 chrome 获取
所以我在 stack here 上看到了一个类似的问题,但它没有被接受的答案,也没有为我提供我需要的信息。 我正在尝试使用“chromedriver”,因为“selenium-webdriver”需要
嗨,在 headless centos 7 中,我正在尝试进行 headless selenium 测试。为此,我安装了 google-chrome、chromedriver 和 selenium p
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我的问题与这篇文章有关:session not created: This version of ChromeDriver only supports Chrome version 74 error
我们试图在 Jenkins 上添加一些 selenium 脚本,但每当我们发出命令时,我都会收到错误消息“Chromedriver.exe 已停止工作”。 我将 chromedriver 移动到另一个
我使用的是 Macbook Pro,并且使用 Selenium 2.46.0 for Java 和 Chromedriver。我只有一个main方法,如下: public static void ma
我正在尝试在 heroku 上设置 selenium。我一直在看Running ChromeDriver with Python selenium on Heroku寻求帮助。基于此,我安装了列出的
当我设置初始设置 Nightwatchjs(使用初学者教程)时,出现如下错误: 尝试启动 ChromeDriver 时出错:无法解析路径:“/node_modules/.bin/chromedrive
我在 Windows 7 上使用 Selenium Chromedriver 时遇到问题。为了显示该问题,我将其简化为一个简单的脚本来简单地启动《纽约时报》网站: from selenium impo
问题 我一直在使用 Selenium 编写 Python 脚本,它在本地运行良好(因为我已将 ChromeDriver 安装在正确的目录中,即 assets/chromedriver),但它无法在赫罗
WebDriver driver = new ChromeDriver(options); 显示构造函数 ChromeDriver(ChromeOptions) 未定义,为什么? 最佳答案 导入以下语
我安装了 nuget 包 - Selenium.WebDriver.ChromeDriver 2.46.0.. 当我发布(通过 dotnet publish .Net CLI 命令).csprojec
我想用 chromedriver 从 fanfiction.net 上抓取一些故事。 我尝试以下方法: from selenium import webdriver import time path
当我尝试运行 npm install chromedriver 我得到... ChromeDriver installation failed Error extracting archive: Er
只是一个简单的 Python 代码: from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_
使用 C# 在 selenium 中哪里可以找到 chromedriver.log。在哪里可以看到chromedriver的日志文件? ChromeOptions optn= new ChromeOp
我在 Linux 上使用 Node 5.10.0。运行脚本时出现一些问题,如下所示 [davea@mydevbox mydir]$ node SkyNet.js Validation Complete
我是一名优秀的程序员,十分优秀!