Robotframework Listener throws “Cannot access execution context” error

前端 未结 1 1186
遇见更好的自我
遇见更好的自我 2021-01-05 11:07

In order to support an alternative logging format I\'ve started the development of a custom Robotframework Listener. Using the examples in the guide I\'ve been able to repli

相关标签:
1条回答
  • 2021-01-05 11:41

    You are trying to reference BuiltIn() before the test starts. That is what is meant by the error Cannot access execution context: the test hasn't started so there is no execution context. Simply put, you cannot access methods of the BuiltIn library before the test runs.

    You will have to wait to call that statement until after the test has started running.

    For example:

    class listener:
        ROBOT_LISTENER_API_VERSION = 2
    
        def start_suite(self, name, attrs):
            self.suite_source = BuiltIn().get_variable_value('${SUITE SOURCE}')
    

    However, if all you need is the source of the current suite, that information is available in the listener method start_suite.

    For example:

    class MyListener:
        ROBOT_LISTENER_API_VERSION = 2
    
        def start_suite(self, name, attrs):
            self.suite_source = attrs["source"]
    
    0 讨论(0)
提交回复
热议问题