Skip to content

Commit

Permalink
Include ignore library and ignore type
Browse files Browse the repository at this point in the history
  • Loading branch information
adiralashiva8 committed Mar 13, 2021
1 parent 2d01946 commit 7d770be
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 46 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Creates awesome HTML (dashboard view) report by parsing robotframework output.xm
---
- __Sample Report__ [link](https://robotmetrics.netlify.com/)

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

- 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)

Expand All @@ -33,7 +33,7 @@ __Step 1__ Install robotmetrics

> Case 1: Using pip
```
pip install robotframework-metrics==3.2.1
pip install robotframework-metrics==3.2.2
```
> Case 2: Using setup.py (clone project and run command within root)
```
Expand Down
72 changes: 42 additions & 30 deletions robotframework_metrics/keyword_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

class KeywordResults(ResultVisitor):

def __init__(self, soup, tbody, ignore_type):
def __init__(self, soup, tbody, ignore_lib, ignore_type):
self.test = None
self.soup = soup
self.tbody = tbody
self.ignore_library = ignore_lib
self.ignore_type = ignore_type

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

keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
# Ignore library keywords
keyword_library = kw.libname

if not keyword_library is None:
pass
else:
table_tr = self.soup.new_tag('tr')
self.tbody.insert(1, table_tr)

table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
keyword_library = ''

if keyword_type != "kw":
table_td.string = str(kw.parent)
else:
table_td.string = str(test_name)
table_tr.insert(0, table_td)

table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
table_td.string = kw.kwname
table_tr.insert(1, table_td)

kw_status = str(kw.status)
if kw_status == "PASS":
table_td = self.soup.new_tag('td', style="color: green")
table_td.string = kw_status
elif kw_status == "FAIL":
table_td = self.soup.new_tag('td', style="color: red")
table_td.string = kw_status
if any(library in keyword_library for library in self.ignore_library):
pass
else:
keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
pass
else:
table_td = self.soup.new_tag('td', style="color: orange")
table_td.string = kw_status
table_tr.insert(2, table_td)
table_tr = self.soup.new_tag('tr')
self.tbody.insert(1, table_tr)

table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")

if keyword_type != "kw":
table_td.string = str(kw.parent)
else:
table_td.string = str(test_name)
table_tr.insert(0, table_td)

table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: normal; text-align:left")
table_td.string = kw.kwname
table_tr.insert(1, table_td)

kw_status = str(kw.status)
if kw_status == "PASS":
table_td = self.soup.new_tag('td', style="color: green")
table_td.string = kw_status
elif kw_status == "FAIL":
table_td = self.soup.new_tag('td', style="color: red")
table_td.string = kw_status
else:
table_td = self.soup.new_tag('td', style="color: orange")
table_td.string = kw_status
table_tr.insert(2, table_td)

table_td = self.soup.new_tag('td')
table_td.string = str(kw.elapsedtime / float(1000))
table_tr.insert(3, table_td)
table_td = self.soup.new_tag('td')
table_td.string = str(kw.elapsedtime / float(1000))
table_tr.insert(3, table_td)
30 changes: 21 additions & 9 deletions robotframework_metrics/keyword_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@ class KeywordStats(ResultVisitor):
failed_keywords = 0
skipped_keywords = 0

def __init__(self, ignore_type):
def __init__(self, ignore_library, ignore_type):
self.ignore_library = ignore_library
self.ignore_type = ignore_type

def start_keyword(self, kw):

keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
# Ignore library keywords
keyword_library = kw.libname

if not keyword_library is None:
pass
else:
keyword_library = ''

if any(library in keyword_library for library in self.ignore_library):
pass
else:
self.total_keywords += 1
if kw.status == "PASS":
self.passed_keywords += 1
elif kw.status == "FAIL":
self.failed_keywords += 1
keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
pass
else:
self.skipped_keywords += 1
self.total_keywords += 1
if kw.status == "PASS":
self.passed_keywords += 1
elif kw.status == "FAIL":
self.failed_keywords += 1
else:
self.skipped_keywords += 1
14 changes: 10 additions & 4 deletions robotframework_metrics/robotmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
except ImportError:
FAILED_IMPORT = True

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


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

# Ignores following library keywords in metrics report
ignore_library = IGNORE_LIBRARIES
if opts.ignore:
ignore_library.extend(opts.ignore)

# Ignores following type keywords in metrics report
ignore_type = IGNORE_TYPES
if opts.ignoretype:
Expand Down Expand Up @@ -269,7 +275,7 @@ def generate_report(opts):
#testpp = round(passed * 100.0 / total, 1)
#testfp = round(failed * 100.0 / total, 1)

kw_stats = KeywordStats(ignore_type)
kw_stats = KeywordStats(ignore_library, ignore_type)
result.visit(kw_stats)

total_keywords = kw_stats.total_keywords
Expand Down Expand Up @@ -698,10 +704,10 @@ def generate_report(opts):
pass
else:
if group:
group.spawn(result.visit, KeywordResults(soup, kw_tbody, ignore_type))
group.spawn(result.visit, KeywordResults(soup, kw_tbody, ignore_library, ignore_type))
group.join()
else:
result.visit(KeywordResults(soup, kw_tbody, ignore_type))
result.visit(KeywordResults(soup, kw_tbody, ignore_library, ignore_type))

test_icon_txt = """
<div class="row">
Expand Down
9 changes: 9 additions & 0 deletions robotframework_metrics/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
from .robotmetrics import generate_report
from .robotmetrics import IGNORE_TYPES
from .robotmetrics import IGNORE_LIBRARIES
from .version import __version__


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

general.add_argument(
'--ignorelib',
dest='ignore',
default=IGNORE_LIBRARIES,
nargs="+",
help="Ignore keywords of specified library in report"
)

general.add_argument(
'--ignoretype',
dest='ignoretype',
Expand Down
2 changes: 1 addition & 1 deletion robotframework_metrics/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.2.1"
__version__ = "3.2.2"

0 comments on commit 7d770be

Please sign in to comment.