刚开始学iOS自动化测试的时候,用的是xpath定位方式,不仅慢,而且我们的app路径还很长。最近发现了一个很好用的方式,就是用坐标点击,再加上findElementByIosNsPredicate的定位方式。
1.坐标点击的方法:TouchAction
例如:点击
new TouchAction(driver)
.press(PointOption.point(x,y))
.release().perform();
例如:滑动
new TouchAction(driver)
.press(PointOption.point(x,y))
.moveTo(PointOption.point(width,height))
.release().perform();
例如:长按
new TouchAction(driver)
.press(PointOption.point(x,y)) //LongPress
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(4))) //长按时间
.release().perform();
2.用findElementByIosNsPredicate找到元素的坐标
driver.findElementByIosNsPredicate("").getLocation().getX()
driver.findElementByIosNsPredicate("").getLocation().getY()