2016-04-29 39 views

回答

1

我找到了答案由我自己。 您應該創建新的偵聽器以用於測試掛鉤。

關於機器人的聽衆: Robot Framework Listener Interface

# -*- 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') 
2

我猜你正在尋找: Suite setup and Suite teardown

或許套件安裝的Test setup and Test teardown

例子:

*** 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 
+0

謝謝您的時間,@michel。在你的回答中:我應該在每個測試套件中寫下這個拆解。我不想這樣做。我用偵聽器接口來實現這個目標。 –