Jiri Janous
Jiri Janous

Reputation: 1242

Show time in console output of robotframework

Is it possible to show time in console output of robotframework. Normally the output looks this way.

==============================================================================
Example test suite
==============================================================================
First test :: Possible test documentation                             | PASS |
------------------------------------------------------------------------------
Second test                                                           | FAIL |
Error message is displayed here
==============================================================================
Example test suite                                                    | FAIL |
2 critical tests, 1 passed, 1 failed
2 tests total, 1 passed, 1 failed
==============================================================================

I would like to see information about how long did the test run in the console. I tried adding option --console verbose to the robot command, but I didn’t notice any change.

You can see this information in the report that is outputted, but what if you don’t get to that point and just want to see which test is slowing down the test suite execution.

Upvotes: 1

Views: 1437

Answers (2)

Bence Kaulics
Bence Kaulics

Reputation: 7271

You can create a small listener, where with the end_test method you can get the start time, end time and elapsed time during execution. You can print them to the console from the listener.

ROBOT_LISTENER_API_VERSION = 3

def end_test(data, result):
    print(f'\nStart time: {result.starttime}')
    print(f'End time: {result.endtime}')
    print(f'Elapsed time: {result.elapsedtime}')

Example:

*** Test Case ***
Test case 1
    Sleep    1 sec
    
Test case 2
    Sleep    2 sec

Test case 3
    Sleep    3 sec
    Fail    Do a fail.

Test case 4
    Sleep    4 sec

Execute like: robot --listener listener.py test.robot

Output on console:

==============================================================================
Test
==============================================================================
Test case 1
Start time: 20210105 10:19:47.711
End time: 20210105 10:19:48.712
Elapsed time: 1001
| PASS |
------------------------------------------------------------------------------
Test case 2
Start time: 20210105 10:19:48.712
End time: 20210105 10:19:50.714
Elapsed time: 2002
| PASS |
------------------------------------------------------------------------------
Test case 3
Start time: 20210105 10:19:50.715
End time: 20210105 10:19:53.716
Elapsed time: 3001
| FAIL |
Do a fail.
------------------------------------------------------------------------------
Test case 4
Start time: 20210105 10:19:53.716
End time: 20210105 10:19:57.719
Elapsed time: 4003
| PASS |
------------------------------------------------------------------------------
Test                                                                  | FAIL |
4 critical tests, 3 passed, 1 failed
4 tests total, 3 passed, 1 failed
==============================================================================

Upvotes: 2

pavelsaman
pavelsaman

Reputation: 8322

I don't think this is possible with the default logger. But you can use listener interface and create your own logger.

For example methods end_test and end_suite from listener interface 3 provide a result argument, which is an object with all sorts of properties like starttime, endtime, and elapsedtime. You might be interested in these.

A short example how to use this:

time_loger.py

ROBOT_LISTENER_API_VERSION = 3

def end_test(data, result):
    print('Test started: ' + result.starttime);
    print('Test ended: ' + result.endtime);

and I execute my tests in a way that only my new logger will print messages to console:

$ robot --listener time_logger.py --console quiet test.robot

which gives me this output:

Test started: 20210105 10:17:30.377
Test ended: 20210105 10:17:32.380

Upvotes: 3

Related Questions