![](/img/trans.png)
[英]Test Setup and Teardown for each test case in a test suite in Robot Framework using python
[英]Global test hook or global test teardown for each test in robot framework
我想在每次測試之前/之后運行某種掛鈎機制。 例如,如果我為每個測試將ARGUMENT=1
傳遞給pybot或python,則要運行關鍵字,而不修改項目中的整個測試。
可能嗎?
以類似的方式,您可以在黃瓜框架上創建一個before或after鈎子,但是在這里。 我還不明白。
謝謝。
我猜您正在尋找: 套件設置和套件拆卸
或者也許是測試設置和測試拆解
套件設置示例:
*** Settings ***
Library DatabaseLibrary
Force Tags UI FINAL
Resource ${CURDIR}${/}..${/}..${/}resources${/}keywords.robot
Suite setup Run Keywords Restore database
... Prepare database
Suite teardown Run Keywords Close All Browsers
... Restore database
*** Keywords ***
Prepare database
Connect to DB
Execute Sql Script ${CURDIR}${/}Setup_td.sql
Disconnect From Database
Restore database
Connect to DB
Execute Sql Script ${CURDIR}${/}Teardown_td.sql
Disconnect From Database
我自己找到了答案。 您應該創建新的偵聽器以用於測試掛鈎。
關於機器人監聽器: 機器人框架監聽器界面
# -*- coding: utf-8 -*-
from robot.libraries.BuiltIn import BuiltIn
class global_hooks(object):
"""
Global scope library listener
as global hook mechanism.
"""
ROBOT_LISTENER_API_VERSION = 3
ROBOT_LIBRARY_SCOPE = "GLOBAL"
def __init__(self):
self.ROBOT_LIBRARY_LISTENER = self
def __log_variables(self):
"""
Example private function.
"""
if BuiltIn().get_variable_value(name='${SOME_VAR}', default=False):
BuiltIn().run_keyword(name=self.log_test_variables.__name__)
def end_test(self, data, result):
""" The `end test` hook """
self.__log_variables()
def log_test_variables(self):
"""
Keyword for showing up all variables in the test context.
"""
BuiltIn().log_variables(level='INFO')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.