org.openqa.selenium.WebDriverException:未知错误:Chrome 启动失败:异常退出
Posted
技术标签:
【中文标题】org.openqa.selenium.WebDriverException:未知错误:Chrome 启动失败:异常退出【英文标题】:org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally 【发布时间】:2015-08-14 23:05:11 【问题描述】:我想在 Linux 平台(Red Hat Enterprise Linux Server 版本 7.0 (Maipo))上托管的 Chrome 浏览器上运行我的回归测试。为相同创建了以下示例测试:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.File;
import java.io.IOException;
public class ChromeTest
private static ChromeDriverService service;
public static void createAndStartService() throws IOException
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("/<pathToChromeDrive>/chromedriver"))
.withLogFile(new File("/<pathToChromeDriveLogs>/chromedriver.log"))
.usingAnyFreePort()
.build();
service.start();
public static void createAndStopService()
service.stop();
public static void main(String[] args)
WebDriver driver;
try
createAndStartService();
driver = new RemoteWebDriver(service.getUrl(),
DesiredCapabilities.chrome());
driver.get("http://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("webdriver");
driver.quit();
createAndStopService();
catch (IOException e)
e.printStackTrace();
当我尝试使用 Chrome(版本 - 43.0.2357.81(64 位))作为 Linux 上的浏览器运行此 selenium 测试时,它会因异常而失败。
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 3039Only local connections are allowed.Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Linux 3.8.13-35.3.1.el7uek.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 60.20 secondsBuild info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'System info: host: 'localhost.localdomain', ip: '<>', os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.13-35.3.1.el7uek.x86_64', java.version: '1.8.0_25'Driver info: org.openqa.selenium.remote.RemoteWebDriver
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:408)
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:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at ChromeTest.main(ChromeTest.java:36)
在运行测试之前,我做了以下工作:
Chrome rpm 是从以下链接下载的。 “https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm”。
使用以下 chromedriver (2.14.313457):http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip
安装chrome后,运行示例测试。
chromedriver日志如下:
[0.398][INFO]: COMMAND InitSession
"desiredCapabilities":
"browserName": "chrome",
"platform": "ANY",
"version": ""
[0.399][INFO]: Populating Preferences file:
"alternate_error_pages":
"enabled": false
,
"autofill":
"enabled": false
,
"browser":
"check_default_browser": false
,
"distribution":
"import_bookmarks": false,
"import_history": false,
"import_search_engine": false,
"make_chrome_default_for_user": false,
"show_welcome_page": false,
"skip_first_run_ui": true
,
"dns_prefetching":
"enabled": false
,
"profile":
"content_settings":
"pattern_pairs":
"https://*,*":
"media-stream":
"audio": "Default",
"video": "Default"
,
"default_content_settings":
"geolocation": 1,
"mouselock": 1,
"notifications": 1,
"popups": 1,
"ppapi-broker": 1
,
"password_manager_enabled": false
,
"safebrowsing":
"enabled": false
,
"search":
"suggest_enabled": false
,
"translate":
"enabled": false
[0.400][INFO]: Populating Local State file:
"background_mode":
"enabled": false
,
"ssl":
"rev_checking":
"enabled": false
[0.401][INFO]: Launching chrome: /opt/google/chrome --disable-background-networking --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-hang-monitor --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --load-extension=/tmp/.com.google.Chrome.69stsm/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12234 --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.5HCrWO data:,
[0.402][WARNING]: PAC support disabled because there is no system implementation
[60.410][INFO]: RESPONSE InitSession unknown error: Chrome failed to start: exited abnormally
【问题讨论】:
【参考方案1】:我很确定这是因为 google chrome 和 chromedriver 之间的版本不匹配。问题中给出的链接表明您正在使用 chromedriver 2.14 和当前稳定版本的 google chrome。 ChromeDriver 2.14 支持从 v39-42 开始的 google chrome 版本(参见 http://chromedriver.storage.googleapis.com/2.14/notes.txt)。根据您使用的 google chrome 版本,使用较新版本的 chromedriver。请参考http://chromedriver.chromium.org/downloads 获取正确版本的chromedriver。
虽然与本题无关,但除非有特定需求,否则无需手动启动和停止 chromeDriverService。使用以下代码就足够了:
System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
【讨论】:
以上是关于org.openqa.selenium.WebDriverException:未知错误:Chrome 启动失败:异常退出的主要内容,如果未能解决你的问题,请参考以下文章