Appium滑动和截屏方法封装

本文介绍了如何使用Appium进行屏幕滑动(向上滑动和向右滑动)和截图操作。提供了`swipeToUp`、`swipeToRight`方法用于屏幕滑动,以及`snapshot`方法用于截取并保存当前屏幕快照。
 /**
     * Swipe up on the screen
     */

   public static void swipeToUp(AndroidDriver driver, int time) {
        int width = driver.manage().window().getSize().width;
        int height = driver.manage().window().getSize().height;
        driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, time);
    }

    /**
     *  Swipe to right on the screen
     */

    public static void swipeToRight(AndroidDriver driver, int time) {
        int width = driver.manage().window().getSize().width;
        int height = driver.manage().window().getSize().height;
        driver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, time);
    }
   
   
    /**
     * This method is created for taking screenshot
     */

    public static void snapshot(TakesScreenshot drivername, String filename) {
        String currentPath = System.getProperty("user.dir");
        File scrFile = drivername.getScreenshotAs(OutputType.FILE);
        try {
            System.out.println("Saved snapshot's path is:" + currentPath + "/"
                    + filename);
            FileUtils.copyFile(scrFile, new File(currentPath + "/" + filename));
        } catch (IOException e) {
            System.out.println("Can't save screenshot!");
            e.printStackTrace();
        } 
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值