既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
本章主要介绍几种原生app定位的方法,我们可以进入npm安装目录下找到driver.js文件打开可以
看到如下几种定位方法,我的地址是(C:\Users\username\AppData\Roaming\npm\node_modules
\appium\node_modules\appium-android-driver\lib),npm版本为8.1.2。
1.id
- 实例
import time
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
desired_cap = {
"platformName": "Android", # 手机系统
"platformVersion": "11", # 手机系统版本
"deviceName": 'xxxxx', # 连接的设备
"automationName": "UiAutomator2", # 自动化测试框架
"appPackage": "xxxxx", # app包名
"appActivity": "xxxxxx", # app的启动页面
"autoGrantPermissions": "true", # 默认允许app获取相关权限
"noReset": True # 保留登录模式
}
driver = webdriver.Remote(command_executor="http://127.0.0.1:4723/wd/hub", desired_capabilities=desired_cap)
driver.implicitly_wait(10) # 设置元素等待
driver.find_element(AppiumBy.ID, "tv.danmaku.bili:id/agree").click() # id定位resource-id
id的值与uiautomatorviewer中resource-id的值一致。resource-id在元素app中并不是唯一的,所以使用要视情况而定。
2.xpath
xpath可根据uiautomatorviewer中node detail的属性和值进行定位
1)单条件定位
driver.find_element(AppiumBy.XPATH, '//*[@text="同意并继续"]').click()
2)多条件定位
driver.find_element(AppiumBy.XPATH, '//*[@text="同意并继续" and @resource-id="tv.danmaku.bili:id/agree"]').click()
多个条件之间用and连接
3.ANDROID_UIAUTOMATOR
1)根据文本(text)值进行定位
精准匹配
import time
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
desired_cap = {
"platformName": "Android", # 手机系统"platformVersion": "11", # 手机系统版本"deviceName": 'xxxxx', # 连接的设备"automationName": "UiAutomator2", # 自动化测试框架"appPackage": "xxxxx", # app包名"appActivity": "xxxxxx", # app的启动页面"autoGrantPermissions": "true", # 默认允许app获取相关权限"noReset": True # 保留登录模式
}
driver = webdriver.Remote(command_executor="http://17.0.0.1:4723/wd/hub", desired_capabilities=desired_cap)
driver.implicitly_wait(10) # 设置元素等待
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("同意并继续")').click() # text值精准匹配
模糊匹配
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textContains("意并继")').click() # text值模糊匹配
开头匹配
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textStartsWith("同意")').click() # text值匹配开头
2)根据class_name进行定位
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().className("android.widget.TextView")').click()
class_name对应的就是class的值
3)根据resource-id进行定位
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("tv.danmaku.bili:id/agree")').click()
4)根据description进行定位
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, ‘new UiSelector().description(“Xxxx”)’).click()
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新