51Testing软件测试论坛

标题: 跪求appium+Java+Junit 九宫格的实例 [打印本页]

作者: 卞信华    时间: 2017-7-7 23:40
标题: 跪求appium+Java+Junit 九宫格的实例
跪求appium+Java+Junit 九宫格的实例
作者: hym222018    时间: 2017-7-9 07:26
回复
作者: 江诗    时间: 2017-7-10 11:27
对于此类滑动解锁,只能使用坐标点来滑动了,要使用坐标点九必须得到1~9这几个点在屏幕上的相对位置,要得到相对位置首先要得到元素view的起始坐标(就是左上角的x和y坐标点),然后再获取到元素的宽和高,由此可以得到1到9的这9个坐标点的x和y坐标,再利用touchaction类的方法进行封装即可,具体实现如下:
        /**
         * 针对应用的九宫格滑动解锁,每个滑动点么有独立的元素,只能通过相对的坐标点进行滑动
         * @param driver
         * @param element
         */
        public void unlockApp(AppiumDriver driver,WebElement element) throws Exception{
                TouchAction ta=new TouchAction(driver);
                //元素的起始x和y坐标
                int x=element.getLocation().getX();
                int y=element.getLocation().getY();
                //元素的宽和高
                int width=element.getSize().getWidth();
                int height=element.getSize().getHeight();
                //九宫格图案,对应的1-9个数字的位置
                int num1x=x+width/4;
                int num1y=y+height/4;
                int num4x=num1x;
                int num4y=y+height/2;
                int num7x=num1x;
                int num7y=y+height*3/4;
                int num2x=x+width/2;
                int num2y=y+height/4;
                int num5x=num2x;
                int num5y=y+height/2;
                int num8x=num2x;
                int num8y=y+height*3/4;
                int num3x=x+width*3/4;
                int num3y=y+height/4;
                int num6x=num3x;
                int num6y=y+height/2;
                int num9x=num3x;
                int num9y=y+height*3/4;
                //moveTo(x,y)滑动时需要提供相对于press坐标点的相对位置,按住一个点后,如果向左或向右滑动那么x坐标为元素宽度的1/4,y坐标为0,相对坐标值为正数时向右滑动,为负数时向左滑动
                //上下滑动时,x相对坐标为0,y的相对坐标为高度的height/4,相对坐标值为正数时向下滑动,为负数时向上滑动
                /*Z字形解锁图案*/
                ta.press(num1x, num1y).waitAction(500).moveTo(width/4, 0).moveTo(width/4, 0).moveTo(-width/4, height/4).moveTo(-width/4, height/4).moveTo(width/4, 0).moveTo(width/4, 0).release().perform();
                /*7字形解锁图案*/
                ta.press(num1x, num1y).waitAction(500).moveTo(width/4, 0).moveTo(width/4, 0).moveTo(0, height/4).moveTo(0, height/4).release().perform();
        }




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2