org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:异常退出

时间:2015-06-01 13:06:17

标签: google-chrome selenium rhel7

我想在Linux平台上托管的Chrome浏览器(Red Hat Enterprise Linux Server 7.0版(Maipo))上进行回归测试。以下样本测试创建:

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

当我尝试在Linux上使用Chrome(版本43.0.2357.81(64位))作为浏览器运行此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)

在运行测试之前,我执行了以下操作:

  1. Chrome rpm已从以下链接下载。 &#34; https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm&#34;

  2. 使用了chromedriver(2.14.313457):http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip

  3. 安装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 个答案:

答案 0 :(得分:0)

我非常确定这是由于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");