未知错误: Chrome 启动失败: 异常退出(驱动程序信息: chromeDriver = 2.9

我试图在 Debian7上运行 Selenium 测试,但是没有成功。

错误是:

unknown error: Chrome failed to start: exited abnormally   (Driver info: chromedriver=2.9.248316,platform=Linux 3.2.0-4-686-pae x86) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.55 seconds Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17' System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.2.0-4-686-pae', java.version: '1.7.0_25' Driver info: org.openqa.selenium.chrome.ChromeDriver

我有 29铬34.01847.76测试版运行在 Debian 732位。我正在使用 Selenium-java 2.33.0

链接之后,29铬34的正确版本。无论如何,以前的版本不能在 Debian 7上工作,因为 glibc 版本..。

----------ChromeDriver v2.9 (2014-01-31)----------
Supports Chrome v31-34

[更新1]

我尝试了 爪哇7Java 6,仍然是同样的问题

[更新2]

我使用这个命令来测试 chrome 驱动程序,以确保这不是 Jenkins 的问题:

curl -X POST -H "Content-Type: application/json; charset=utf-8" -d "{\"desiredCapabilities\":{\"platform\":\"ANY\",\"browserName\":\"chrome\",\"chromeOptions\":{\"args\":[],\"extensions\":[]},\"version\":\"\",\"chrome.switches\":[]}}" localhost:12495/session

我收到了同样的错误消息:

{"sessionId":"210f3f837a798ee68cd91f089976d0c2","status":13,"value":{"message":"unknown error: Chrome failed to start: exited abnormally\n  (Driver info: chromedriver=2.9.248316,platform=Linux 3.2.0-4-686-pae x86)"}}

如果你能帮我弄清楚发生了什么,我将不胜感激。

谢谢

139368 次浏览

Are you passing the DISPLAY parameter to your Jenkins job?

I assume you are trying to execute the tests in headless mode, too. So setup some x service (i.e. Xvfb) and pass the DISPLAY number to your job. Worked for me.

I finally managed to get Selenium tests starting the Chrome Driver on my laptop (server).

The important bit is to use Xvfb. Don't ask me why but once you accept this fact follow these steps (more detailed than @Anon answer)

  • In you Jenkins settings add a global property

    key : DISPLAY
    value:0:0
    
  • On your server start Xvfb in the background:

     Xvfb :0 -ac -screen 0 1024x768x24 &
    

Passing no-sandbox to exec seems important for jenkins on windows in foreground or as service. Here's my solution

chromedriver fails on windows jenkins slave running in foreground

I was trying to run selenium on Jenkins with Mocha framework using wdio. So following are the steps to solve this issue:-

Install google chrome

sudo apt-get update


sudo apt-get install google-chrome-stable

Install chrome-driver

wget http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux64.zip
unzip chromedriver_linux64.zip

Run following commands to start selenium web server

nohup sudo Xvfb :10 -ac
export DISPLAY=:10
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.chrome.bin="/usr/bin/google-chrome" -Dwebdriver.chrome.driver="vendor/bin/chromedriver"

After this start you tests with wdio command

wdio wdio.conf.js

We had the same issue while trying to launch Selenium tests from Jenkins. I had selected the 'Start Xvfb before the build, and shut it down after' box and passed in the necessary screen options, but I was still getting this error.

It finally worked when we passed in the following commands in the Execute Shell box.

Xvfb :99 -ac -screen 0 1280x1024x24 & nice -n 10 x11vnc 2>&1 & ... killall Xvfb

Exporting the DISPLAY variable is definitely the solution but depending on your setup you may have to do this in a slightly different way.

In my case, I have two different processes: the first one starts Xvfb, the other one launches the tests. So my shell scripting knowledge is a bit rusty but I figured out that exporting the DISPLAY variable from the first process didn't make it available in the second process.

Fortunately, Selenium WebDriver allows you to 'redefine' your environment. This is my function for creating a driver for Chrome in JS. Pretty sure the equivalent exists for your programming language:

const caps = require('selenium-webdriver/lib/capabilities');
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');


module.exports = function (cfg) {
let serviceBuilder = new chrome.ServiceBuilder(chromedriver.path);
let options = chrome.Options.fromCapabilities(caps.Capabilities.chrome());
let service;
let myENV = new Map();


// 're-export' the `DISPLAY` variable
myENV.set('DISPLAY', ':1');
serviceBuilder.setEnvironment(myENV);


service = serviceBuilder.build();


options.addArguments('disable-setuid-sandbox');
options.addArguments('no-sandbox');
options.addArguments('allow-insecure-localhost');
options.excludeSwitches('test-type');


return chrome.Driver.createSession(options, service);
};

The Mike R's solution works for me. This is the full set of commands:

Xvfb :99 -ac -screen 0 1280x1024x24 &
export DISPLAY=:99
nice -n 10 x11vnc 2>&1 &

Later you can run google-chrome:

google-chrome --no-sandbox &

Or start google chrome via selenium driver (for example):

ng e2e --serve true --port 4200 --watch true

Protractor.conf file:

capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['no-sandbox']
}
},

