Pycharm执行Airtest脚本如何生成报告?

摘要

在Airtest IDE运行脚本后快捷键Ctrl+L可以很方便的查看测试报告,那么问题来了,也许很多同学像我一样喜欢用Pycharm工具编写测试脚本,在Pycharm执行测试脚本后怎么生成报告并能查看呢?

方法

Airtest提供了这个simple_report生成报告的接口。我们只要在脚本执行完后调用这个接口就会生成HTML测试报告。

可阅读Airtest API详细说明文档。

接口介绍

simple_report()
导入:from airtest.report.report import simple_report
生成报告的接口:simple_report(filepath, logpath=True, logfile=‘log.txt’, output=‘log.html’)
参数说明:

  • filepath:脚本文件的路径,可以直接传入变量__file__。
  • logpath :log 内容所在路径,如为 True ,则默认去当前脚本所在路径找 log 内容。
  • logfile :log.txt 的文件路径 。
  • output :报告的到处路径,必须以 .html 结尾 。

实例说明

这里用华为手机(HUAWEI nova3)做示例,打开相机APP,连续点击10次后关闭相机APP,最后生成测试报告。

from airtest.core.api import *
from airtest.core.android import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
from airtest.report.report import simple_report
import  unittest

popc=AndroidUiautomationPoco(use_airtest_input=True,screenshot_each_action=False)
auto_setup(__file__,logdir=True)

class CameraTest(unittest.TestCase):
    def setUp(self) -> None:
        # 启动相机
        snapshot(filename=r"D:\Airtest_Code\Airtest01\img\cameraStart.png",msg="已启动相机.")
        start_app("com.huawei.camera")
    def tearDown(self) -> None:
        # 关闭相机
        stop_app("com.huawei.camera")
        snapshot(filename=r"D:\Airtest_Code\Airtest01\img\cameraStop.png",msg="已关闭相机.")
        simple_report(__file__, logpath=True, logfile=r"D:\Airtest_Code\Airtest01\log\log.txt",
                      output=r"D:\Airtest_Code\Airtest01\log\log.html")
    def test01(self):
        # 用例1:打开相机,连续点击10次。
        i=0
        while(i<10):
            popc("com.huawei.camera:id/shutter_button").click()
            i=i+1
            print("第%d次点击相机。"%(i))
        return 0

if __name__ == '__main__':
    unittest.main()

执行结果

在这里插入图片描述

测试报告

测试报告在对应文件的路径里。
在这里插入图片描述

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值