编程语言
首页 > 编程语言> > 【Mac + Appium + Java1.8学习(二)】之Android模拟器自动化测试脚本开发以及简易例子

【Mac + Appium + Java1.8学习(二)】之Android模拟器自动化测试脚本开发以及简易例子

作者:互联网

直接上代码:

import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

import static java.lang.Thread.sleep;


public class TestXueqiuDemo {
    private AppiumDriver<WebElement> driver;

    @Before
    public void setUp() throws MalformedURLException {
        // set up appium
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability("deviceName", "192.168.56.101:5555");
        capabilities.setCapability("appPackage","com.xueqiu.android");
        capabilities.setCapability("appActivity",".view.WelcomeActivityAlias");

        driver = new AppiumDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
    }

    @After
    public void tearDown() throws Exception{
//        driver.quit();
        System.out.println("测试结束!");
    }

    @Test
    public void testDemo01() throws Exception {
        driver.findElementById("com.xueqiu.android:id/open").click();
        int i = 0;
        for (i=0;i<2;i++){
            driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click();
        }
//        driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click();
        sleep(5000);
//      隐式等待
//        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        System.out.println("暂停10s");
        driver.findElementById("com.xueqiu.android:id/agree").click();
        driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click();
        sleep(2000);
        driver.findElementByXPath("//*[@text='自选']").click();
    }

}

 

标签:Appium,java,Java1.8,setCapability,driver,capabilities,Mac,org,import
来源: https://www.cnblogs.com/Owen-ET/p/10021353.html