简体   繁体   English

Java Selenium和Appium无法正常工作无法启动REST http接口侦听器

[英]Java Selenium and Appium doesn't work Could not start REST http interface listener

I using Java, selenium and appium for automation testing web application on android 我使用Java,selenium和appium在android上自动测试web应用程序

I use this code: 我用这个代码:

        service = AppiumDriverLocalService.buildDefaultService();
        service.start();
        if (service == null || !service.isRunning())
            throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");
        DesiredCapabilities capabilitiesAndroid = new DesiredCapabilities();
        capabilitiesAndroid.setCapability("deviceName", "Android Emulator");
        capabilitiesAndroid.setCapability("deviceOrientation", "portrait");
        capabilitiesAndroid.setCapability("platformVersion", "8.0.0");
        capabilitiesAndroid.setCapability("platformName", "Android");
        capabilitiesAndroid.setCapability("browserName", "Chrome");
        driver = new AndroidDriver<WebElement>(capabilitiesAndroid);

With the same parameter I can open new session in appium. 使用相同的参数,我可以在appium中打开新的会话。 In Java I got 2 times this error: 在Java中我得到了2次这个错误:

[Appium] Welcome to Appium v1.6.5
[HTTP] Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.

Error: listen EADDRINUSE 0.0.0.0:4723
    at Object._errnoException (util.js:1041:11)
    at _exceptionWithHostPort (util.js:1064:20)
    at Server.setupListenHandle [as _listen2] (net.js:1322:14)
    at listenInCluster (net.js:1370:12)
    at doListen (net.js:1492:7)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

I haven't started process node.exe. 我还没有启动进程node.exe。 Anyone know why it doesn't work? 任何人都知道它为什么不起作用?

You can not use the same port to initialize one more instance. 您不能使用相同的端口初始化另一个实例。 You can initialize with different port. 您可以使用不同的端口进行初始化。 Your code tries to initialize the instance with same port number every time. 您的代码每次尝试使用相同的端口号初始化实例。 You can use the below code to solve the issue. 您可以使用以下代码来解决问题。

 service = AppiumDriverLocalService.buildService( new
      AppiumServiceBuilder().usingDriverExecutable(new File(
      "C:\\Program Files\\nodejs\\node.exe")) .withAppiumJS(new File(
      "C:\Users\YourUserName\AppData\Roaming\npm\node_modules\appium\build\lib\main.js"
      )) .withIPAddress("127.0.0.1").usingAnyFreePort());

     service.start();

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM