自动化运行后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,重新运行自动化程序,报告生成。

相关推荐
belldeep11 分钟前
python:genesis-world, Genesis-Embodied-AI
人工智能·python·ai·genesis
benchmark_cc1 小时前
A 股、港股、美股如何建立统一的标的主数据格式?
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
维克兜率天2 小时前
【维克】趋势型CTA:期货市场的“追涨杀跌“
人工智能·python
天远Date Lab2 小时前
零信任架构实战:基于天远租凭分期报告构建自动化汽车以租代购免押风控网关
网络·人工智能·架构·自动化
取名真是2 小时前
Python 算法知识点从基础到进阶
开发语言·python·算法
vibecode2 小时前
网站服务器失去响应怎么解决?我把连接超时和读超时这两段计时拆开跑了一遍
运维·服务器
梦想不只是梦与想3 小时前
PyTorch、CPU、GPU、CUDA
人工智能·pytorch·python·深度学习·机器学习·cuda
数字融合3 小时前
透明化视频孪生危化安全管控解决方案
人工智能·python·安全
工业一体机老司机3 小时前
Docker部署工控机采集服务 Compose编排与开机自启
运维·docker·容器
迪康Defender4 小时前
终端供应链安全:应用白名单与软件正版化检测落地|终端安全治理实践
运维·服务器·网络·安全·web安全·自动化·运维开发