GithubHelp home page GithubHelp logo

seldomqa / xtestrunner Goto Github PK

View Code? Open in Web Editor NEW
166.0 11.0 129.0 13.29 MB

Modern style test report based on unittest framework.

License: Apache License 2.0

Python 57.41% HTML 42.59%
unittest python html

xtestrunner's Issues

【功能】如何添加非错误截图到报告中

如题,想添加一些操作完成后的截图到报告中
但是好像只能在源码中修改,自己有修改过源码可以用,但是错误截图不知道为什么都是空白图片的。
想问问如果要添加非错误截图是不是一定要修改源码?或者我下面代码需要怎样修改才能使错误截图也能生效
我原来的想法是通过输出截图名称,然后匹配改名称去获取我存储截图的路径,将路径添加到报告截图路径中

    if getattr(test, 'images', []):

        tmp = ""
        for i, img in enumerate(test.images):
            if i == 0:
                tmp += """<img src="data:image/jpg;base64,{}" style="display: block;" class="img"/>\n""".format(img)
            else:
                tmp += """<img src="data:image/jpg;base64,{}" style="display: none;" class="img"/>\n""".format(img)
        screenshots_html = CustomTemplate.IMG_TMPL.format(images=tmp)
    else:
        screenshots_html = """"""
        unum = str(uo).rfind('screenshot_')
        if (uo or ue) and unum != -1:
            hidde_status = ''
            left_key = str(uo).rfind('screenshot')
            right_key = str(uo).rfind('png')
            image_url = './images/' + str(uo)[left_key:right_key + 3].replace(' ', '')
            tmp += "<img src="+image_url + " class='img'/>\n"
            screenshots_html = CustomTemplate.IMG_TMPL.format(images=tmp)

HTMLTestRunner

你更改后的版本,我在python2.7.13版本可以使用,python3.6.1版本会报错

EF.1.2Traceback (most recent call last):
File "HTMLTestRunner.py", line 826, in
main(module=None)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/main.py", line 94, in init
self.runTests()
File "HTMLTestRunner.py", line 817, in runTests
unittest.TestProgram.runTests(self)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/main.py", line 255, in runTests
self.result = testRunner.run(self.test)
File "HTMLTestRunner.py", line 632, in run
self.generateReport(test, result)
File "HTMLTestRunner.py", line 689, in generateReport
self.stream.write(output.encode('utf8'))
TypeError: write() argument must be str, not bytes

发送邮件失败

1712660913288(1)
像上面这样写,发送邮件失败,报如下错误:
Traceback (most recent call last):
File "f:\work\python\POProject\test\case\test3.py", line 47, in
runner.send_email(
File "D:\software\python\lib\site-packages\XTestRunner\htmlrunner\runner.py", line 505, in send_email
smtp.sender(to=to, subject=subject, attachments=attachments)
File "D:\software\python\lib\site-packages\XTestRunner_email.py", line 91, in sender
smtp.starttls()
File "D:\software\python\lib\smtplib.py", line 805, in starttls
raise SMTPResponseException(resp, reply)
smtplib.SMTPResponseException: (454, b'Command not permitted when TLS active')

在linux容器中运行脚本时,没有执行到用例

run.py

if __name__ == '__main__':
    # 报告存放路径,可设置相对路径
    print(os.system('google-chrome --version'))
    print(os.system('chrome --version'))
    print(os.system('chromedriver -v'))
    rpfilepath = rpfolder
    filename = EmailConfData.attachment_html_filename
    file_path = rpfilepath + "/" + filename
    file_result = open(file_path, 'wb')
    # 定义测试报告
    runner = HTMLTestRunner(stream=file_result, title=u"**测试报告", description=u"**自动化测试", tester=u"chandler", rerun=2)
    # 运行测试用例
    suite = unittest.defaultTestLoader.discover(CommonDate.path+'/testcase', pattern='test*.py')
    print(suite)
    print(runner.run(suite))
    file_result.close()
    # 发送邮件
    send_emails()
    # 发送到飞书
    send_result_to_feishu()

Jenkins输入日志:

sh: 1: google-chrome: not found
32512
Google Chrome for Testing 118.0.5993.70 
0
ChromeDriver 118.0.5993.70 (e52f33f30b91b4ddfad649acddc39ab570473b86-refs/branch-heads/5993@{#1216})
0
headless_mode enable
Running on Linux
<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[<test_1_Login.TestLoginPage testMethod=test_1001_get_ver_code_with_error_phone>, <test_1_Login.TestLoginPage testMethod=test_1002_get_ver_code_with_error_email>, <test_1_Login.TestLoginPage testMethod=test_1003_login_with_error_ver_code_email>, <test_1_Login.TestLoginPage testMethod=test_1004_login_with_error_ver_code_phone>, <test_1_Login.TestLoginPage testMethod=test_1005_get_ver_code_with_empty_area_code>, <test_1_Login.TestLoginPage testMethod=test_1006_get_ver_code_with_empty_phone>, <test_1_Login.TestLoginPage testMethod=test_1007_get_ver_code_with_empty_email>, <test_1_Login.TestLoginPage testMethod=test_1008_get_ver_code_with_correct_phone>, <test_1_Login.TestLoginPage testMethod=test_1009_get_ver_code_with_correct_email>, <test_1_Login.TestLoginPage testMethod=test_1010_not_agree_policy_phone>, <test_1_Login.TestLoginPage testMethod=test_1011_not_agree_policy_email>, <test_1_Login.TestLoginPage testMethod=test_1012_login_with_phone_correct>]>]>, <unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[<test_2_Notes.TestNotesPage testMethod=test_2001_close_popup_windows>]>]>, <unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<test_3_BooxDrop.TestBooxDropPage testMethod=test_3001_push_file>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3002_repush_file>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3003_search_file>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3004_delete_file>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3005_cancel_delete_file>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3006_push_oversize_file>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3101_push_screensaver>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3102_search_screensaver>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3103_repush_screensaver>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3104_delete_screensaver>, <test_3_BooxDrop.TestBooxDropPage testMethod=test_3105_cancel_delete_screensaver>]>, <unittest.suite.TestSuite tests=[]>]>, <unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[<test_4_PushRead.TestPushReadPage testMethod=test_4001_push_url_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4002_push_error_url_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4003_create_folder_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4004_rename_folder_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4005_delete_cancel_folder_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4006_delete_folder_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4007_rename_url_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4008_edit_favorite_url_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4009_delete_cancel_url_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4010_delete_url_webpage>, <test_4_PushRead.TestPushReadPage testMethod=test_4101_create_rss_group>, <test_4_PushRead.TestPushReadPage testMethod=test_4102_rename_rss_group>, <test_4_PushRead.TestPushReadPage testMethod=test_4103_delete_rss_group>, <test_4_PushRead.TestPushReadPage testMethod=test_4201_create_opds_group>, <test_4_PushRead.TestPushReadPage testMethod=test_4202_rename_rss_group>, <test_4_PushRead.TestPushReadPage testMethod=test_4203_delete_opds_group>]>]>]>

