【发布时间】:2018-10-07 22:49:28
【问题描述】:
所以我使用下面的代码尝试自动启动 Appium 服务器,但连接被拒绝:连接错误。 我正在使用带有 Testng 的 Maven
日志:
配置失败:@BeforeTest 功能 org.openqa.selenium.WebDriverException:连接被拒绝:连接 构建信息:版本:'3.10.0',修订:'176b4a9',时间:'2018-03-02T19:03:16.397Z' 系统信息:主机:'MEL01-ULPT027',ip:'172.24.80.1',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'1.8 .0_152' 驱动信息:driver.version:AndroidDriver 在 io.appium.java_client.remote.AppiumCommandExecutor.lambda$2(AppiumCommandExecutor.java:141) 在 java.util.Optional.orElseGet(未知来源) 在 io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:140) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) 在 io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) 在 io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) 在 io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) 在 io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
代码:
public class Startup {
RemoteWebDriver driver = null;
public void startAppiumServer() throws IOException, InterruptedException {
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("C:\\Program Files (x86)\\Appium\\node.exe");
command.addArgument("C:\\Program Files (x86)\\Appium\\node_modules\\appium\\lib\\appium.js");
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");
command.addArgument("--full-reset", false);
command.addArgument("--bootstrap-port",false);
command.addArgument("4724",false);
command.addArgument("--selendroid-port",false);
command.addArgument("8082",false);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
// executor.setExitValue(1);
InputStream is = new InputStream() {
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();
}
}
【问题讨论】:
-
几点建议:不要用appium.js,用main.js。为什么要使用最后四个参数?此外,您可能希望使用 0.0.0.0 而不是 127.0.0.1
-
谢谢,刚刚改变了启动appium的方式。现在我正在创建一个 bat 文件并使用 Java Runtime 命令启动 appium 服务器。然而另一方面,现在我正在努力以编程方式关闭 appium 服务器的代码。有什么建议吗?