html tool

2019年3月19日星期二

robotframe的listener



参考:
https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/ExtendingRobotFramework/ListenerInterface.rst#listener-examples

说明:


robot 的listener可以在robot运行中监听当前运行test的内容:
 start.end.status 等,具体参见:

https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/ExtendingRobotFramework/ListenerInterface.rst#listener-version-3

这里区分robot2/3是不同的,

下面是官方的demo for robot3,测试通过了,现在想想可以解决修改testsuit name的问题,其他功能还有待发掘。不过这个listener现在感觉是robot运行过程中的一个对话监控者。
如果有其他辅助信息,可以使用它做其他的传导。

eg:


If the above example would be saved to, for example, :file:`PauseExecution.py` file, it could be used from the command line like this:
robot --listener path/to/PauseExecution.py tests.robot
The same example could also be implemented also using the newer listener version 3 and used exactly the same way from the command line.
"""Listener that stops execution if a test fails."""

ROBOT_LISTENER_API_VERSION = 3

def end_test(data, result):
    if not result.passed:
        print('Test "%s" failed: %s' % (result.name, result.message))
        raw_input('Press enter to continue.') #这个检测可以发现测试停止了,
     #说明listener 和robot是使用一个线程的,不是两个,这个要注意,但是listener中错误应是
     #被封装了,在robot运行中是不会看到listener的错误的:),留心不报错的代码执行问题。

The next example, which still uses Python, is slightly more complicated. 

Modifying execution and results

These examples illustrate how to modify the executed tests and suites as well as the execution results. All these examples require using the listener version 3.

Modifying executed suites and tests

Changing what is executed requires modifying the model object containing the executed `test suite <running.TestSuite_>`__or `test case <running.TestCase_>`__ objects passed as the first argument to start_suite and start_test methods. This is illustrated by the example below that adds a new test to each executed test suite and a new keyword to each test.
ROBOT_LISTENER_API_VERSION = 3

def start_suite(suite, result):
    suite.tests.create(name='New test')

def start_test(test, result):
    test.keywords.create(name='Log', args=['Keyword added by listener!'])

Trying to modify execution in end_suite or end_test methods does not work, simply because that suite or test has already been executed. Trying to modify the name, documentation or other similar metadata of the current suite or test in start_suite or start_test method does not work either, because the corresponding result object has already been created. Only changes to child tests or keywords actually have an effect.

没有评论:

发表评论