亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

用戶關鍵字的 robot.running.model.Keyword 對象子屬性在

用戶關鍵字的 robot.running.model.Keyword 對象子屬性在

Cats萌萌 2023-06-06 17:31:30
我有一個簡單的預運行修改器,start_suite它實現了從變量中獲取套件設置關鍵字suite并打印其屬性的功能。該對象是類的實例robot.running.model.Keyword,這是該類的文檔。name、關鍵字和type屬性是正確的id,parent但timeout、doc、tags、children屬性不返回任何內容。keywords它與和屬性相同messages。下面是我的簡化代碼示例和輸出。我希望有以下子項:Log、Log Many、No Operation。是否可以像這樣在預運行修飾符中獲取這些關鍵字的名稱(和參數)?我正在使用 robotframework==3.1.2。這是套件文件 (test.robot):*** Settings ***Suite Setup? ? Custom Suite Setup Keyword*** Test Cases ***A test? ? No Operation? ??*** Keywords ***Custom Suite Setup Keyword? ? [Timeout]? ? 2 min? ? [Documentation]? ? It is a keyword doc.? ? [Tags]? ? 1TAG? ? 2TAG? ? Log? ? 1st child? ? Log Many? ? 2nd? ? child? ? No Operation? ? [Teardown]? ? My Keyword Teardown? ??My Keyword Teardown? ? Log? ? ?teardown這是預運行修改器 (modifier.py):from robot.api import SuiteVisitorfrom robot.libraries.BuiltIn import BuiltInclass MyModifier(SuiteVisitor):? ? def __init__(self):? ? ? ? self._BuiltIn = BuiltIn()? ? ? ??? ??? ? def start_suite(self, suite):? ? ? ? self._BuiltIn.log_to_console(f'suite keywords - {suite.keywords}')? ? ? ? self._BuiltIn.log_to_console(f'class? ? ? ? ? - {type(suite.keywords.setup)}')? ? ? ? self._BuiltIn.log_to_console(f'name? ? ? ? ? ?- {suite.keywords.setup.name}')? ? ? ? self._BuiltIn.log_to_console(f'id? ? ? ? ? ? ?- {suite.keywords.setup.id}')? ? ? ? self._BuiltIn.log_to_console(f'parent(suite)? - {suite.keywords.setup.parent}')? ? ? ? self._BuiltIn.log_to_console(f'timeout? ? ? ? - {suite.keywords.setup.timeout}')? ? ? ? self._BuiltIn.log_to_console(f'type? ? ? ? ? ?- {suite.keywords.setup.type}')? ? ? ? self._BuiltIn.log_to_console(f'doc? ? ? ? ? ? - {suite.keywords.setup.doc}')? ? ? ? self._BuiltIn.log_to_console(f'tags? ? ? ? ? ?- {suite.keywords.setup.tags}')? ? ? ? self._BuiltIn.log_to_console(f'children? ? ? ?- {suite.keywords.setup.children}')
查看完整描述

2 回答

?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

我設法在 Robot Framework 的API 文檔中找到了相關部分。我想要實現的目標是不可能的。

訪問者可以很容易地修改測試套件結構或從中收集信息。它們與executable model和 一起工作result model,但傳遞給訪問者方法的對象根據它們所使用的模型略有不同。主要?區別在于,在執行端關鍵字沒有子?關鍵字或消息,并且只有結果對象具有與狀態相關的屬性,如statusstarttime。


查看完整回答
反對 回復 2023-06-06
?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

使用 Robot Framework 4.0,如果用作套件設置的關鍵字是在套件本身內實現的,也就是套件擁有關鍵字,則這是可能的。該屬性的文檔說:robot.running.model.TestSuite?resource

ResourceFile包含套件擁有的導入、變量和關鍵字的實例。從文件系統解析數據時,該數據來自創建套件的同一個測試用例文件。

因此可以在對象列表中找到子關鍵字及其參數suite.resource.keywords

from robot.api import SuiteVisitor


class Visitor(SuiteVisitor):

? ??

? ? def start_suite(self, suite):

? ? ? ? for keyword in suite.resource.keywords:

? ? ? ? ? ? if suite.setup.name == keyword.name:

? ? ? ? ? ? ? ? for item in keyword.body:

? ? ? ? ? ? ? ? ? ? print(f'{item.name} - {item.args} - {item.type}')


? ? ? ? ? ? ? ? if keyword.teardown.name:

? ? ? ? ? ? ? ? ? ? print(f'{keyword.teardown.name} - {keyword.teardown.args} - {keyword.teardown.type}')

這打?。?/p>


Log - ('1st child',) - KEYWORD

Log Many - ('2nd', 'child') - KEYWORD

No Operation - () - KEYWORD

My Keyword Teardown - () - TEARDOWN

同樣,如果 user 關鍵字是在導入的資源文件中而不是在套件文件本身中實現的,這將不起作用。


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

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號