from engine.browser_engine import BrowserEngine
from engine.read_config import ReadConfig
from engine.logger import Logger
import os,time


def get_engine(file, url):
    def inner(f):

        def wapper(*args, **kwargs):
            try:
                start_time = time.time()
                log_name = os.path.split(file)[-1].split(".")[0]
                image_path = os.path.join(os.path.dirname(os.path.dirname(file)), "images")
                image_path = os.path.join(image_path, log_name)
                image_path += '.png'

                engine = BrowserEngine(image_path, log_name, url)

                ret = f(engine, *args, **kwargs)

                end_time = time.time()
                engine.logger.info(f'执行时间：{end_time-start_time}s')
                if engine: del engine
                return ret
            except Exception as e:
                print(e)

        return wapper

    return inner
