如果从代码启动Appium服务器,则无法实例化android驱动程序

时间:2015-08-07 10:47:55

标签: android webdriver appium

我正在关注的步骤,启动服务器是: 使用以下命令创建了一个bat文件: " C:/ Program Files(x86)/Appium/node.exe" " C:/ Program Files(x86)/Appium/node_modules/appium/bin/Appium.js" --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 18 --automation-name Appium --no-reset --local-timezone --log E:\ Android \ appium.log&# 34;"

代码编写启动服务器:

public class Testing {
    AppiumDriver driver;

    @BeforeTest

    public void AppiumServerStart() throws MalformedURLException, InterruptedException {

        String s = null;

        String Filepath = "C:\\appiumserver.bat";

        // String Command = \""C:/Program Files (x86)/Appium/node.exe"
        // "C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js"
        // --address 127.0.0.1 --port 4723 --platform-name Android
        // --platform-version 18 --automation-name Appium --no-reset
        // --local-timezone"\"

        System.out.println(Filepath);

        try {
            Process p = Runtime.getRuntime().exec(Filepath);


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println(Filepath);
        System.out.println("Server Started");

        Thread.sleep(6000);

}

添加欲望功能的代码并创建android驱动程序实例:

public class DemoCalc extends Testing {

    AppiumDriver driver;

    @Test

    public void Setup() throws MalformedURLException, InterruptedException {

        File file = new File(System.getProperty("user.dir"));

        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.VERSION, "4.4.4");
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "169.254.140.101:5555");
        cap.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2");
        cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
        driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), cap);

但是,Android驱动程序实例上会抛出以下异常:

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'

如果我手动,通过单击appium.exe启动服务器,则不会发生问题。但是当服务器从java代码启动时出现问题。

运行bat文件启动appium服务器后,我在任务管理器中看到节点进程,该进程显示appium服务器已连接。

请帮忙

1 个答案:

答案 0 :(得分:0)

在执行测试之前,尝试将Appium服务器作为单独的线程运行。