我想在 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();
}
}
}
当我尝试在 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)
在运行测试之前,我做了以下事情:
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