• appium 中部分 api 的使用方法


    使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建议多参考java-client-2.1.0-javadoc。

    1.使用AndroidDriver,其已经继承了AppiumDriver

    private AndroidDriver driver;
    
        @Before
        public void setUp() throws Exception {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("deviceName", "Android Emulator");
            capabilities.setCapability("platformVersion", "4.4");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("appPackage", "com.android.settings");
            capabilities.setCapability("appActivity", ".Settings");
    
            driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                    capabilities);
        }
    
        @After
        public void tearDown() throws Exception {
            driver.quit();
        }
    

    2.截屏并保存至本地

    File screen = driver.getScreenshotAs(OutputType.FILE);
            File screenFile = new File("d:\screen.png");
            try {
                FileUtils.copyFile(screen, screenFile); //commons-io-2.0.1.jar中的api
            } catch (IOException e) {
                e.printStackTrace();
            } 
    

    3.push文件、pull文件

    File file = new File("d:\test.txt"); //test.txt内容为"testerHome"
            String content = null;
            try {
                content = FileUtils.readFileToString(file);
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            byte[] data = Base64.encodeBase64(content.getBytes());
            driver.pushFile("sdcard/test.txt", data);
    
            byte[] resultDate = driver.pullFile("sdcard/test.txt");
            System.out.println(new String(Base64.decodeBase64(resultDate))); //打印结果为"testerHome"
    

    4.

            //获取当前界面的activity,可用于断言是否跳转到预期的activity
            driver.currentActivity();
    

    5.

            //打开通知栏界面
            driver.openNotifications();
    

    6.

            //获取网络状态
            int status = driver.getNetworkConnection().value;
            System.out.println(status);
    
            //设置网络状态
            driver.setNetworkConnection(new NetworkConnectionSetting(status));
            //或者
            driver.setNetworkConnection(new NetworkConnectionSetting(false, true, false));
    

    7.

            //启动其他应用,跨APP
            driver.startActivity("com.android.camera", ".CameraLauncher");
    

    8.

            //自动滑动列表
            driver.scrollTo("text");
            //或者
            driver.scrollToExact("text"); 
    

    9.拖动元素

            //拖动相机图标至日历图标位置
            new TouchAction(driver).longPress(driver.findElementByName("相机"))
            .moveTo(driver.findElementByName("日历")).release().perform();
    

    10.图案解锁,解锁该图案:

            TouchAction action = new TouchAction(driver);
            action.press(215, 870).moveTo(540, 870).moveTo(862, 870)
                    .moveTo(540, 1195).moveTo(215, 1195).moveTo(215, 1518)
                    .moveTo(540, 1518).moveTo(862, 1518).moveTo(862, 1195)
                    .release().perform();
  • 相关阅读:
    根据指定月份,打印该月份所属的季节
    求出1~100之间,既是3又是7的倍数的自然数出现的次数
    打印所有的水仙花数
    升景坊单间短期出租
    找出1000以内的所有完数
    ssh config host
    shell获取ip
    mongodb sharding 简单部署记录
    tcp转发
    openssl和Java的keytool证书相关的命令总结
  • 原文地址:https://www.cnblogs.com/111testing/p/7824397.html
Copyright © 2020-2023  润新知