简体   繁体   English

以编程方式启动Appium服务器

[英]Starting Appium server programmatically

So i am using below code as a try to start the Appium server automatically but getting the connection refused:connect error. 因此,我使用下面的代码作为尝试自动启动Appium服务器的尝试,但连接被拒绝:连接错误。 I am using Maven with Testng 我正在将Maven与Testng一起使用

Logs: 日志:

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 失败的配置:@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) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38) (RemoteWebDriver.java:219)在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:142)在io.appium.java_client.DefaultGenericMobileDriver。(DefaultGenericMobileDriver.java:38)

Code: 码:

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();
        }
   }

I suggest to avoid running Appium from command line, your code won't work on Linux or different OS. 我建议避免从命令行运行Appium,否则您的代码将无法在Linux或其他操作系统上运行。 So that use AppiumDriverLocalService to start the server. 这样就可以使用AppiumDriverLocalService启动服务器。 You can find here useful ways to start your server. 您可以在此处找到启动服务器的有用方法。

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

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