部署(硒)时的Chromedriver按时出现



我在部署应用程序时很难启动Chromedriver的Selenium。它是bluemix上的WebSphere应用程序服务器的自由应用程序。

使用测试驱动程序以及我的本地实例,该应用程序正常工作。在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对象创建线上丢弃。

此错误消息...

[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

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

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

解决方案

更改System.setProperty()线如下:

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");

看来您在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();

相关内容

  • 没有找到相关文章

最新更新