关于airtest生成的报告中缺少poco语句问题

1、airtest生成的报告只显示airtest的相关操作,如果是poco和airtest-selenium的操作则不记录。因此需要在报告中引用插件。

  • 支持poco语句插件,poco.utils.airtest.report
  • 支持airtest-selenium语句插件,airtest_selenium.report

2、在IDE运行 .py脚本报告生成的依据是脚本运行时保存的log内容,所以我们在运行 .py 脚本时,必须要保存log内容,否则后续将生成无log内容的airtest报告,即空的报告。那么我们就需要设置log的路径并传给logdir。

log_path=r"D:\lianxi\airtest_study\report"
auto_setup(__file__,logdir=log_path)

 在用例的最后面需要引用报告插件,plugins 。

 3、如果是生成简单的报告,只需在脚本中调用接口simple_report()。

simple_report(filepath, logpath=True, logfile='log.txt', output='log.html')

对应参数:

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

4、如果需要记录poco和airtest-selenium的操作,则需要使用LogToHtml类。

class LogToHtml(script_root, log_root='', static_root='', export_dir=None, script_name='', logfile='log.txt', lang='en', plugins=None)

对应参数:

  • script_root ,脚本路径
  • log_root ,log文件的路径
  • static_root ,部署静态资源的服务器路径
  • export_dir ,导出报告的存放路径
  • script_name ,脚本名称
  • logfile ,log文件log.txt的路径
  • lang ,报告的语言(中文:zh;英文:en)
  • plugins ,插件,记录poco或者airtest-selenium操作

5、生成的报告如下:

 

# -*- encoding=utf8 -*-
__author__ = "Zoe"

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

poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)

log_path=r"D:\lianxi\airtest_study\report"

auto_setup(__file__,logdir=log_path)

start_app("tv.danmaku.bili")
sleep(4.0)

poco(text="首页").wait_for_appearance()

assert_equal(poco(text="首页").exists(),True,"断言进入首页")

poco(text="我的").click()

poco(text="账号密码登录").wait_for_appearance()

poco(text="账号密码登录").click()

poco(text="账号密码登录").wait_for_appearance()

assert_equal(poco(text="账号密码登录").exists(),True,"断言进入登录页")

# 生成包含poco脚本的Airtest报告
h1 = LogToHtml(script_root=__file__, log_root=log_path, lang='zh', plugins=['poco.utils.airtest.report'])
h1.report(output_file=r"D:\lianxi\airtest_study\report\poco_report.html")

 

posted @ 2024-07-04 16:46  Zoe_Luck  阅读(3)  评论(0编辑  收藏  举报