App自动化测试 —— App元素定位&滑动操作

1262 篇文章 11 订阅
682 篇文章 4 订阅

1、APP元素定位

  1. ID定位
  2. text定位
  3. className定位-这种方式一般得到的会是多个元素
  4. Xpath定位
  5. accessibility id定位-在UIAutomatorViewer并没有此属性,对应是content-desc属性
  6. 坐标定位 -- 只能执行点击操作-xpath支持单引号
  • 设置坐标操作:选择设置中关于手机->连续点击五次版本号->进入开发者选项->指针位置进行勾选
  • 坐标定位受设备屏幕尺寸/分辨率/DPI影响,万不得已不要使用此种方式
//1、ID
//找到我的柠檬元素并且点击
androidDriver.findElement(MobileBy.id("com.lemon.lemonban:id/navigation_my")).clic
k();

//2、text--双引号要转义下
androidDriver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\"全
程班\")");

// 3、className
androidDriver.findElement(MobileBy.className("android.widget.LinearLayout"));

//4 、Xpath
androidDriver.findElement(MobileBy.xpath("//android.widget.TextView[@text='全程
班']"));    里头有单引号,是因为xpath支持单引号

//5、AccessibilityId
androidDriver.findElement(MobileBy.AccessibilityId("题库"));

2、等待-toast元素如何定位(不会获得焦点,无法被点击)-一种简易的消息提示框

获取方式:

隐式等待

androidDriver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
androidDriver.findElement(MobileBy.xpath("//*[contains(@text, 'tips')]"));

显示等待-等待条件只能够去用等待元素存在这一个

WebElement webElement = webDriverWait.until(ExpectedConditions.
presenceOfElementLocated(MobileBy.xpath("//*[contains(@text,'账号信
息')]")));
System.out.println(webElement.getText());

3、滑动操作-两个位置从一个移动到另外一个

//向左滑动方法
    public void swipeleft(int time){
        //获取屏幕宽和高
        int width = androidDriver.manage().window().getSize().getWidth();
        int height = androidDriver.manage().window().getSize().getHeight();
        TouchAction touchAction = new TouchAction(androidDriver);
        PointOption pointOption1 = PointOption.point(width*3/4,height/2);
        PointOption pointOption2 = PointOption.point(width/4,height/2);

        Duration duration = Duration.ofMillis(time);
        WaitOptions waitOptions = WaitOptions.waitOptions(duration);
        touchAction.press(pointOption1).waitAction(waitOptions).moveTo(pointOption2).release().perform();
    }



 @Test
    public void testSwipe() throws InterruptedException {
        //swipeDown();
        //连续向左滑动四次
        swipeleft(200);
        swipeleft(200);
        swipeleft(200);
        swipeleft(200);
        Thread.sleep(5000);
        androidDriver.quit();

    }

下面是配套学习资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!

软件测试面试小程序

被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!

涵盖以下这些面试题板块:

1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux

6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础

资料获取方式 :

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值