简体   繁体   English

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

[英]AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started

Im trying to start Appium server programmatically from Java (OS: Windows7 x64)我试图从 Java 以编程方式启动 Appium 服务器(操作系统:Windows7 x64)

The code that I use for starting Appium sever is:我用于启动 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();
}

I'm getting an exception :遇到了一个例外

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\"}] 

Process output: C:\\Users[user]\\AppData\\Roaming\\npm\\node_modules\\appium\\lib\\appium.js:1 (function (exports, require, module, __filename, __dirname) { import _ from 'lodash'; ^^^^^^进程输出:C:\\Users[user]\\AppData\\Roaming\\npm\\node_modules\\appium\\lib\\appium.js:1 (function (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

I tried every way to start Appium server from the source, but second one causes to the same, but third causes to error我尝试了从源代码启动 Appium 服务器的所有方法,但第二个导致相同,但第三个导致错误在此处输入图片说明

Any ideas?有任何想法吗? Thanks to all in advance!提前感谢大家!

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

Make sure your env setup for Appium is correct and that appium service/client versions are compatible. 确保您的Appium的环境设置正确,并且appium服务/客户端版本兼容。

It did mistake in code. 它确实在代码中出错。 Fixed method is: 固定方法是:

     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();
}
public class ServerManager {
    AppiumDriverLocalService service;
    public static void main(String args[]) {
        ServerManager sm = new ServerManager();
        sm.startServer();
        
    }
    public void startServer() {
        final DesiredCapabilities cap = new DesiredCapabilities();
        //Set Capabilities
        
        cap.setCapability("noReset", "false");

        //Build the Appium service
        AppiumServiceBuilder builder = new AppiumServiceBuilder();
        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");

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

    public void stopServer() {
        service.stop();
    }

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 启动后如何更改Spring Boot服务器的时间 - How to change the Spring boot server time after it has been started 如果由AppiumServiceBuilder启动appium服务器,如何启用--no-reset - How to enable --no-reset if appium server is started by AppiumServiceBuilder 以编程方式启动appium服务器时,iOS应用不会启动 - iOS app wont launch when appium server is started programmatically Appium“ HasClipboard()”的“方法尚未实现”异常 - “Method has not yet been implemented” exception for appium `HasClipboard()` Appium IOS 测试在手动启动服务器时运行,但在通过 AppiumDriverLocalService 启动服务器时不运行 - Appium IOS tests running when server started manually but not when server is started via AppiumDriverLocalService 局部变量尚未初始化? - local variable has not been initialized? 连接到服务器,但服务器尚未启动Java - connecting to server but server has not started java 警告:活动尚未开始,其当前任务已被置于最前面 - Warning: Activity not started , its current task has been brought to the front 如何检查FirebaseFirestore是否已在Android中启动? - How to check if FirebaseFirestore has already been started in Android? 由IllegalStateException引起的Hibernate InstantiationException:此Web容器尚未启动 - Hibernate InstantiationException caused by IllegalStateException: This web container has not yet been started
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM