问题描述:

方法加入 自定义装饰器 后,调用时不显示参数,并且无法联想到后续的方法 ( click, sendkeys 等)

会报错,但用例正常运行
已尝试使用 @wraps(func),依然有该问题

装饰器 handle_black

import logging

from appium.webdriver.common.mobileby import MobileBy


def handle_black(func):
    def wrapper(*args, **kwargs):
        logging.basicConfig(level=logging.INFO)
        _black_list = [
            (MobileBy.ID, "mIvClose")
        ]
        _max_err_num = 3
        _error_num = 0
        from Oxygen_UI.page.base_page import BasePage
        instance: BasePage = args[0]
        try:
            logging.info("run " + func.__name__ + "\n args:" + repr(args[1:]) + "\n" + repr(kwargs))
            element = func(*args, **kwargs)
            _error_num = 0
            instance.set_implicitly_wait(5)
            return element

        except Exception as e:
            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

方法

@handle_black
    def find(self, by, locator=None) -> WebElement:
        if locator is None:
            result = self.driver.find_element(*by)
        else:
            result = self.driver.find_element(by, locator)
        return result

不显示参数

联想不到方法

报错信息

E       AttributeError: 'NoneType' object has no attribute 'click'


↙↙↙阅读原文可查看相关链接,并与作者交流