ChromeDriver部署时超时(Selenium)

时间:2018-04-25 18:54:07

标签: java selenium websphere selenium-chromedriver

部署应用程序时,我无法启动Selenium的ChromeDriver。它是Bluemix上的WebSphere Application Server的Liberty应用程序。

使用测试驱动程序和我本地的WAS实例时,应用程序工作正常。在Bluemix上运行应用程序时,我不断收到错误

Error 500: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z' System info: host: 'ab262009-655a-4b7e-72a8-eb5250d668ac', ip: '10.254.1.142', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-75-generic', java.version: '1.8.0_161' Driver info: driver.version: ChromeDriver

我的日志显示了这两个错误

[err] /home/vcap/app/wlp/usr/servers/projectname/resources/chromedriver: 1: /home/vcap/app/wlp/usr/servers/projectname/resources/chromedriver: Syntax error: Unterminated quoted string
APP/0[ERROR ] org.apache.commons.exec.ExecuteException: Process 
exited with an error: 2 (Exit value: 2)
APP/0org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
APP/0[ERROR ] SRVE0777E: Exception thrown by application class 'org.openqa.selenium.remote.service.DriverService.waitUntilAvailable:192'
APP/0Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:31300/status] to be available after 20018 ms

/home/vcap/app/wlp/usr/servers/projectname/resources/chromedriver: Syntax error: "(" unexpected

源代码:

public static void runTest(String os) throws InterruptedException {

    // Detect Operating System user is running
    System.out.println("Operating system read in: " + os);
    // Initialize driver

    if (os.contains("Mac")) {
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/resources/chromedriver");
    } else {
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/resources/chromedriver_windows.exe");
    }
    WebDriver driver = new ChromeDriver();

ChromeDriver对象创建行上会抛出错误。

2 个答案:

答案 0 :(得分:0)

在创建WebDriver对象之前,您似乎没有设置二进制位置。按照以下更新你的runTest方法,然后试试。

public static void runTest(String os) throws InterruptedException {

    // Detect Operating System user is running
    System.out.println("Operating system read in: " + os);
    // Initialize driver
    String DRIVER_BINARY_LOCATION;
    switch(os.toUpperCase()){

        case "MAC":
            DRIVER_BINARY_LOCATION = System.getProperty("user.dir") + "/resources/chromedriver");
            break;
        case "LINUX":
            DRIVER_BINARY_LOCATION = System.getProperty("user.dir") + "/resources/chromedriver");
            break;
        case "WINDOW":
            DRIVER_BINARY_LOCATION = System.getProperty("user.dir") + "/resources/chromedriver.exe");
            break;
        default:
            throw new IllegalArgumentException("Any meaningful message");
    }
    System.setProperty("webdriver.chrome.driver", DRIVER_BINARY_LOCATION);
    WebDriver driver = new ChromeDriver();

答案 1 :(得分:0)

此错误消息......

System.setProperty()

...表示行System.setProperty()语法错误特别是未终止的引用字符串

您的主要问题在System.setProperty()内, path.separator 如下:

解决方案

更改if (os.contains("Mac")) { String user_dir = System.getProperty("user.dir"); System.setProperty("webdriver.chrome.driver", user_dir+"/resources/chromedriver"); } else { System.setProperty("webdriver.chrome.driver", user_dir+"/resources/chromedriver_windows.exe"); 行,如下所示:

if (os.contains("Mac")) {
    System.setProperty("webdriver.chrome.driver", "./resources/chromedriver");
    } else {
    System.setProperty("webdriver.chrome.driver", "./resources/chromedriver_windows.exe");

更新

由于您仍然看到相同的错误,您可以尝试以下替代方法:

export class DepNodeProvider implements vscode.TreeDataProvider<Dependency> {