最近在研究Appium+python写Android自动化测试脚本,之前用过selenium+python写web的自动化测试脚本,在此基础上修改。
还是使用POM,一个page页面对应一个test_case,base页面封装一些公共方法。封装的一个查找元素的公共方法:
def find_element(self, *loc):
try:
WebDriverWait(self.driver,10,0.5).until(EC.visibility_of_element_located(loc))
return self.driver.find_element(*loc)
except AssertionError as e:
self.driver.close()
*loc表示这是一个元组对象。
之前使用selenium写page页面调用该方法查找元素,例如:
login_username_loc = (By.XPATH, 'XXX')
el = self.find_element(*self.login_button_loc)
Appium的webdriver中新增了一些查找元素方法,我要通过accessibility_id查找元素,find_element_by_accessibility_id方法。但是selenium的selenium.webdriver.common.by中没有accessibility_id,如下所示,只有:ID、XPATH、LINK_TEXT、PARTIAL_LINK_TEXT、NAME、TAG_NAME、CLASS_NAME、CSS_SELECTOR。
cla