1 回答

TA貢獻1810條經(jīng)驗 獲得超5個贊
對于這種情況,我可以想象的是一個自定義元數(shù)據(jù),您可以使用Set Suite Metadata關鍵字將其設置為您想要的任何值。
然后您可以創(chuàng)建一個小的ResultVisitor來檢索所需的元數(shù)據(jù)。我在下面的示例中使用 Robot Framework 3.1.2。
示例(SO.robot):
***?Test?Cases?*** Test? ???Set?Suite?Metadata????My?Return?Value????My?VALUE????append=True????top=True
調(diào)用 Robot CLI 和 ResultVisitor 的 Python 文件:
from robot import run_cli
from robot.api import ExecutionResult, ResultVisitor
class ReturnValueFetcher(ResultVisitor):
? ? def __init__(self):
? ? ? ? self.custom_rc = None
? ? def visit_suite(self, suite):
? ? ? ? try:
? ? ? ? ? ? self.custom_rc = suite.metadata["My Return Value"]
? ? ? ? except KeyError:
? ? ? ? ? ? self.custom_rc = 'Undefined' # error, False, exception, log error, etc.
? ? ? ??
? ? ? ? # Only visit the top suite
? ? ? ? return False
# Run robot, exit=False is needed so the script won't be terminated here
rc = run_cli(['SO.robot'], exit=False)
# Instantiate result visitor
retval = ReturnValueFetcher()
# Parse execution result using robot API
# assuming the output.xml is in the same folder as the Python script
result = ExecutionResult("./output.xml")
# Visit the top level suite to retrive needed metadata
result.visit(retval)
# Print return values
print(f"normal rc:{rc} - custom_rc:{retval.custom_rc}")
您的自定義返回值也將在您的 log.html 和 report.html 文件中清晰可見。
這是控制臺輸出:
添加回答
舉報