I had simillar issue with maven tests on x86 linux which i was using in terminal. I was logging in to linux by ssh. I started my java selenium tests by

mvn -DargLine="-Dbaseurl=http://http://127.0.0.1:8080/web/" install

Excepting my app, after running these tests I received error in logs:

unknown error: Chrome failed to start: exited abnormally

I was running these tests as root user. Before this error i received that ChromeDriver is nor present. I moved forward with this by installing ChromeDriver binary and adding it to PATH. But then i had to install google-chrome browser - ChromeDriver alone isn't enough to run tests. So the mistake is problem maybe with screen buffer in terminal window, but You can install Xvfb which is virtual screen buffer. What is important, that you should run your tests not as root, because you may receive another Chrome Browser error. So no as root i run:

export DISPLAY=:99
Xvfb :99 -ac -screen 0 1280x1024x24 &

What is important here, that in my case the number related to DISPLAY ought to be same as Xvfb :NN parameter. 99 in that case. I had another problem because i ran Xvfb with another DISPLAY value and I wanted it to stop. In order to restart Xvfb:

ps -aux | grep Xvfb
kill -9 PID
sudo rm /tmp/.X11-unix/X99

So find a process PID with grep. Kill Xvfb process. And then there is lock in /tmp/.X11-unix/XNN , so delete this lock and you can start server again. If You run not as root, set simillar displays, install google-chrome then with maven you can start selenium tests. My tests went fine with these rules and operations.

I am running a similar setup: Selenium 3.40, Chrome 61, chromedriver 2.33 running with xvfb on ubuntu 16.04.

I was getting the same Chrome error intermittently. It seems that sometimes, the chromedriver fails to cleanup the temp files associated with the Chrome profile.

A workaround for me is to cleanup the temp files before running tests:

rm -rf /tmp/.org.chromium.Chromium*

I expect this will be resolved in future versions of chromedriver, but for now this solves the problem in my case.

I've been fighting with this issue for a long time, and just y'day I figure out how to make it gone and today I can run a 50 threads process calling selenium without seen this issue anymore and also stop crashing my machine with outofmemory issue with too many open chromedriver processes.

  1. I am using selenium 3.7.1, chromedrive 2.33, java.version: '1.8.0', redhat ver '3.10.0-693.5.2.el7.x86_64', chrome browser version: 60.0.3112.90;
  2. running an open session with screen, to be sure my session never dies,
  3. running Xvfb : nohup Xvfb -ac :15 -screen 0 1280x1024x16 &
  4. export DISPLAY:15 from .bashsh/.profile

these 4 items are the basic setting everyone would already know, now comes the code, where all made a lot of difference to achieve the success:

