zoukankan      html  css  js  c++  java
  • appium移动端测试之滑动(二)

    在ios测试中,需要用到滑动,所以用java封装了一套滑动的方法,不多说,贴代码

    /**
         * 上滑1/4屏幕
         */
        public void slideUP1_4() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 2, y / 3 * 2, x / 2, y / 3 * 1, 0);
        }
    
        /**
         * 上滑1/2屏幕
         */
        public void slideUP1_2() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 2, y / 4 * 3, x / 2, y / 4 * 1, 0);
        }
    
        /**
         * 下滑1/4屏幕
         */
        public void slideDown1_4() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 2, y / 3 * 1, x / 2, y / 3 * 2, 0);
        }
    
        /**
         * 下滑1/2屏幕
         */
        public void slideDown1_2() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 2, y / 4 * 1, x / 2, y / 4 * 3, 0);
        }
    
        /**
         * 左滑1/2屏幕
         */
        public void slideLeft1_2() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 4 * 3, y / 2, x / 4 * 1, y / 2, 0);
        }
    
        /**
         * 左滑2/3屏幕
         */
        public void slideLeft2_3() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 3 * 2, y / 2, 0, y / 2, 0);
        }
    
        /**
         * 右滑1/2屏幕
         */
        public void slideRight1_2() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 4 * 1, y / 2, x / 4 * 3, y / 2, 0);
        }
    
        /**
         * 右滑2/3屏幕
         */
        public void slideRight2_3() {
            int x = driver.manage().window().getSize().width;
            int y = driver.manage().window().getSize().height;
            driver.swipe(x / 3 * 1, y / 2, x, y / 2, 0);
        }
    
        /**
         * 在某元素中滑动向上滑动
         * 
         * @param 传入WebElement
         */
        public void slideUP(WebElement a) {
            int x = a.getSize().width;
            int y = a.getSize().height;
            driver.swipe(x / 10, y / 3 * 2, x / 10, y / 3 * 1, 0);
    
        }
    
        /**
         * 在某元素中滑动向下滑动
         * 
         * @param 传入WebElement
         */
        public void slideDown(WebElement a) {
            int x = a.getSize().width;
            int y = a.getSize().height;
            driver.swipe(x / 10, y / 3 * 1, x / 10, y / 3 * 2, 0);
        }
    
        /**
         * 在某元素中滑动向左滑动
         * 
         * @param 传入WebElement
         */
        public void slideLeft(WebElement a) {
    
            int x = a.getSize().width;
            int y = a.getSize().height;
            driver.swipe(x / 4 * 3, y / 10, x / 4 * 2, y / 10, 0);
        }
    
        /**
         * 在某元素中滑动向右滑动
         * 
         * @param 传入 Webelement
         */
        public void slideRight(WebElement a) {
            int x = a.getSize().width;
            int y = a.getSize().height;
            driver.swipe(x / 4 * 2, y / 10, x / 4 * 3, y / 10, 0);
        }
    
        /**
         * 长按某元素
         * 
         * @param 传入WebElement
         * @param 传入时间 ms
         *           
         */
        public void longpress(WebElement el, int duration) {
            TouchAction action = new TouchAction(driver);
            action.longPress(el, duration);
        }
    
        /**
         * 将某元素拖动至另一元素
         * 
         * @param 传入WebElement
         */
        public void touch_webelement_to_other_webelement(WebElement e1, WebElement e2) {
            TouchAction action = new TouchAction(driver);
            action.longPress(e1).moveTo(e2);
        }
  • 相关阅读:
    【BZOJ3261】— 最大异或和(可持久化0/1Trie)
    【ZJOI2007】—捉迷藏(动态点分治)
    【HNOI2010】-城市建设(动态最小生成树)
    【BOI2007】Mokia 摩基亚
    【BZOJ 3262】-陌上花开(CDQ分治+树状数组)
    Win64 驱动内核编程-24.64位驱动里内嵌汇编
    Win64 驱动内核编程-23.Ring0 InLineHook 和UnHook
    Win64 驱动内核编程-23.Ring0 InLineHook 和UnHook
    Win64 驱动内核编程-22.SHADOW SSDT HOOK(宋孖健)
    Win64 驱动内核编程-22.SHADOW SSDT HOOK(宋孖健)
  • 原文地址:https://www.cnblogs.com/llining/p/5050508.html
Copyright © 2011-2022 走看看