python class 类 带参数的装饰器
def three_loop(webpage):
def function(fun):
def wrapper(self, *args, **kwargs):
for i in range(3):
try:
return fun(self, *args, **kwargs)
except:
print('%s 页的 %s 方法报错,重试第%d次' % (webpage, fun.__name__, i))
time.sleep(1)
else:
print('%s 页的 %s 方法重复执行3次失败退出方法!' % (webpage, fun.__name__))
return wrapper
return function
class User():
def __init__(self, user, pwd):
self.user = user
self.pwd = pwd
@three_loop('登陆')
def huancun(self):
page = rpa.chrome.create('chrome://settings/')
rpa.chrome.max_window()
if rpa.win32.element_count("恢复弹窗"):
rpa.win32.click("恢复弹窗")
rpa.win32.click("清除缓存1")
time.sleep(1)
rpa.win32.click("清除缓存2")