Java 怎么设置Appium服务器

2019年7月29日19:57:03Java 怎么设置Appium服务器已关闭评论 651 2302字阅读7分40秒

1.简介

Java 怎么设置Appium服务器?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;

public class TestCalcUISelector {

    public static AndroidDriver<MobileElement> driver;

    
    public static Process process;

    
    public static String STARTSERVER = "C:\\Program Files (x86)\\Appium\\node.exe C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\appium.js";

    
    public static void StartAppiumServer() throws InterruptedException,
            IOException {
        Runtime runtime = Runtime.getRuntime();
        Thread.sleep(7000);

        process = runtime.exec(STARTSERVER);

        if (process != null) {
            System.out.println("Appium Server Started Successfully");
        }

    }

    
    public static void StopAppiumServer() {

        if (process != null) {
            process.destroy();
        }
        System.out.println("Appium Server Stopped Successfully");
    }

    public static void main(String[] args) throws InterruptedException,
            IOException {

        StopAppiumServer();
        StartAppiumServer();

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability("deviceName", "Android");

        capabilities.setCapability("platformVersion", "4.4.2");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.asus.calculator");
        capabilities.setCapability("appActivity",
                "com.asus.calculator.Calculator");
        driver = new AndroidDriver<MobileElement>(new URL(
                "http:

        driver.manage().timeouts().implicitlyWait(5L, TimeUnit.SECONDS);

        
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"C\")")
                .click();
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"6\")")
                .click();
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"5\")")
                .click();
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"+\")")
                .click();
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"2\")")
                .click();
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"5\")")
                .click();
        driver.findElementByAndroidUIAutomator(
                "UiSelector().className(\"android.widget.Button\").text(\"=\")")
                .click();

        driver.quit();

        StopAppiumServer();

    }

}

 
继续阅读
编程十万个怎么办