1、APP元素定位
- ID定位
- text定位
- className定位-这种方式一般得到的会是多个元素
- Xpath定位
- accessibility id定位-在UIAutomatorViewer并没有此属性,对应是content-desc属性
- 坐标定位 -- 只能执行点击操作-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、计算机基础
资料获取方式 :