forked from laurentbristiel/elapsed_by_keyword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elapsed_by_keyword.py
executable file
·36 lines (27 loc) · 1.03 KB
/
elapsed_by_keyword.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
"""Usage: elapsed_by_keyword inpath
Reads result of a test run from Robot output file
and returns the list of all the keywords on the standard output
sorted by the elapsed time in each keyword
"""
import sys
from robot.api import ExecutionResult, ResultVisitor
class ExecutionKeywordStats(ResultVisitor):
def __init__(self):
self.elapsed_by_kw = {}
def end_keyword(self, keyword):
if keyword.name in self.elapsed_by_kw:
self.elapsed_by_kw[keyword.name] = self.elapsed_by_kw[keyword.name] + keyword.elapsedtime
else:
self.elapsed_by_kw[keyword.name] = keyword.elapsedtime
def stats_by_keywords(inpath):
result = ExecutionResult(inpath)
visitor = ExecutionKeywordStats()
result.visit(visitor)
for kw in sorted(visitor.elapsed_by_kw, key=visitor.elapsed_by_kw.get, reverse=True):
print kw, visitor.elapsed_by_kw[kw]
if __name__ == '__main__':
try:
stats_by_keywords(*sys.argv[1:])
except TypeError:
print __doc__