Robot Framework 自定义执行状态 [英] Customized Execution status in Robot Framework

查看:41
本文介绍了Robot Framework 自定义执行状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Robot Framework 中,每个测试用例的执行状态可以是 PASS 或 FAIL.但是我有一个特定要求,当由于依赖关系而失败时,将少数测试标记为 NOT EXECUTED.

我不确定如何实现这一目标.我需要专家的建议才能继续前进.

解决方案

在实现 SKIP 状态之前,您可以使用

In Robot Framework, the execution status for each test case can be either PASS or FAIL. But I have a specific requirement to mark few tests as NOT EXECUTED when it fails due to dependencies.

I'm not sure on how to achieve this. I need expert's advise for me to move ahead.

解决方案

Until a SKIP status is implemented, you can use exitonfailure to stop further execution if a critical test failed, and then change the output.xml (and the tests results.html) to show those tests as "NOT_RUN" (gray color), rather than "FAILED" (red color).

Here's an example (Tested on RobotFramework 3.1.1 and Python 3.6):

First create a new class that extends the abstract class ResultVisitor:

class ResultSkippedAfterCritical(ResultVisitor):

    def visit_suite(self, suite):
        suite.set_criticality(critical_tags='Critical')
        for test in suite.tests:
            if test.status == 'FAIL' and "Critical failure occurred" in test.message:
                test.status = 'NOT_RUN'
                test.message = 'Skipping test execution after critical failure.'

Assuming you've already created the suite (for example with TestSuiteBuilder()), run it without creating report.html and log.html:

outputDir = suite.name.replace(" ", "_") 
outputFile = "output.xml"

logger.info(F"Running Test Suite: {suite.name}", also_console=True)
result = suite.run(output=outputFile, outputdir=outputDir, \
         report=None, log=None, critical='Critical', exitonfailure=True)

Notice that I've used "Critical" as the identifing tag for critical tests, and exitonfailure option.

Then, revisit the output.xml, and create report.html and log.html from it:

revisitOutputFile = os.path.join(outputDir, outputFile)
logger.info(F"Checking skipped tests in {revisitOutputFile} due to critical failures", also_console=True)
result = ExecutionResult(revisitOutputFile) 
result.visit(ResultSkippedAfterCritical())
result.save(revisitOutputFile)

reportFile = 'report.html'
logFile = 'log.html'
logger.info(F"Generating {reportFile} and {logFile}", also_console=True)
writer = ResultWriter(result)
writer.write_results(outputdir=outputDir, report=reportFile, log=logFile)

It should display all the tests after the critical failure with grayed status = "NOT_RUN":

这篇关于Robot Framework 自定义执行状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