class take_screen_shot(): #这个类将在下面作为装饰器使用
def __init__(self, func):
self.func = func
self.name = func.__name__ + ' (error).png' #拼接截图文件名
def __call__(self, *args): #对每次调用的函数都做截图操作
try:
self.func(self, *args)
except Exception as msg:
self.driver.get_screenshot_as_file('C:\\Users\\zhengtao\\Desktop\\pic\\'+self.name)
raise msg
我使用@take_screen_shot调用装饰器的时候,总是报错
AttributeError: 'take_screen_shot' object has no attribute 'driver'
这是为何,不解!