第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

機器人框架 - 獲取變量

機器人框架 - 獲取變量

桃花長相依 2023-06-06 16:09:04
我正在嘗試使用 publicAPI 從report.xml文件中獲取變量值。這是報告的樣子:它有一個變量Var,并為其分配了一個測試值。我創(chuàng)建了簡單的 REST API 來運行測試:from flask import Flaskfrom flask import requestfrom robot import runfrom robot import run_cliapp = Flask(__name__)@app.route('/')def runRobot():?robotName = request.args.get('robot')?robotName = robotName + '.robot'?rc = run(robotName)?return str(rc)我想返回Var變量的值而不是執(zhí)行代碼。我在文檔中找不到符合我要求的匹配函數(shù)有可能做到嗎?
查看完整描述

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 文件中清晰可見。

http://img1.sycdn.imooc.com/647ee9d200019cdc06480248.jpg

這是控制臺輸出:

http://img4.sycdn.imooc.com/647ee9dd00011ecb06470269.jpg


查看完整回答
反對 回復 2023-06-06
  • 1 回答
  • 0 關注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號