异常螺纹"主" org.openqa.selenium.remote.UnreachableBrowserException:无法启动一个新的会话,当使用appium [英] Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session, When using appium

查看:2179
本文介绍了异常螺纹"主" org.openqa.selenium.remote.UnreachableBrowserException:无法启动一个新的会话,当使用appium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

得到一个错误始终运行code,对于它是我的机器上运行Appium服务器时。谁能帮我从这。我曾跟随某些线程但没有人解决不了我的问题。

如果我手动运行appium.exe&放大器;运行code工作正常,但是当我开始运行从code和appium;相互作用是给有问题。

配置:Windows 7的64位,Appium 1.2.4.1,硒2.45,Appium Java客户端 - 2.2,JAVA 1.6

下面是code推出Appium服务器编程

 公共类AppiumServerUtils {    公共无效startserver的(){      的CommandLine命令=新的CommandLine(CMD);
      command.addArgument(/ C);
      command.addArgument(F:\\\\软件\\\\硒\\\\ Appium \\\\ AppiumForWindows-1.2.4.1 \\\\ Appium \\\\ node.exe);
      command.addArgument(\"F:\\\\Softwares\\\\Selenium\\\\Appium\\\\AppiumForWindows-1.2.4.1\\\\Appium\\\
ode_modules\\\\appium\\\\bin\\\\appium.js\");
      command.addArgument( - 地址);
      command.addArgument(127.0.0.1,FALSE);
      command.addArgument( - 口,FALSE);
      command.addArgument(4723,FALSE);
      command.addArgument( - 引导端口,FALSE);
      command.addArgument(4724,FALSE);
      command.addArgument( - selendroid端口,FALSE);
      command.addArgument(8082,FALSE);
      command.addArgument( - 没有复位,FALSE);
      command.addArgument( - 本地时区);
      command.addArgument( - 日志);
      command.addArgument(F:\\\\软件\\\\硒\\\\ Appium \\\\ appiumServerLogs.txt);
      DefaultExecuteResultHandler resultHandler =新DefaultExecuteResultHandler();
      DefaultExecutor执行人=新DefaultExecutor();
      executor.setExitValue(1);      尝试{
       executor.execute(指挥,resultHandler);
      }赶上(IOException异常五){
       e.printStackTrace();
      }
     }     公共无效stopServer(){      的CommandLine命令=新的CommandLine(CMD);
      command.addArgument(/ C);
      command.addArgument(TASKKILL);
      command.addArgument(/ F);
      command.addArgument(/ IM);
      command.addArgument(node.exe);      DefaultExecuteResultHandler resultHandler =新DefaultExecuteResultHandler();
      DefaultExecutor执行人=新DefaultExecutor();
      executor.setExitValue(1);      尝试{
        executor.execute(指挥,resultHandler);
      }赶上(IOException异常五){
        e.printStackTrace();
      }
     }

}

我的移动脚本,

 静态AndroidDriver驱动程序;    AppiumServerUtils Aserver的=新AppiumServerUtils();
    aServer.startServer();DesiredCapabilities mDesiredCapabilities =新DesiredCapabilities();
    mDesiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,机器人);
    mDesiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME的Nexus S);
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_PACKAGEcom.android.vod);
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_ACTIVITYcom.android.vod.launcher.Main);
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_WAIT_ACTIVITYcom.android.vod.tools.remotecontrol.dialogs.Authentication);
    mDesiredCapabilities.setCapability(MobileCapabilityType.VERSION,4.3);    司机=新AndroidDriver(新URL(http://127.0.0.1:4723/wd/hub),mDesiredCapabilities);
androidDriver.manage()超时()implicitlyWait(40 TimeUnit.SECONDS)。
androidDriver.hideKeyboard();
driver.close();

获取以下例外情况,


  

异常线程mainorg.openqa.selenium.remote.UnreachableBrowserException:无法启动新的会话。可能的原因是远程服务器或浏览器启动失败的无效地址。
      构建信息:版本:2.45.0,修订版:'5017cb8,时间:2015年2月26日23点59分五十秒
      系统信息:主持人:Saravanan-PC,IP:192.168.101.22,os.name:Windows 7的,os.arch:'86',os.version:'6.1',java.version:1.6 .0_45
      驱动方式:driver.version:AndroidDriver
          在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
          在io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
          在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
          在org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java:126)
          在org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java:153)
          在io.appium.java_client.AppiumDriver(AppiumDriver.java:109)
          在io.appium.java_client.android.AndroidDriver(AndroidDriver.java:40)
          在com.helloappium.HelloAppium.main(HelloAppium.java:48)
      org.apache.http.conn.HttpHostConnectException:引起连接到127.0.0.1:4723 [/127.0.0.1]失败:连接被拒绝:连接
          在org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:142)
          在org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:319)
          在org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
          在org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
          在org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
          在org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
          在org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
          在org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
          在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
          在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
          在org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:126)
          在org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:72)
          在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:133)
          在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
          ... 7个
      java.net.ConnectException:产生的原因拒绝连接:连接
          在java.net.PlainSocketImpl.socketConnect(本机方法)
          在java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
          在java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
          在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
          在java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
          在java.net.Socket.connect(Socket.java:529)
          在org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
          在org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:125)
          ... 20更多
      [36minfo [39米:欢迎Appium V1.2.4(REV 71584425ecf777349e3215f0f18e71e7782acfb6)
      [36minfo [39米:Appium REST HTTP接口监听器开始127.0.0.1:4723
      [36minfo [39米:[调试]非默认的服务器ARGS: {\"address\":\"127.0.0.1\",\"noReset\":true,\"log\":\"F:\\Softwares\\Selenium\\Appium\\appiumServerLogs.txt\",\"localTimezone\":true,\"selendroidPort\":8082}
      [36minfo [39米:控制台的LogLevel:调试
      [36minfo [39米:文件的LogLevel:调试



解决方案

我设法重现该问题。出现该问题的原因appium需要相对较长的时间才能启动。你可以看到,如果复制你建到的命令提示符的命令行并启动它。大约需要30秒,appium做好准备。因此,肮脏的解决方案只是添加视频下载(30000); aServer.startServer(); 在移动脚本。更好的解决方案是等到appium将准备就绪。为此,我认为最好的办法 - 读取输出流,并验证它包含预期的响应

这个简单的code显示了该方法(不响应验证)

  InputStream为=新的InputStream(){
    @覆盖
    公众诠释的read()抛出IOException
        返回0;
    }
};
。executor.getStreamHandler()setProcessOutputStream(是);
尝试{
     executor.execute(指挥,resultHandler);
     的for(int i = 1;我小于10;我++){
         INT NREAD = is.​​read();
         如果(NREAD!= 0)
             打破;
         视频下载(5000);
         }
     }赶上(IOException异常五){
            e.printStackTrace();
     }赶上(InterruptedException的E){
            e.printStackTrace();
     }
}

Getting an error always while running code for Appium server which is running on my machine. Could anyone help me out from this. I had followed some threads but none of them could not resolve my issue.

If i run manually "appium.exe" & run code is working fine but when i start running appium from code & interacting is giving a problem.

Configurations: Windows 7 64 bit, Appium 1.2.4.1, Selenium 2.45, Appium Java client - 2.2, java 1.6

Below is the code to launch Appium server programmatically

public class AppiumServerUtils {

    public  void startServer(){

      CommandLine command = new CommandLine("cmd");
      command.addArgument("/c");
      command.addArgument("F:\\Softwares\\Selenium\\Appium\\AppiumForWindows-1.2.4.1\\Appium\\node.exe");
      command.addArgument("F:\\Softwares\\Selenium\\Appium\\AppiumForWindows-1.2.4.1\\Appium\\node_modules\\appium\\bin\\appium.js");
      command.addArgument("--address");
      command.addArgument("127.0.0.1",false);
      command.addArgument("--port",false);
      command.addArgument("4723",false);
      command.addArgument("--bootstrap-port",false);
      command.addArgument("4724",false);
      command.addArgument("--selendroid-port",false);
      command.addArgument("8082",false); 
      command.addArgument("--no-reset",false);
      command.addArgument("--local-timezone");
      command.addArgument("--log");
      command.addArgument("F:\\Softwares\\Selenium\\Appium\\appiumServerLogs.txt");
      DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
      DefaultExecutor executor = new DefaultExecutor();
      executor.setExitValue(1);

      try {
       executor.execute(command, resultHandler);
      } catch (IOException e) {
       e.printStackTrace();
      }
     }

     public  void stopServer(){

      CommandLine command = new CommandLine("cmd");
      command.addArgument("/c");
      command.addArgument("taskkill");
      command.addArgument("/F");
      command.addArgument("/IM");
      command.addArgument("node.exe");

      DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
      DefaultExecutor executor = new DefaultExecutor();
      executor.setExitValue(1);

      try {
        executor.execute(command, resultHandler);
      } catch (IOException e) {
        e.printStackTrace();
      }


     }

}

My script for mobile is,

static AndroidDriver driver;

    AppiumServerUtils aServer = new AppiumServerUtils();
    aServer.startServer();

DesiredCapabilities mDesiredCapabilities = new DesiredCapabilities();
    mDesiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    mDesiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus S");
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.vod");
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.vod.launcher.Main");
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_WAIT_ACTIVITY, "com.android.vod.tools.remotecontrol.dialogs.Authentication");
    mDesiredCapabilities.setCapability(MobileCapabilityType.VERSION, "4.3");

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), mDesiredCapabilities);
androidDriver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
androidDriver.hideKeyboard();
driver.close();

Getting the following Exceptions,

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50' System info: host: 'Saravanan-PC', ip: '192.168.101.22', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_45' Driver info: driver.version: AndroidDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:40) at com.helloappium.HelloAppium.main(HelloAppium.java:48) Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:319) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:126) at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:72) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:133) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572) ... 7 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72) at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:125) ... 20 more [36minfo[39m: Welcome to Appium v1.2.4 (REV 71584425ecf777349e3215f0f18e71e7782acfb6) [36minfo[39m: Appium REST http interface listener started on 127.0.0.1:4723 [36minfo[39m: [debug] Non-default server args: {"address":"127.0.0.1","noReset":true,"log":"F:\Softwares\Selenium\Appium\appiumServerLogs.txt","localTimezone":true,"selendroidPort":8082} [36minfo[39m: Console LogLevel: debug [36minfo[39m: File LogLevel: debug

解决方案

I managed to reproduce the problem. The problem occurs because for appium takes relatively long time to start. You can see it if copy the command line that you built to the cmd prompt and launch it. It takes about 30 sec for appium to be ready. So the dirty solution is just to add Thread.sleep(30000); after aServer.startServer(); in the mobile script. The better solution is wait until appium will ready. For this purpose I think the best approach - read output stream and verify that it contains the expected response.

This simple code shows this approach (without the response verification)

InputStream is = new InputStream() {
    @Override
    public int read() throws IOException {
        return 0;
    }
};
executor.getStreamHandler().setProcessOutputStream(is);
try {
     executor.execute(command, resultHandler);
     for (int i=1; i<10; i++) {
         int nRead = is.read();
         if(nRead!=0)
             break;
         Thread.sleep(5000);
         }
     }catch (IOException e) {
            e.printStackTrace();
     }catch (InterruptedException e) {
            e.printStackTrace();
     }
}

这篇关于异常螺纹&QUOT;主&QUOT; org.openqa.selenium.remote.UnreachableBrowserException:无法启动一个新的会话,当使用appium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