Stop time
Time measurement during a test can be very helpful. The
Read the next example and you will understand the mix of different time lines:
XML DSL
<testcase name="StopTimeTest">
<actions>
<trace-time/>
<trace-time id="time_line_id"/>
<sleep seconds="3.5"/>
<trace-time id=" time_line_id "/>
<sleep milliseconds="5000"/>
<trace-time/>
<trace-time id=" time_line_id "/>
</actions>
</testcase>
Java DSL
@CitrusTest
public void stopTimeTest() {
stopTime();
stopTime("time_line_id");
sleep(3.5); // do something
stopTime("time_line_id");
sleep(5000); // do something
stopTime();
stopTime("time_line_id");
}
The test output looks like follows:
Starting TimeWatcher:
Starting TimeWatcher: time_line_id
TimeWatcher time_line_id after 3500 milliseconds
TimeWatcher after 8500 seconds
TimeWatcher time_line_id after 8500 milliseconds
Important Time line ids should not exist as test variables before the action is called for the first time. This would break the time line initialization.
Note
In case no time line id is specified the framework will measure the time for a default time line. To print out the current elapsed time for a time line you simply have to place the
`
Each time line is stored as test variable in the test case. By default you will have the following test variables set for each time line:
- CITRUS_TIMELINE first timestamp of time line
- CITRUS_TIMELINE_VALUE latest time measurement value (time passed since first timestamp in milliseconds)
According to your time line id you will get different test variable names. Also you can customize the time value suffix (default: _VALUE):
XML DSL
<trace-time id="custom_watcher" suffix="_1st"/>
<sleep/>
<trace-time id="custom_watcher" suffix="_2nd"/>
Java DSL
@CitrusTest
stopTime("custom_watcher", "_1st");
sleep();
stopTime("custom_watcher", "_2nd");
You will get following test variables set:
- custom_watcher first timestamp of time line
- custom_watcher_1st time passed since start
- custom_watcher_2nd time passed since start
Of course using the same suffix multiple times will overwrite the timestamps in test variables.