• Appium简单测试用例


    工程目录如下:

    封装初始化androiddriver 方法

    import org.openqa.selenium.remote.DesiredCapabilities;
    
    import java.io.File;
    
    public class DeviceSession {
        static
        {
            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        }
        static DesiredCapabilities capabilities=null;
        public static DesiredCapabilities getDesiredCapabilities()
        {
            //因为所有在java.io中的类都是将相对路径名解释为起始于用户的当前工作目录,
            // 所以可以通过调用System.getProperty("user.dir") 来获得
                    File classpathRoot = new File(System.getProperty("user.dir"));//默认文件位置
            File appDir = new File(classpathRoot, "apk");
            File apk = new File(appDir, "android-debug.apk");
            if(capabilities==null)
            {
                capabilities = new DesiredCapabilities();
                capabilities.setCapability("platformName", "Android");
                capabilities.setCapability("deviceName", "UGUWUGTWYP49KVNJ");
                capabilities.setCapability("platformVersion", "4.2");
                capabilities.setCapability("app", apk.getAbsolutePath());//"E:\apk\android-debug.apk"(绝对路径,存放在电脑的某个位置)
                capabilities.setCapability("appPackage", "com.eshare.Purse");
                capabilities.setCapability("automationName", "Appium");
                capabilities.setCapability("appActivity", ".MainActivity");
                
            }
            return capabilities;
        }
       }            

     测试用例如下:

    import com.eshare.qa.common.*;
    import com.eshare.qa.wireless.DeviceSession;
    import io.appium.java_client.android.AndroidDriver;
    import org.json.JSONObject;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    import org.testng.asserts.Assertion;
    import java.net.URL;
    
    public class TestPurse {
        public AndroidDriver<WebElement> driver=null;
        Assertion assertion;
        @BeforeClass
        public void setUp() throws  Exception{
            assertion = new Assertion();
            DesiredCapabilities capabilities = DeviceSession.getDesiredCapabilities();
            try {
                driver = new AndroidDriver<WebElement>(
                        new URL(Configuration.Url), capabilities);
            } catch (Exception ex) {
                System.out.println(ex.toString());
            }
            //System.out.println("new!");
            try {
                Thread.sleep(15 * 1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
        @Test
        public void test() throws  Exception{
            boolean ret = ViewUtils.waitForWebViewInit(driver,"WEBVIEW_com.eshare.Purse");
            assertion.assertTrue(ret);
            driver.context("WEBVIEW");
            String loginButtonXpath = "//*[text()='手机登入']";
            boolean isExsit = isElementExist(loginButtonXpath);
            if(isExsit){
                login();
                afterLogin();
            }else{
                afterLogin();
            }
        }
        @AfterClass
        public void teardown(){
            driver.quit();
        }
  • 相关阅读:
    NIS server on centOS 7
    fabric-python-基于centos 7
    玩玩Jenkins
    身份认证技术性能对比
    Linux时区设置和时间同步-基于CentOS 6(最小安装)
    openldap+phpadmin的最简安装和配置
    tomcat8.5的网页管理(远程)配置、SSL证书配置-基于Debian 9
    tomcat添加为service服务-基于Debian 9
    安装、配置MySQL5.8基于Debian 9(用apt-get install 默认安装结果是mariadb)
    下载并配置jdk环境-基于debain 9
  • 原文地址:https://www.cnblogs.com/testlurunxiu/p/6025537.html
Copyright © 2020-2023  润新知