zoukankan      html  css  js  c++  java
  • Appium第二天

    屏幕解锁:

    package com.APPtest.class4;

    import java.io.File;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.remote.DesiredCapabilities;

    import io.appium.java_client.TouchAction;
    import io.appium.java_client.android.AndroidDriver;

    public class class_demo4 {

    public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    AndroidDriver driver;

    DesiredCapabilities cap=new DesiredCapabilities();

    cap.setCapability("automationName", "Appium");//appium做自动化
    // cap.setCapability("browserName", "chrome");//设置HTML5的自动化,打开谷歌浏览器
    cap.setCapability("deviceName", "S4");//设备名称
    cap.setCapability("platformName", "Android"); //安卓自动化还是IOS自动化
    cap.setCapability("platformVersion", "4.4"); //安卓操作系统版本
    cap.setCapability("udid", "192.168.10.101:5555"); //设备的udid (adb devices 查看到的)
    cap.setCapability("appPackage", "com.android.settings");
    cap.setCapability("appActivity", ".Settings");
    cap.setCapability("unicodeKeyboard", "True"); //支持中文输入
    cap.setCapability("resetKeyboard", "True"); //支持中文输入,必须两条都配置
    cap.setCapability("noSign", "True"); //不重新签名apk
    cap.setCapability("newCommandTimeout", "30"); //没有新命令,appium30秒退出

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);//把以上配置传到appium服务端并连接手机
    driver.scrollTo("备份和重置");
    driver.findElementByName("安全").click();
    driver.findElementByName("屏幕锁定").click();
    driver.findElementByName("图案").click();
    TouchAction action=new TouchAction(driver);
    //7(210,1320)、5(540,990)
    action.press(870,1320).moveTo(-330, -330).moveTo(-330,-330).moveTo(660,330).moveTo(-330, -330).moveTo(-330, 330).moveTo(660, -330).moveTo(-330, 330).moveTo(-330, 330).perform();
    Thread.sleep(3000);
    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();
    }


    }

    }

  • 相关阅读:
    JDBC数据库程序连接MySQL
    java中image显示图片,随上下左右键移动
    java匿名类关闭窗口
    一个通用的SQL客户程序
    我的第一个JavaApplet程序
    Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
    Java MessagePanel
    线程通信,生产者消费者问题(Java)
    Java程序显示正在运行的时钟(timer类)
    百度star2012初赛第一场的题目
  • 原文地址:https://www.cnblogs.com/Sherlock-wu/p/6527128.html
Copyright © 2011-2022 走看看