zoukankan      html  css  js  c++  java
  • 【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();
        }
    
    }
  • 相关阅读:
    Python笔记:日期时间获取与转换
    算法笔记:递归、动态规划
    容器技术介绍:Docker Dockerfile语法与指令
    Netdiscover网络扫描工具
    持续集成:jenkins + pytest + selenium + Git + Allure自动化测试
    MySQL数据库基础入门
    Parameters 至少一个参数没有指定
    C/C++ 延时函数 (标准库)
    TabController控件测试
    contentEditable
  • 原文地址:https://www.cnblogs.com/Owen-ET/p/10021353.html
Copyright © 2011-2022 走看看