【Appium】之自动化定位总结

一、同级定位时,先定位上级

我想定位【必填】框,我先定位【姓名】的同一个上级

 

self.driver.find_element(MobileBy.XPATH,"//*[contains(@text,'姓名')]/../*[@text='必填']").send_keys(name)
self.driver.find_element(MobileBy.XPATH,"//*[contains(@text,'手机')]/..//*[@text='必填']").send_keys(tel)

二、打印app页面属性

self.driver.page_source

三、替换输入值的方法

def xxx(text):

  f"{text}"

    def findEle(self,text):
        while(True):
            try:
                self.driver.find_element(By.XPATH, f"//*[@text='{text}']").click()

四、其他参数配置方法

"skipServerInstallation": True,     # 跳过UIautomator2 server安装
"skipDeviceInitialization": True,   # 跳过设备的初始化
"dontStopAppOnReset": True,        # 测试之前不停止app运行
"automationName": "UiAutomator2"    # Toast内容

五、其他自动化Flutter

flutter : https://github.com/truongsinh/appium-flutter-driver

六、打印日志

logging.basicConfig(level=logging.INFO)


logging.info("find")
logging.info(loc)

然后在PageObject路径下设置一下,pytest.ini配置文件:

[pytest]
addopts= --capture=no

 

 

 

附录:

①实战2地址:https://ceshiren.com/t/topic/10536

②实战1地址:https://ceshiren.com/t/topic/10490

 

posted @ 2022-06-20 11:11  Owen_ET  阅读(104)  评论(0编辑  收藏  举报