Skip to content

生成的log.html无法正常加载 #1287

@lihuaming07

Description

@lihuaming07

(请尽量按照下面提示内容填写,有助于我们快速定位和解决问题,感谢配合。否则直接关闭。)

(重要!问题分类)
airtest.report.report

  • 图像识别、设备控制相关问题 -> 按下面的步骤

描述问题bug
使用

# E:\LHM\Python\Auto_Programe\小游戏赚钱.air\logs\28071
simple_report(__file__, logpath=logdir, output=logdir + f'/log_{ID}.html')

生成了一份log.html
以下是浏览器控制台报错

Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/report.css
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/jquery-1.10.2.min.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/jquery-lang.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/langpack/zh_CN.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/lazyload.js
log_28071.html?_ijt=h92v8mh06dh8t1shmp1amsuho8&_ij_reload=RELOAD_ON_SAVE:22 Uncaught ReferenceError: Lang is not defined
    at log_28071.html?_ijt=h92v8mh06dh8t1shmp1amsuho8&_ij_reload=RELOAD_ON_SAVE:22:7
log_28071.html:210 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/monokai_sublime.min.css
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/download_log.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/copy.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/Airtest.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/poco.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/AirtestIDE.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/AirLab.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/netease.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/minimize.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/close.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/maximize.svg
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/highlight.min.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/paging.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/report.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/report.css
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/monokai_sublime.min.css
Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/report.css
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/jquery-1.10.2.min.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/jquery-lang.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/langpack/zh_CN.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/lazyload.js
log_28071.html?_ijt=h92v8mh06dh8t1shmp1amsuho8&_ij_reload=RELOAD_ON_SAVE:22 Uncaught ReferenceError: Lang is not defined
    at log_28071.html?_ijt=h92v8mh06dh8t1shmp1amsuho8&_ij_reload=RELOAD_ON_SAVE:22:7
log_28071.html:210 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/monokai_sublime.min.css
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/download_log.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/copy.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/Airtest.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/poco.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/AirtestIDE.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/AirLab.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/netease.png
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/minimize.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/close.svg
log_28071.html:211 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/image/maximize.svg
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/highlight.min.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/paging.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/js/report.js
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/report.css
log_28071.html:1 Not allowed to load local resource: file:///C:/Users/35324/AppData/Local/Programs/Python/Python312/Lib/site-packages/airtest/report/css/monokai_sublime.min.css

相关截图

Image

复现步骤

  1. 项目代码
    小游戏赚钱.py:
# -*- encoding=utf8 -*-
from pathlib import Path
import os
from airtest.core.api import *
from airtest.core import android
from airtest.report.report import simple_report

using("E:/LHM/Python/Auto_Programe/小游戏赚钱.air")
# package_manage 是我的一个内部文件,包含package_names和game_2_pkg_name两个变量,影响不大
import package_manage as pkg_manage


@logwrap
def uninstall_third_party():
    log("卸载游戏和游戏任务软件")
    apps = dev.list_app(third_only=True)
    log(apps)
    games_pkg_names = pkg_manage.package_names
    print(games_pkg_names)
    for app in apps:
        if app in games_pkg_names:
            uninstall(app)
    if pkg_manage.game_2_pkg_name in apps:
        uninstall(pkg_manage.game_2_pkg_name)


# 生成当前设备的日志目录
# ID是通过launch.py文件传入的全局变量
ID = "28071"
logdir = os.path.join(Path(__file__).parent, 'logs', ID)
log(f'log_dir:{logdir}')
os.makedirs(logdir, exist_ok=True)
auto_setup(__file__, logdir=logdir, compress=1)

dev = device()
uninstall_third_party()
home()
touch((266, 1056))
touch((451,1056))
simple_report(__file__, logpath=logdir, output=logdir + f'/log_{ID}.html')

launch.py:

# 教程:https://mp.weixin.qq.com/s?__biz=MzUxMDc4NTkwMA==&mid=2247485616&idx=1&sn=87c0fb6da743b093a0e903d2df76e47e&chksm=f97ce8b3ce0b61a53909e916438f24fcd3b7191991dcadfa6a7963f19101cb87c3aa98647234&token=1051694015&lang=zh_CN#rd
from airtest.cli.runner import AirtestCase, run_script
from airtest.cli.parser import runner_parser


class CustomAirtestCase(AirtestCase):
    def setUp(self):
        # 在air脚本运行之前获取这个自定义的参数
        if self.args.ID:
            self.scope['ID']=self.args.ID

if __name__ == '__main__':
    ap = runner_parser()
    # 添加自定义的命令行参数,不能用小写id,会和python内置函数冲突
    ap.add_argument(
        "--ID", help="The id of the device")
    args = ap.parse_args()
    run_script(args, CustomAirtestCase)

generate_log.py:

import os
from pathlib import Path
import subprocess, traceback



def run_one_report(air, devID):
    """"
        生成一个脚本的测试报告
        Build one test report for one air script
    """
    try:
        log_dir = str(os.path.join(Path(air), 'logs', devID))
        log = str(os.path.join(log_dir, 'log.txt'))
        if os.path.isfile(log):
            cmd = [
                "airtest",
                "report",
                air,
                "--log_root",
                log_dir,
                "--outfile",
                os.path.join(log_dir, 'log.html'),
                "--lang",
                "zh"
            ]
            print(cmd)
            ret = subprocess.call(cmd, shell=True, cwd=os.getcwd())
            return {
                'status': ret,
                'path': os.path.join(log_dir, 'log.html')
            }
        else:
            print("Report build Failed. File not found in dir %s" % log)
    except Exception as e:
        traceback.print_exc()
    return {'status': -1, 'device': devID, 'path': ''}


if __name__ == '__main__':
    for i in range(71, 83): # 遍历所有logs
        ret = run_one_report(air=str(Path(__file__).parent), devID='280' + str(i))

2.在项目文件夹下打开命令行,运行

chcp 65001
python launcher.py E:/LHM/Python/Auto_Programe/小游戏赚钱.air --device Android:///42.XX.XX.94:28071 --ID 28071
  1. 打开小游戏赚钱.air/logs/28071/log.html
  2. See error
    预期效果

Image

python 版本: python3.12

airtest 版本: 1.3.5

设备:

  • 型号: [深度定制云机]
  • 系统: [Android 12]

其他相关环境信息
Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions