1.利用try catch捕获异常
2.异常处理弹框
参考链接:https://github.com/yuruotong1/ui_framework
#main.yml文件内容
- by: id
locator: tv_search
action: click
#base_page.py文件内容
import yaml
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.common.by import By
class BasePage:
_driver: WebDriver
#定义黑名单列表
_black_list=[(By.ID, "iv_close")]
def __init__(self, driver: WebDriver = None):
self._driver = driver
#查找元素的时候通过try catch捕获异常
def find(self, locator, value):
try:
element = self._driver.find_element(locator, value)
return element
except:
for black in self._black_list:
elements = self._driver.find_elements(*black)
if len(elements) > 0:
elements[0].click()
break
# 处理完黑名单后,再次找原来的元素
return self.find(locator, value)
#测试步骤的数据驱动
def steps(self, path):
with open(path) as f:
steps = yaml.safe_load(f)
element = None
for step in steps:
if "by" in step.keys():
element = self.find(step["by"], step["locator"])
if "action" in step.keys():
action = step["action"]
if action == "click":
element.click()
后面打造框架会再次进行构造