#!/usr/bin/python
# coding: utf-8

'''
class screenshot:
    def savePIC(self,path,scriptname):
        self.driver.get_screenshot_as_file(path)
        self.driver.save_screenshot('%s' % scriptname + '.png')
        return "saveIMG OK!"

'''
import logging
import time
from functools import wraps


'''
截图装饰器设置
'''
class Decorator:
    def getImage(function):
        @wraps(function)
        def get_ErrImage(self, *args, **kwargs):
            try:
                result = function(self, *args, **kwargs)
            except:
                timestr = time.strftime("%Y-%m-%d_%H_%M_%S")
                self.dr.get_screenshot_as_file('E:\\Appium\\Mailchat\\image\\getscreen\\%s %s.png' %
                                               (function.__name__timestr))
            else:
                logging.info(" %s 脚本运行正常" %
                             (function.__name__)
                             )
            return result
        return get_ErrImage

    '''
    函数运行时间统计装饰器
    '''
    def timer(func):
        def wrapper(*args, **kw):
            start_time = time.time()
            # 这是函数真正执行的地方
            func(*args, **kw)
            end_time = time.time()
            t = end_time - start_time
            print("花费时间：{}秒".format(t))
            return t
        return wrapper