public class HttpWebClient {
public static ChromeDriverService service;
public ThreadLocal<WebDriver> threadWebDriver = new ThreadLocal<WebDriver>(){
@Override
protected WebDriver initialValue() {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("permissions.default.stylesheet", 2);
profile.setPreference("permissions.default.image", 2);
profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
WebDriver driver = new FirefoxDriver(profile);
return driver;
};
};


public HttpWebClient(){
// fix for headless systems:
// start service first, this will create an instance at system and every time you call the
// browser will be used
// be sure you start the service only if there are no alive instances, that will prevent you to have
// multiples chromedrive instances causing it to crash
try{
if (service==null){
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(conf.get("webdriver.chrome.driver"))) // set the chromedriver path at your system
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY", ":15"))
.withSilent(true)
.build();
service.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


// my Configuration class is for good and easy setting, you can replace it by using values instead.
public WebDriver getDriverForPage(String url, Configuration conf) {
WebDriver driver = null;
DesiredCapabilities capabilities = null;
long pageLoadWait = conf.getLong("page.load.delay", 60);


try {
System.setProperty("webdriver.chrome.driver", conf.get("webdriver.chrome.driver"));
String driverType = conf.get("selenium.driver", "chrome");


capabilities = DesiredCapabilities.chrome();
String[] options = new String[] { "--start-maximized", "--headless" };
capabilities.setCapability("chrome.switches", options);


// here is where your chromedriver will call the browser
// I used to call the class ChromeDriver directly, which was causing too much problems
// when you have multiple calls
driver = new RemoteWebDriver(service.getUrl(), capabilities);


driver.manage().timeouts().pageLoadTimeout(pageLoadWait, TimeUnit.SECONDS);
driver.get(url);


// never look back


} catch (Exception e) {
if (e instanceof TimeoutException) {
LOG.debug("Crawling URL : "+url);
LOG.debug("Selenium WebDriver: Timeout Exception: Capturing whatever loaded so far...");
return driver;
}
cleanUpDriver(driver);
throw new RuntimeException(e);
}
return driver;
}


public void cleanUpDriver(WebDriver driver) {
if (driver != null) {
try {
// be sure to close every driver you opened
driver.close();
driver.quit();
//service.stop(); do not stop the service, bcz it is needed
TemporaryFilesystem.getDefaultTmpFS().deleteTemporaryFiles();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

}

Good luck and I hope you don't see that crash issue anymore

Please comment your success

Best regards,

Not sure if this is stopping everyone else, but I resolved this by upgrading chromedriver and then ensuring that it was in a place that my user could read from (it seems like a lot of people encountering this are seeing it for permission reasons like me).

On Ubuntu 16.04: 1. Download chromedriver (version 2.37 for me) 2. Unzip the file 3. Install it somewhere sensible (I chose /usr/local/bin/chromedriver)

Doesn't even need to be owned by my user as long as it's globally executable (sudo chmod +x /usr/local/bin/chromedriver)

I increase max memory to start node-chrome with -Xmx3g, and it's work for me

You don't need Xvfb

It is failing to start due to a mismatch between the chrome version and the chromedriver version. Downloading and installing the same versions or latest versions would solve the issue.

  1. Check that you use ChromeDriver version that corresponds to your Chrome version
  2. In case you are on Linux without graphical interface "headless" mode must be used

Example of WebDriverSettings.java :

...
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--no-sandbox");
options.addArguments("--headless"); //!!!should be enabled for Jenkins
options.addArguments("--disable-dev-shm-usage"); //!!!should be enabled for Jenkins
options.addArguments("--window-size=1920x1080"); //!!!should be enabled for Jenkins
driver = new ChromeDriver(options);
...

In Linux adding these lines to my code helped me.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options




chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=chrome_options)


driver.get("www.counterviews.online")

In my Ubuntu server, following solve the issue

Xvfb :11 -ac -screen 0 1024x768x24 &
export DISPLAY=:11


python selenium_test.py


killall Xvfb

dont use the last line if you have multiple Xvfb process are running at the same time.