zoukankan      html  css  js  c++  java
  • 自动化测试工具Appium入门--特殊操作技巧

    1 截屏

    //截屏图片保存路径

    static String path = "E:\workspace\PhonewoTest\ScreenshotPic\";

    static AndroidDriver driver = DriverInit.driver;

    /*截屏

    * tag表示一个模块标记字符

    */

    public static void takeScreenShot(AndroidDriver driver,String tag){  

       File screenShotFile = 

                 ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);  

       try {   

       FileUtils.copyFile(screenShotFile, new File(path + tag + 

                     getCurrentDateTime()+ ".jpg"));  

       }catch (IOException e) {

       e.printStackTrace();

       }  

      

    //格式化当前时间

    public static String getCurrentDateTime(){

       SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");//设置日期格式

       return df.format(new Date());

    }

    2 粘贴

    /*粘贴

    */

    public static void Clip(WebElement el) { 

    //获取焦点

    el.click();

    //ctrl+v的组合操作

    driver.sendKeyEvent(50,AndroidKeyMetastate.META_CTRL_ON);

    }

    3 硬件返回

    driver.sendKeyEvent(4);

    或者,

    driver.sendKeyEvent(AndroidKeyCode.BACK);

    4 滑动

    //向上滑动

    driver.swipe(20, 400, 20, 100, 300);

    5 长按

    //初始化

    TouchAction action = new TouchAction(driver);

    //获取要长按的元素

    WebElement el = driver.findElement(By.id("cn.langma.phonewo:id/user_name"));

    //长按

    action.longPress(el).perform();

    6 按住不放

    //初始化

    TouchAction action = new TouchAction(driver);

    //按住等待5秒后释放       

    action.press(driver.findElement(By.name("按住说话"))).waitAction(5000);

    action.perform();

  • 相关阅读:
    spring整合mybatis的事物管理配置
    平庸久了,是会上瘾的
    kafka基本概念
    JMS编程模型
    aop的基本概念
    事务的隔离级别和传播行为
    IntelliJ IDEA 导入Project
    [PowerShell]列出檔案與資料夾的資訊
    [powershell]统计目录大小
    [powershell]有关IP的设置
  • 原文地址:https://www.cnblogs.com/tianqianlan/p/11209789.html
Copyright © 2011-2022 走看看