From 7d770be03a481f58771784c5e3de44f52da97d34 Mon Sep 17 00:00:00 2001 From: Shiva Date: Sat, 31 Oct 2020 12:59:17 +0530 Subject: [PATCH] Include ignore library and ignore type --- README.md | 4 +- robotframework_metrics/keyword_results.py | 72 +++++++++++++---------- robotframework_metrics/keyword_stats.py | 30 +++++++--- robotframework_metrics/robotmetrics.py | 14 +++-- robotframework_metrics/runner.py | 9 +++ robotframework_metrics/version.py | 2 +- 6 files changed, 85 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 0524ee0..8024e3c 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) ``` diff --git a/robotframework_metrics/keyword_results.py b/robotframework_metrics/keyword_results.py index d374ca1..fc4984c 100644 --- a/robotframework_metrics/keyword_results.py +++ b/robotframework_metrics/keyword_results.py @@ -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): @@ -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) \ No newline at end of file + table_td = self.soup.new_tag('td') + table_td.string = str(kw.elapsedtime / float(1000)) + table_tr.insert(3, table_td) \ No newline at end of file diff --git a/robotframework_metrics/keyword_stats.py b/robotframework_metrics/keyword_stats.py index b6fa173..c0070ff 100644 --- a/robotframework_metrics/keyword_stats.py +++ b/robotframework_metrics/keyword_stats.py @@ -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 diff --git a/robotframework_metrics/robotmetrics.py b/robotframework_metrics/robotmetrics.py index 3db5f56..83a9b32 100644 --- a/robotframework_metrics/robotmetrics.py +++ b/robotframework_metrics/robotmetrics.py @@ -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): @@ -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: @@ -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 @@ -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 = """
diff --git a/robotframework_metrics/runner.py b/robotframework_metrics/runner.py index 3a8396c..3b1451a 100644 --- a/robotframework_metrics/runner.py +++ b/robotframework_metrics/runner.py @@ -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__ @@ -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', diff --git a/robotframework_metrics/version.py b/robotframework_metrics/version.py index 96af409..1e3bed4 100644 --- a/robotframework_metrics/version.py +++ b/robotframework_metrics/version.py @@ -1 +1 @@ -__version__ = "3.2.1" \ No newline at end of file +__version__ = "3.2.2"