XTestRunner Running tests...

----------------------------------------------------------------------
Generating HTML reports...
<XTestRunner.htmlrunner.result._TestResult run=0 errors=0 failures=0>
Done.
Finished: SUCCESS

从Jenkins运行日志看到suite是有内容的,但是runner.run(suite)打印出来是<XTestRunner.htmlrunner.result._TestResult run=0 errors=0 failures=0>,没有执行用例
同样的代码在本地的linux中运行可以正确运行全部用例,有人知道是什么回事吗

测试报告无法更新

执行test目录下的case,结果不会更新;尝试了其他方法 也无法生成最新的测试结果,麻烦帮忙解决一下

报告截图的一些问题和尝试

现象

前段时间用你没重构前的报告框架,在截图这块也尝试过在addError/addFailure方法中增加截图逻辑,这样业务层代码确实不需要再额外添加截图逻辑,但有一个问题:如果有tearDown逻辑,截图会在tearDown逻辑之后执行,会改变报错场景,得到无效的截图

解决方案

目前我这边最开始尝试的解决方案是重写unittest常用的断言方法,增加失败截图的逻辑,这样在fail的时候就会截到当时的图片;
但这样还存在一个问题:当case error时依然没法截到当时的图,最终的解决方案是在case层增加一层截图的装饰器

希望能展示 `subtest.msg` 而不是 `subtest.shortDescription`

class TestOdd(unittest.TestCase):
    def test_odd(self):
        """
        check if odd
        """
        for i in range(0, 5):
            with self.subTest(f"checking {i}", i=i):
                self.assertTrue(i % 2)

现在html里展示的是:

Test Group/Test Case Description
test_odd check if odd
test_odd check if odd
test_odd check if odd
test_odd check if odd
test_odd check if odd

希望展示的:

Test Group/Test Case Description
test_odd checking 0
test_odd checking 1
test_odd checking 2
test_odd checking 3
test_odd checking 4

我有试着直接去改,但直接判断 isinstance(test, unittest.case._SubTest) 没有效果

# XTestRunner/XTestRunner/htmlrunner/runner.py:line 431
doc = str(test) if isinstance(test, unittest.case._SubTest) else test.shortDescription() or ""

xml 格式的报告记录 注释

例如:

class PayPalTest(TestCase):
    """
    PayPal支付
    """

    def test_paypal_success(self):
        """paypal支付成功"""

类和方法的注释信息可以在 xml 报告中展示。

希望能加上去掉报告底部脚注的参数

在公司使用本模块生成的报告,底部都会自动加上脚注,个人觉得有影响(跟公司品牌互斥)。虽然说可以手动在模板中去掉,但是不可能每次都手动去修改。如果本项目是开源的话,我建议可以去掉脚注或者给可以去掉脚注的参数。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.