Ejemplo n.º 1
0
    def test_set_logdir(self):
        new_logfile = "log123.txt"
        new_logdir = DIR("./logs_new")
        self.delete_path([new_logdir, new_logfile])
        # set logfile = ./logs_new/log123.txt
        ST.LOG_FILE = new_logfile
        set_logdir(new_logdir)
        argv = ["run", OWL, "--device", "Android:///"]
        main_parser(argv)
        G.LOGGER.set_logfile(None)
        self.assertTrue(os.path.exists(os.path.join(ST.LOG_DIR, ST.LOG_FILE)))

        rpt = LogToHtml(OWL)
        rpt.report()
        self.assertTrue(os.path.exists(self.OUTPUT_HTML))

        # test export log
        self.delete_path([self.EXPORT_DIR])
        rpt_export = LogToHtml(OWL, export_dir=self.EXPORT_DIR)
        rpt_export.report()
        export_path = os.path.join(self.EXPORT_DIR, self.SCRIPT_NAME + ".log")
        self.assertTrue(
            os.path.exists(os.path.join(export_path, self.OUTPUT_HTML)))
        self.assertTrue(os.path.exists(os.path.join(export_path, "static")))

        self.delete_path([new_logdir, new_logfile])
        ST.LOG_FILE = DEFAULT_LOG_FILE
        ST.LOG_DIR = DEFAULT_LOG_DIR
Ejemplo n.º 2
0
 def test_export_log(self):
     rpt = LogToHtml(OWL, export_dir=self.EXPORT_DIR)
     rpt.report()
     export_path = os.path.join(self.EXPORT_DIR, self.SCRIPT_NAME + ".log")
     self.assertTrue(
         os.path.exists(os.path.join(export_path, self.OUTPUT_HTML)))
     self.assertTrue(os.path.exists(os.path.join(export_path, "static")))
Ejemplo n.º 3
0
 def test_static_root(self):
     # set static_root
     rpt = LogToHtml(OWL, self.LOG_DIR, static_root=self.HTTP_STATIC)
     rpt.report()
     self.assertTrue(os.path.exists(self.OUTPUT_HTML))
     with open(self.OUTPUT_HTML, encoding="utf-8", errors="ignore") as f:
         self.assertTrue(self.HTTP_STATIC in f.read())
Ejemplo n.º 4
0
 def test_export_log_http_static(self):
     # http static file
     rpt_static = LogToHtml(OWL,
                            export_dir=self.EXPORT_DIR,
                            static_root=self.HTTP_STATIC)
     rpt_static.report()
     export_path = os.path.join(self.EXPORT_DIR, self.SCRIPT_NAME + ".log")
     self.assertTrue(
         os.path.exists(os.path.join(export_path, self.OUTPUT_HTML)))
     self.assertTrue(
         not os.path.exists(os.path.join(export_path, "static")))
Ejemplo n.º 5
0
def get_report(script,
               log_root=ST.LOG_DIR,
               outfile='log.html',
               static_root="",
               lang="zh",
               record_list=None):
    """生成airtest_report"""
    path, name = script_dir_name(script)
    rpt = LogToHtml(path,
                    log_root,
                    static_root=static_root,
                    export_dir=report_path(),
                    script_name=name,
                    lang=lang,
                    plugins=["poco.utils.airtest.report"])
    rpt.report(HTML_TPL, output_file=outfile, record_list=record_list)
Ejemplo n.º 6
0
def _airtest_report(htmlName):
    """
    自定义airtest报告输出,需要传入报告html文件名称

    :param htmlName: airtest报告输出的html文件
    :return: None
    """
    htmlName = os.path.join(tempDir, htmlName)
    path, name = script_dir_name(caseFileName)
    rpt = LogToHtml(
        path,
        reportLogDir,
        static_root="static/",
        logfile=LOGFILE,
        script_name=name,
    )
    rpt.report(HTML_TPL, output_file=htmlName)
Ejemplo n.º 7
0
def genReport(script,logPath,reportPath,outFile='log.html',lang='zh'):
    '''
    生成详细报告
    :param script:脚本路径
    :param logPath:日志路径
    :param reportPath:报告路径
    :param outFile:输出名字
    :param lang:语言
    :return:
    '''
    # script filepath
    path, name = script_dir_name(script)   #name  脚本的名字
    record_list = []
    log_root = decode_path(logPath)
    static_root = STATIC_DIR
    static_root = decode_path(static_root)
    export = decode_path(reportPath)
    lang = lang if lang in ['zh', 'en'] else 'en'
    plugins = ("poco.utils.airtest.report",)

    # gen html report
    rpt = LogToHtml(path, log_root, static_root, export_dir=export, script_name=name, lang=lang, plugins=plugins)
    rpt.report(HTML_TPL, output_file=outFile, record_list=record_list)
Ejemplo n.º 8
0
def report(task, log_path):
    """
    生成报告
    :param task: 前端配置的任务
    :param log_path:日志的路径
    :return:
    """
    path, name = script_dir_name(__file__)
    try:
        m = importlib.import_module('config')
        if task is not None:
            m.__author__ = task.name
        path, name = script_dir_name(m.__file__)
    except:
        try:
            m = importlib.import_module('library.author')
            if task is not None:
                m.__author__ = task.name
            path, name = script_dir_name(m.__file__)
        except:
            if task is not None:
                path, name = script_dir_name(sys.argv[0])

    static_root = {}
    if task is not None:
        static_root['static_root'] = 'http://localhost:9000/static'

    rpt = LogToHtml(script_root=path,
                    script_name=name,
                    export_dir=log_path,
                    **static_root,
                    log_root=log_path,
                    logfile=LOGFILE,
                    lang="zh",
                    plugins=["poco.utils.airtest.report"])
    rpt.report(HTML_TPL)
    return name.replace('.py', '') + '.log'
Ejemplo n.º 9
0
 def test_logtohtml_script_py(self):
     # script_root is .py
     script_py = os.path.join(OWL, self.SCRIPT_NAME + ".py")
     rpt_py = LogToHtml(script_py)
     rpt_py.report()
     self.assertTrue(os.path.exists(self.OUTPUT_HTML))
Ejemplo n.º 10
0
 def test_logtohtml_set_log(self):
     # set log_root
     rpt_logroot = LogToHtml(OWL, log_root=self.LOG_DIR)
     rpt_logroot.report()
     self.assertTrue(os.path.exists(self.OUTPUT_HTML))
Ejemplo n.º 11
0
 def test_logtohtml_default(self):
     # All parameters use default parameters
     rpt = LogToHtml(OWL)
     rpt.report()
     self.assertTrue(os.path.exists(self.OUTPUT_HTML))
Ejemplo n.º 12
0
 def test_output_file(self):
     rpt = LogToHtml(OWL)
     new_output_file = os.path.join(self.LOG_DIR, "new_log.html")
     rpt.report(output_file=new_output_file)
     self.assertTrue(os.path.exists(new_output_file))
     self.delete_path([new_output_file])