问题描述
得到一个错误始终运行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();
获取以下例外情况,
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!