Appium 自动化测试(8) -- Appium Python client -- API

it2024-10-07  16

最好的学习方法,就是看源码!

在  \appium\webdriver\webdriver.py ,新增了两个封装好定位安卓元素的方法,如  find_element_by_accessibility_id 与 find_element_by_android_uiautomator

 

如下图,定位“一起玩”tab页:

一、根据UIAutomator定位元素

def test_find_element(self): self.driver.wait_activity('com.yy.mobile.ui.home.MainActivity',30) # text 属性的方法 el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("一起玩")') self.assertIsNotNone(el) e2 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("起玩")') self.assertIsNotNone(e2) e3 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("一起")') self.assertIsNotNone(e3) e4 = self.driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^一起.*")') self.assertIsNotNone(e4) # class属性的方法 e5 = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("一起玩")') self.assertIsNotNone(e5) # resourceId属性的方法 e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.yy.mobile.plugin.main:id/tab_tab_btn")') self.assertIsNotNone(e6)

二、根据accessibility_id定位

def find_element_by_accessibility_id(self, id): """Finds an element by accessibility id. :Args: - id - a string corresponding to a recursive element search using the Id/Name that the native Accessibility options utilize :Usage: driver.find_element_by_accessibility_id() """ return self.find_element(by=By.ACCESSIBILITY_ID, value=id)

对于 Android 就是 content-description

对于 iOS 就是 accessibility identifier

 三、看源码可知,Appium 中的Webdriver是Selenium中的webdirver.Remote的子类,所以更多的API,可是在Selenium中寻找

 

***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***

转载于:https://www.cnblogs.com/guanfuchang/p/9122370.html

相关资源:Appium-Python-Client
最新回复(0)