AppiumServerHasNotBeenStartedLocallyException:尚未启动本地appium服务器

时间:2018-04-02 11:36:09

标签: java node.js appium

我试图以编程方式从Java中启动Appium服务器 (操作系统:Windows7 x64)

我用于启动Appium服务器的代码是:

  public void startServer() {
    //Set Capabilities
    cap = new DesiredCapabilities();
    cap.setCapability("noReset", "false");

    //Build the Appium service
    builder = new AppiumServiceBuilder();
    builder.withIPAddress("127.0.0.1");
    builder.usingPort(4723);
    builder.withCapabilities(cap);
    builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
    builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");

    //added by myself:
    builder.usingDriverExecutable(new File("C:/node/node.exe"));
    builder.withAppiumJS(new File("C:/Users/[user]/AppData/Roaming/npm/node_modules/appium/lib/appium.js"));


    //Start the server with the builder
    service = AppiumDriverLocalService.buildService(builder);
    service.start();
}

得到例外

Exception in thread "main" io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: C:\node\node.exe Arguments: [C:\Users\Dima\AppData\Roaming\npm\node_modules\appium\lib\appium.js, --port, 4723, --address, 127.0.0.1, --log-level, error, --session-override, --default-capabilities, {\"noReset\": \"false\"}] 

流程输出:C:\ Users [user] \ AppData \ Roaming \ npm \ node_modules \ appium \ lib \ appium.js:1 (函数(exports,require,module,__ filename,__ dirname){import _ from'lodash'; ^^^^^^

SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

我尝试了从源头启动Appium服务器的各种方法,但第二个导致相同,但第三个导致错误enter image description here

有什么想法吗?提前全部感谢!

2 个答案:

答案 0 :(得分:0)

查看官方文档: https://github.com/appium/java-client/blob/master/docs/The-starting-of-an-app-using-Appium-node-server-started-programmatically.md

确保您的Appium的env设置正确且appium服务/客户端版本兼容。

答案 1 :(得分:0)

它在代码中犯了错误。固定方法是:

     public static String runAppiumService(int appiumPort) {

        //Build parameters for appium server:
        AppiumServiceBuilder appiumServiceBuilder = new AppiumServiceBuilder();
        appiumServiceBuilder.usingPort(appiumPort)
                .withIPAddress(APPIUM_IP)
                .withAppiumJS(new File(getAppiumJsPath()))
                .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                .withLogFile(new File(System.getProperty("user.dir") + "/target/resources/appium_server_logs" + Thread.currentThread().getId()));
        AppiumDriverLocalService service = AppiumDriverLocalService.buildService(appiumServiceBuilder);
        service.start();
}