繁体   English   中英

以编程方式启动Appium服务器

[英]Starting Appium server programmatically

因此,我使用下面的代码作为尝试自动启动Appium服务器的尝试,但连接被拒绝:连接错误。 我正在将Maven与Testng一起使用

日志:

失败的配置:@BeforeTest功能org.openqa.selenium.WebDriverException:连接被拒绝:connect构建信息:版本:'3.10.0',版本:'176b4a9',时间:'2018-03-02T19:03:16.397Z'系统信息:主机:'MEL01-ULPT027',ip:'172.24.80.1',操作系统名称:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8。 0_152'驱动程序信息:driver.version:io.appium.java_client.remote.AppiumCommandExecutor.lambda $ 2(AppiumCommandExecutor.java:141)上的AndroidDriver io.appium.java_client.remote上的java.util.Optional.orElseGet(Unknown Source) io的org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)处的.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:140)在io的io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) org.openqa.selenium.remote.RemoteWebDriver.startSession上的io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)上的appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) (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,否则您的代码将无法在Linux或其他操作系统上运行。 这样就可以使用AppiumDriverLocalService启动服务器。 您可以在此处找到启动服务器的有用方法。

暂无
暂无

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

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