目录
自动化需要准备的环境
打开逍遥模拟器,安装测试apk
启动appium server端
启动Inspector
开始写脚本
初始化
测试结束后关闭driver
常见的定位方法
- Appium 桌面版
- Android sdk
- Java 环境jdk
- 逍遥模拟器
- Inspector
appium启动后点击这个图标会跳转到下载页面
查看模拟器的设备名字
device_name 是127.0.0.1:21503
打开appium桌面版,点击【Edit Configurations】,设置sdk环境
点击【Start Server V1.22.0】启动服务,看到下面的文字就是成功了
Inspector 可以用来查看app上的元素,在脚本中用来定位元素
deviceName | 设备名字,前面adb devices查出 |
appPackage | adb shell dumpsys window w |findstr / |findstr name= mSurface=Surface(name/WebviewExActivity) / 斜杠左侧是appPackage,右侧是appActivity |
appActivity |
点击【Start Sessions】,会在模拟器上打开app
新建一个maven项目
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0"xmlns:xsi=""xsi:schemaLocation=".0.0 .0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId&le</groupId><artifactId>app_uiautomitor</artifactId><version>1.0-SNAPSHOT</version><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><mavenpiler.target>1.8</mavenpiler.target><mavenpiler.source>1.8</mavenpiler.source></properties><dependencies><!-- .appium/java-client --><dependency><groupId>io.appium</groupId><artifactId>java-client</artifactId><version>7.6.0</version></dependency><!-- .seleniumhq.selenium/selenium-java --><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>3.141.59</version></dependency><!-- .testng/testng --><dependency><groupId&stng</groupId><artifactId>testng</artifactId><version>7.4.0</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>3.0.0-M5</version><configuration><useSystemClassLoader>false</useSystemClassLoader></configuration></plugin></plugins></build>
</project>
想要定位图中的元素,可以先定位到有 resource-id的元素,然后找它的子元素。
driver.findElementById(")
.findElements(By.className("android.widget.LinearLayout"))
.get(0)
driver.findElementByXPath("//android.view.View[@resource-id='app']/android.view.View[6]/android.view.View[3]").click();
xpath的元素从1开始,所以[3]表示第三个 android.view.View
场景:需要长按某个元素,然后弹出一个窗口,再点击窗口里的元素
1,找到需要长按的元素
WebElement element = driver.findElementById("xxx");
2,执行长按操作
TouchAction touchAction = new TouchAction(driver);touchAction.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(element)).withDuration(Duration.ofSeconds(1))).perform();
3,点击页面的元素
driver.findElementById("xxx").click();
从(x1,y1) 滑动到(x2,y2)
TouchAction touchAction = new TouchAction(driver);touchAction.press(PointOption.point(x1, y1)).moveTo(PointOption.point(x2, y2)).release().perform();
定位的终极大法:点坐标
new TouchAction<>(driver).press(PointOption.point(x,y)).release().perform();
本文发布于:2024-01-31 23:36:09,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170671537132212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |