UI自动化中黑名单元素,如何实现 通过yaml读取黑名单元素 ?

UI自动化中的黑名单过滤功能,目前是手动输入过滤元素。

请问下老师同学,如何实现通过 yaml 文件读取过滤元素

handle_black.py

(_black_list中是过滤元素)

import functools
import logging

import allure
from appium.webdriver import WebElement
from appium.webdriver.common.mobileby import MobileBy


def handle_black(fun):
    def wrapper(*args, **kwargs):
        logging.basicConfig(level=logging.INFO)
        _black_list = [
            (MobileBy.ID, "mIvClose"),
            (MobileBy.ID, "tv_agree"),
            (MobileBy.ID, "main_permission_btn"),
            (MobileBy.ID, "btn_start"),
            (MobileBy.ID, "gb_sure"),
            (MobileBy.ID, "iv_close")
        ]
        _max_err_num = 3
        _error_num = 0
        from Oxygen_UI_Android.page.base_page import BasePage

        instance: BasePage = args[0]
        try:
            logging.info(
                "run "
                + fun.__name__
                + "\n args:"
                + repr(args[1:])
                + "\n"
                + repr(kwargs)
            )
            element = fun(*args, **kwargs)
            _error_num = 0
            instance.set_implicitly_wait(5)
            return element

        except Exception as e:
            instance.screenshot("../pics/pics.png")
            with open("../pics/pics.png", "rb") as f:
                content = f.read()
            allure.attach(content, attachment_type=allure.attachment_type.PNG)
            logging.error("元素未找到,开始处理黑名单流程")
            instance.set_implicitly_wait(1)
            if _error_num > _max_err_num:
                _error_num = 0
                raise e
            _error_num += 1
            for ele in _black_list:
                eles = instance.finds(ele)
                if len(eles) > 0:
                    eles[0].click()
                    return wrapper(*args, **kwargs)

            raise ValueError("元素不在黑名单中")

    return wrapper

和咱们课上讲的一样,在yaml文件里放元素的定位方法,定位表达式,解析出来,去操作即可
比如

- by: id
    locator: "xxxxx"