Skip to content

Commit 7d770be

Browse files
committed
Include ignore library and ignore type
1 parent 2d01946 commit 7d770be

File tree

6 files changed

+85
-46
lines changed

6 files changed

+85
-46
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Creates awesome HTML (dashboard view) report by parsing robotframework output.xm
1111
---
1212
- __Sample Report__ [link](https://robotmetrics.netlify.com/)
1313

14-
- Whats new in __v3.2.1__ [link](https://github.com/adiralashiva8/robotframework-metrics/releases/tag/v3.2.1)
14+
- Whats new in __v3.2.2__ [link](https://github.com/adiralashiva8/robotframework-metrics/releases/tag/v3.2.2)
1515

1616
- Source Code used to parse output.xml in metrics report [link](https://adiralashivaprasad.blogspot.com/2019/01/how-to-get-suite-test-and-keyword.html)
1717

@@ -33,7 +33,7 @@ __Step 1__ Install robotmetrics
3333

3434
> Case 1: Using pip
3535
```
36-
pip install robotframework-metrics==3.2.1
36+
pip install robotframework-metrics==3.2.2
3737
```
3838
> Case 2: Using setup.py (clone project and run command within root)
3939
```

robotframework_metrics/keyword_results.py

+42-30
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
class KeywordResults(ResultVisitor):
55

6-
def __init__(self, soup, tbody, ignore_type):
6+
def __init__(self, soup, tbody, ignore_lib, ignore_type):
77
self.test = None
88
self.soup = soup
99
self.tbody = tbody
10+
self.ignore_library = ignore_lib
1011
self.ignore_type = ignore_type
1112

1213
def start_test(self, test):
@@ -19,37 +20,48 @@ def start_keyword(self, kw):
1920
# Get test case name (Credits: Robotframework author - Pekke)
2021
test_name = self.test.name if self.test is not None else ''
2122

22-
keyword_type = kw.type
23-
if any(library in keyword_type for library in self.ignore_type):
23+
# Ignore library keywords
24+
keyword_library = kw.libname
25+
26+
if not keyword_library is None:
2427
pass
2528
else:
26-
table_tr = self.soup.new_tag('tr')
27-
self.tbody.insert(1, table_tr)
28-
29-
table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
29+
keyword_library = ''
3030

31-
if keyword_type != "kw":
32-
table_td.string = str(kw.parent)
33-
else:
34-
table_td.string = str(test_name)
35-
table_tr.insert(0, table_td)
36-
37-
table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
38-
table_td.string = kw.kwname
39-
table_tr.insert(1, table_td)
40-
41-
kw_status = str(kw.status)
42-
if kw_status == "PASS":
43-
table_td = self.soup.new_tag('td', style="color: green")
44-
table_td.string = kw_status
45-
elif kw_status == "FAIL":
46-
table_td = self.soup.new_tag('td', style="color: red")
47-
table_td.string = kw_status
31+
if any(library in keyword_library for library in self.ignore_library):
32+
pass
33+
else:
34+
keyword_type = kw.type
35+
if any(library in keyword_type for library in self.ignore_type):
36+
pass
4837
else:
49-
table_td = self.soup.new_tag('td', style="color: orange")
50-
table_td.string = kw_status
51-
table_tr.insert(2, table_td)
38+
table_tr = self.soup.new_tag('tr')
39+
self.tbody.insert(1, table_tr)
40+
41+
table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
42+
43+
if keyword_type != "kw":
44+
table_td.string = str(kw.parent)
45+
else:
46+
table_td.string = str(test_name)
47+
table_tr.insert(0, table_td)
48+
49+
table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
50+
table_td.string = kw.kwname
51+
table_tr.insert(1, table_td)
52+
53+
kw_status = str(kw.status)
54+
if kw_status == "PASS":
55+
table_td = self.soup.new_tag('td', style="color: green")
56+
table_td.string = kw_status
57+
elif kw_status == "FAIL":
58+
table_td = self.soup.new_tag('td', style="color: red")
59+
table_td.string = kw_status
60+
else:
61+
table_td = self.soup.new_tag('td', style="color: orange")
62+
table_td.string = kw_status
63+
table_tr.insert(2, table_td)
5264

53-
table_td = self.soup.new_tag('td')
54-
table_td.string = str(kw.elapsedtime / float(1000))
55-
table_tr.insert(3, table_td)
65+
table_td = self.soup.new_tag('td')
66+
table_td.string = str(kw.elapsedtime / float(1000))
67+
table_tr.insert(3, table_td)

robotframework_metrics/keyword_stats.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,31 @@ class KeywordStats(ResultVisitor):
77
failed_keywords = 0
88
skipped_keywords = 0
99

10-
def __init__(self, ignore_type):
10+
def __init__(self, ignore_library, ignore_type):
11+
self.ignore_library = ignore_library
1112
self.ignore_type = ignore_type
1213

1314
def start_keyword(self, kw):
1415

15-
keyword_type = kw.type
16-
if any(library in keyword_type for library in self.ignore_type):
16+
# Ignore library keywords
17+
keyword_library = kw.libname
18+
19+
if not keyword_library is None:
20+
pass
21+
else:
22+
keyword_library = ''
23+
24+
if any(library in keyword_library for library in self.ignore_library):
1725
pass
1826
else:
19-
self.total_keywords += 1
20-
if kw.status == "PASS":
21-
self.passed_keywords += 1
22-
elif kw.status == "FAIL":
23-
self.failed_keywords += 1
27+
keyword_type = kw.type
28+
if any(library in keyword_type for library in self.ignore_type):
29+
pass
2430
else:
25-
self.skipped_keywords += 1
31+
self.total_keywords += 1
32+
if kw.status == "PASS":
33+
self.passed_keywords += 1
34+
elif kw.status == "FAIL":
35+
self.failed_keywords += 1
36+
else:
37+
self.skipped_keywords += 1

robotframework_metrics/robotmetrics.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
except ImportError:
2222
FAILED_IMPORT = True
2323

24-
IGNORE_TYPES = ['foritem', 'for']
24+
IGNORE_LIBRARIES = ['BuiltIn', 'Collections', 'DateTime', 'Dialogs', 'OperatingSystem', 'Process', 'SeleniumLibrary', 'String', 'Screenshot', 'Telnet', 'XML']
25+
IGNORE_TYPES = ['FOR ITERATION', 'FOR']
2526

2627

2728
def generate_report(opts):
@@ -32,6 +33,11 @@ def generate_report(opts):
3233
# URL or filepath of your company logo
3334
logo = opts.logo
3435

36+
# Ignores following library keywords in metrics report
37+
ignore_library = IGNORE_LIBRARIES
38+
if opts.ignore:
39+
ignore_library.extend(opts.ignore)
40+
3541
# Ignores following type keywords in metrics report
3642
ignore_type = IGNORE_TYPES
3743
if opts.ignoretype:
@@ -269,7 +275,7 @@ def generate_report(opts):
269275
#testpp = round(passed * 100.0 / total, 1)
270276
#testfp = round(failed * 100.0 / total, 1)
271277

272-
kw_stats = KeywordStats(ignore_type)
278+
kw_stats = KeywordStats(ignore_library, ignore_type)
273279
result.visit(kw_stats)
274280

275281
total_keywords = kw_stats.total_keywords
@@ -698,10 +704,10 @@ def generate_report(opts):
698704
pass
699705
else:
700706
if group:
701-
group.spawn(result.visit, KeywordResults(soup, kw_tbody, ignore_type))
707+
group.spawn(result.visit, KeywordResults(soup, kw_tbody, ignore_library, ignore_type))
702708
group.join()
703709
else:
704-
result.visit(KeywordResults(soup, kw_tbody, ignore_type))
710+
result.visit(KeywordResults(soup, kw_tbody, ignore_library, ignore_type))
705711

706712
test_icon_txt = """
707713
<div class="row">

robotframework_metrics/runner.py

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import argparse
33
from .robotmetrics import generate_report
44
from .robotmetrics import IGNORE_TYPES
5+
from .robotmetrics import IGNORE_LIBRARIES
56
from .version import __version__
67

78

@@ -22,6 +23,14 @@ def parse_options():
2223
help="User logo (default: dummy image )"
2324
)
2425

26+
general.add_argument(
27+
'--ignorelib',
28+
dest='ignore',
29+
default=IGNORE_LIBRARIES,
30+
nargs="+",
31+
help="Ignore keywords of specified library in report"
32+
)
33+
2534
general.add_argument(
2635
'--ignoretype',
2736
dest='ignoretype',

robotframework_metrics/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.2.1"
1+
__version__ = "3.2.2"

0 commit comments

Comments
 (0)