org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally

笑着哭i 提交于 2021-01-27 04:47:54

问题


I wanted to carry out the run for my regression tests on Chrome browser hosted on the Linux platform (Red Hat Enterprise Linux Server release 7.0 (Maipo)). Following sample test was created for the same:

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();
    }
}
}

When I try running this selenium test using Chrome (version- 43.0.2357.81 (64-bit)) as browser on Linux it fails following exception.

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)

Before running the tests I did the following:

  1. Chrome rpm was downloaded form the below link. "https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm".

  2. Following chromedriver used (2.14.313457): http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip

After installing chrome, the sample test was ran.

chromedriver logs are as below :

[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:


I am pretty sure it is because of version mismatch between google chrome and chromedriver. The links given in the question suggest that you are using chromedriver 2.14 and current stable version of google chrome. ChromeDriver 2.14 supports google chrome versions from v39-42 (See http://chromedriver.storage.googleapis.com/2.14/notes.txt). User newer version of chromedriver according to the google chrome version you are using. Refer http://chromedriver.chromium.org/downloads for the correct version of chromedriver.

Although it is not related to this question, but you don't need to start and stop chromeDriverService manually unless you have some specific requirement. it will be sufficient to use following code:

System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
WebDriver driver = new ChromeDriver();              
driver.get("http://www.google.com");


来源:https://stackoverflow.com/questions/30574334/org-openqa-selenium-webdriverexception-unknown-error-chrome-failed-to-start-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!