自动化运行后BeautifulReport内容为空

一、问题描述

自动化程序运行后发现运行目录下生成的html报告文件内容为空,没有运行结果。

二、测试环境

  1. 操作系统:Windows 11 家庭版
  2. BeautifulReport:0.1.3
  3. Python:3.11.9
  4. Appium-Python-Client:5.0.0
  5. Appium Server:2.17.1

三、源代码

复制代码
import unittest
import os

from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
from BeautifulReport import BeautifulReport  # 导入 BeautifulReport

capabilities = dict(
    platformName='Android',
    automationName='uiautomator2',
    deviceName='Android',
    appPackage='com.android.settings',
    appActivity='.Settings',
    language='en',
    locale='US'
)

appium_server_url = 'http://localhost:4723'

class TestAppium(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities))

    def tearDown(self) -> None:
        if self.driver:
            self.driver.quit()

    def test_find_battery(self) -> None:
        el = self.driver.find_element(by=AppiumBy.XPATH, value='//*[@text="Battery"]')
        el.click()


if __name__ == '__main__':
    report_dir = './reports'
    if not os.path.exists(report_dir):
        os.makedirs(report_dir)
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestAppium))
    runner = BeautifulReport(suite)
    runner.report(
        filename='test_report.html',  # 报告文件名
        description='Appium Test Report',  # 报告描述
        report_dir=report_dir  # 报告保存路径
    )

四、解决办法

报告模板中的资源加载失败。修改 BeautifulReport 的模板文件 template.html

1.template.html文件位置

作者的位置如下,每个人自己的路径不一样,仅供参考。

html 复制代码
C:\Users\PAL\AppData\Roaming\Python\Python311\site-packages\BeautifulReport\template

2.替换

替换成下面的 CSS 和 JavaScript 链接

html 复制代码
<!-- CSS -->
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.0.0-beta3/css/fontawesome.css" rel="stylesheet">
<link href="https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.min.css" rel="stylesheet">
<link href="https://cdn.bootcdn.net/ajax/libs/chosen/1.8.8.rc6/chosen.css" rel="stylesheet">

<!-- JavaScript -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.2.2/echarts.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/chosen/1.8.8.rc6/chosen.jquery.js"></script>

3.保存

修改后保存template.html,重新运行自动化程序,报告生成。

相关推荐
Flash.kkl6 小时前
Linux——进程信号
运维·服务器
苏宸啊7 小时前
Linux权限
linux·运维·服务器
多米Domi0117 小时前
0x3f第33天复习 (16;45-18:00)
数据结构·python·算法·leetcode·链表
Gofarlic_oms17 小时前
Windchill用户登录与模块访问失败问题排查与许可证诊断
大数据·运维·网络·数据库·人工智能
freepopo7 小时前
天津商业空间设计:材质肌理里的温度与质感[特殊字符]
python·材质
森叶7 小时前
Java 比 Python 高性能的原因:重点在高并发方面
java·开发语言·python
xqhoj7 小时前
Linux——make、makefile
linux·运维·服务器
文亭湖畔程序猿8 小时前
Debian 12 日常命令 & nano 快捷键速查表
运维·debian
张童瑶8 小时前
Linux 在线安装编译Python3.11
linux·运维·python3.11
ziqibit8 小时前
debian Live with Persistence 持久化U盘的debian系统
运维·debian