Skip to content

Commit

Permalink
Fix issues with rf4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adiralashiva8 committed Mar 12, 2021
1 parent bd096c4 commit bbbb513
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 95 deletions.
24 changes: 2 additions & 22 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.0__ [link](https://github.com/adiralashiva8/robotframework-metrics/releases/tag/v3.2.0)
- Whats new in __v3.2.1__ [link](https://github.com/adiralashiva8/robotframework-metrics/releases/tag/v3.2.1)

- 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.0
pip install robotframework-metrics==3.2.1
```
> Case 2: Using setup.py (clone project and run command within root)
```
Expand Down Expand Up @@ -115,26 +115,6 @@ Specify Logo in Robotframework metrics:
```
> By default `--fullsuitename` is `False`

#### How to Ignore Library Keywords in Metrics Report

- Use command line options to ignore library keywords
```
--ignore "Collections,Selenium2Library"
```

- In Metric report, keywords with type value 'for' and 'foritem' are ignored

- Following library keywords are ignored in Metrics Report
```
ignore_library = [
'BuiltIn',
'SeleniumLibrary',
'String',
'Collections',
'DateTime',
]
```
---

#### Generate robotframework-metrics after execution
Expand Down
71 changes: 32 additions & 39 deletions robotframework_metrics/keyword_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

class KeywordResults(ResultVisitor):

def __init__(self, soup, tbody, ignore_lib, ignore_type):
def __init__(self, soup, tbody, 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 @@ -20,43 +19,37 @@ 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 ''

# Ignore library keywords
keyword_library = kw.libname

if any(library in keyword_library for library in self.ignore_library):
keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
pass
else:
keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
pass
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_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.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)
24 changes: 9 additions & 15 deletions robotframework_metrics/keyword_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ class KeywordStats(ResultVisitor):
failed_keywords = 0
skipped_keywords = 0

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

def start_keyword(self, kw):
# Ignore library keywords
keyword_library = kw.libname

if any(library in keyword_library for library in self.ignore_library):
keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
pass
else:
keyword_type = kw.type
if any(library in keyword_type for library in self.ignore_type):
pass
self.total_keywords += 1
if kw.status == "PASS":
self.passed_keywords += 1
elif kw.status == "FAIL":
self.failed_keywords += 1
else:
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
self.skipped_keywords += 1
12 changes: 3 additions & 9 deletions robotframework_metrics/robotmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
except ImportError:
FAILED_IMPORT = True

IGNORE_LIBRARIES = ['BuiltIn', 'SeleniumLibrary', 'String', 'Collections', 'DateTime']
IGNORE_TYPES = ['foritem', 'for']


Expand All @@ -33,11 +32,6 @@ 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 @@ -275,7 +269,7 @@ def generate_report(opts):
#testpp = round(passed * 100.0 / total, 1)
#testfp = round(failed * 100.0 / total, 1)

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

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

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


Expand All @@ -23,14 +22,6 @@ 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.0"
__version__ = "3.2.1"

0 comments on commit bbbb513

Please sign in to comment.