所以我使用下面的代码尝试自动启动Appium服务器,但连接被拒绝:连接错误。 我正在使用 Maven 和 Testng
日志:
FAILED CONFIGURATION: @BeforeTest capabilities org.openqa.selenium.WebDriverException: Connection refused: connect Build info: version: '3.10.0', revision: '176b4a9', time: '2018-03-02T19:03:16.397Z' System info: host: '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 info: driver.version: AndroidDriver at io.appium.java_client.remote.AppiumCommandExecutor.lambda$2(AppiumCommandExecutor.java:141) at java.util.Optional.orElseGet(Unknown Source) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:140) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at 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,您的代码将无法在 Linux 或其他操作系统上运行。这样就使用AppiumDriverLocalService来启动服务器。 您可以找到here启动服务器的有用方法。
关于java - 以编程方式启动 Appium 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50056502/