Skip to content

Commit

Permalink
Support SKIP status
Browse files Browse the repository at this point in the history
  • Loading branch information
adiralashiva8 committed Oct 31, 2020
1 parent 74a2e69 commit 993540e
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 44 deletions.
6 changes: 3 additions & 3 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.1.7__ [link](https://github.com/adiralashiva8/robotframework-metrics/releases/tag/v3.1.7)
- Whats new in __v3.1.9__ [link](https://github.com/adiralashiva8/robotframework-metrics/releases/tag/v3.1.9)

- 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.1.7
pip install robotframework-metrics==3.1.9
```
> Case 2: Using setup.py (clone project and run command within root)
```
Expand Down Expand Up @@ -208,4 +208,4 @@ If you have any questions / suggestions / comments on the report, please feel fr
:star: repo if you like it
---
---
6 changes: 4 additions & 2 deletions robotframework_metrics/keyword_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def start_keyword(self, kw):
if kw_status == "PASS":
table_td = self.soup.new_tag('td', style="color: green")
table_td.string = kw_status
else:
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')
Expand Down
5 changes: 4 additions & 1 deletion robotframework_metrics/keyword_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class KeywordStats(ResultVisitor):
total_keywords = 0
passed_keywords = 0
failed_keywords = 0
skipped_keywords = 0

def __init__(self, ignore_library, ignore_type):
self.ignore_library = ignore_library
Expand All @@ -24,5 +25,7 @@ def start_keyword(self, kw):
self.total_keywords += 1
if kw.status == "PASS":
self.passed_keywords += 1
else:
elif kw.status == "FAIL":
self.failed_keywords += 1
else:
self.skipped_keywords += 1
80 changes: 56 additions & 24 deletions robotframework_metrics/robotmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,17 @@ def generate_report(opts):
test_stats = TestStats()
result.visit(test_stats)

total_suite = test_stats.total_suite
passed_suite = test_stats.passed_suite
failed_suite = test_stats.failed_suite
try:
test_stats_obj = test_stats.all
except:
test_stats_obj = test_stats
total_suite = test_stats_obj.total_suite
passed_suite = test_stats_obj.passed_suite
failed_suite = test_stats_obj.failed_suite
try:
skipped_suite = test_stats_obj.skipped_suite
except:
skipped_suite = 0

#suitepp = round(passed_suite * 100.0 / total_suite, 1)
#suitefp = round(failed_suite * 100.0 / total_suite, 1)
Expand All @@ -252,9 +260,17 @@ def generate_report(opts):
generator = "Rebot"

stats = result.statistics
total = stats.total.all.total
passed = stats.total.all.passed
failed = stats.total.all.failed
try:
stats_obj = stats.total.all
except:
stats_obj = stats.total
total = stats_obj.total
passed = stats_obj.passed
failed = stats_obj.failed
try:
skipped = stats_obj.skipped
except:
skipped = 0

#testpp = round(passed * 100.0 / total, 1)
#testfp = round(failed * 100.0 / total, 1)
Expand All @@ -265,6 +281,10 @@ def generate_report(opts):
total_keywords = kw_stats.total_keywords
passed_keywords = kw_stats.passed_keywords
failed_keywords = kw_stats.failed_keywords
try:
skipped_keywords = kw_stats.skipped_keywords
except:
skipped_keywords = 0

# Handling ZeroDivisionError exception when no keywords are found
# if total_keywords > 0:
Expand Down Expand Up @@ -313,10 +333,12 @@ def generate_report(opts):
<tbody>
<tr style="height:70%;font-size:25px" align="center" valign="middle">
<td style="width: 33%; color:brown">__STOTAL__</td>
<td style="width: 33%; color:orange">__SSKIP__</td>
<td style="width: 33%; color:#fc6666">__SFAIL__</td>
</tr>
<tr style="height:30%" align="center" valign="top">
<td style="width: 33%"><span style="color: #999999;font-size:10px">Total</span></td>
<td style="width: 33%"><span style="color: #999999;font-size:10px">Skip</span></td>
<td style="width: 33%"><span style="color: #999999;font-size:10px">Fail</span></td>
</tr>
</tbody>
Expand Down Expand Up @@ -352,10 +374,12 @@ def generate_report(opts):
<tbody>
<tr style="height:70%;font-size:25px" align="center" valign="middle">
<td style="width: 33%; color:brown">__TTOTAL__</td>
<td style="width: 33%; color:orange">__TSKIP__</td>
<td style="width: 33%; color:#fc6666">__TFAIL__</td>
</tr>
<tr style="height:30%" align="center" valign="top">
<td style="width: 33%"><span style="color: #999999;font-size:10px">Total</span></td>
<td style="width: 33%"><span style="color: #999999;font-size:10px">Skip</span></td>
<td style="width: 33%"><span style="color: #999999;font-size:10px">Fail</span></td>
</tr>
</tbody>
Expand Down Expand Up @@ -391,10 +415,12 @@ def generate_report(opts):
<tbody>
<tr style="height:70%;font-size:25px" align="center" valign="middle">
<td style="width: 33%; color:brown">__KTOTAL__</td>
<td style="width: 33%; color:orange">__KSKIP__</td>
<td style="width: 33%; color:#fc6666">__KFAIL__</td>
</tr>
<tr style="height:30%" align="center" valign="top">
<td style="width: 33%"><span style="color: #999999;font-size:10px">Total</span></td>
<td style="width: 33%"><span style="color: #999999;font-size:10px">Skip</span></td>
<td style="width: 33%"><span style="color: #999999;font-size:10px">Fail</span></td>
</tr>
</tbody>
Expand Down Expand Up @@ -452,14 +478,14 @@ def generate_report(opts):
<script>
window.onload = function(){
executeDataTable('#sm',5);
executeDataTable('#sm',6);
executeDataTable('#tm',3);
executeDataTable('#km',3);
createPieChart(__SPASS__,__SFAIL__,'suiteChartID','Suite Status:');
createBarGraph('#sm',0,5,10,'suiteBarID','Elapsed Time (s) ','Suite');
createPieChart(__TPASS__,__TFAIL__,'testChartID','Tests Status:');
createPieChart(__SPASS__,__SFAIL__,__SSKIP__,'suiteChartID','Suite Status:');
createBarGraph('#sm',0,6,10,'suiteBarID','Elapsed Time (s) ','Suite');
createPieChart(__TPASS__,__TFAIL__,__TSKIP__,'testChartID','Tests Status:');
createBarGraph('#tm',1,3,10,'testsBarID','Elapsed Time (s) ','Test');
createPieChart(__KPASS__,__KFAIL__,'keywordChartID','Keywords Status:');
createPieChart(__KPASS__,__KFAIL__,__KSKIP__,'keywordChartID','Keywords Status:');
createBarGraph('#km',1,3,10,'keywordsBarID','Elapsed Time (s) ','Keyword');
};
</script>
Expand All @@ -479,12 +505,15 @@ def generate_report(opts):
dashboard_content = dashboard_content.replace("__STOTAL__", str(total_suite))
dashboard_content = dashboard_content.replace("__SPASS__", str(passed_suite))
dashboard_content = dashboard_content.replace("__SFAIL__", str(failed_suite))
dashboard_content = dashboard_content.replace("__SSKIP__", str(skipped_suite))
dashboard_content = dashboard_content.replace("__TTOTAL__", str(total))
dashboard_content = dashboard_content.replace("__TPASS__", str(passed))
dashboard_content = dashboard_content.replace("__TFAIL__", str(failed))
dashboard_content = dashboard_content.replace("__TSKIP__", str(skipped))
dashboard_content = dashboard_content.replace("__KTOTAL__", str(total_keywords))
dashboard_content = dashboard_content.replace("__KPASS__", str(passed_keywords))
dashboard_content = dashboard_content.replace("__KFAIL__", str(failed_keywords))
dashboard_content = dashboard_content.replace("__KSKIP__", str(skipped_keywords))
dashboard_content = dashboard_content.replace("__KHIDE__", str(hide_keyword))

page_content_div.append(BeautifulSoup(dashboard_content, 'html.parser'))
Expand Down Expand Up @@ -538,17 +567,17 @@ def generate_report(opts):
tr.insert(4, th)

th = soup.new_tag('th')
th.string = "Time (s)"
th.string = "Fail"
tr.insert(5, th)

th = soup.new_tag('th')
th.string = "Time (s)"
tr.insert(6, th)

suite_tbody = soup.new_tag('tbody')
table.insert(11, suite_tbody)

# GET SUITE METRICS
if group:
group.spawn(result.visit, SuiteResults(soup, suite_tbody, log_name, opts.fullsuitename))
else:
result.visit(SuiteResults(soup, suite_tbody, log_name, opts.fullsuitename))
result.visit(SuiteResults(soup, suite_tbody, log_name, opts.fullsuitename))

test_icon_txt = """
<div class="row">
Expand Down Expand Up @@ -614,10 +643,7 @@ def generate_report(opts):
table.insert(11, test_tbody)

# GET TEST METRICS
if group:
group.spawn(result.visit, TestResults(soup, test_tbody, log_name, opts.fullsuitename, opts.showtags))
else:
result.visit(TestResults(soup, test_tbody, log_name, opts.fullsuitename, opts.showtags))
result.visit(TestResults(soup, test_tbody, log_name, opts.fullsuitename, opts.showtags))

test_icon_txt = """
<div class="row">
Expand Down Expand Up @@ -714,17 +740,17 @@ def generate_report(opts):
# END OF LOGS
script_text = """
<script>
function createPieChart(passed_count,failed_count,ChartID,ChartName){
function createPieChart(passed_count, failed_count, skipped_count, ChartID, ChartName){
var status = [];
status.push(['Status', 'Percentage']);
status.push(['PASS',parseInt(passed_count)],['FAIL',parseInt(failed_count)]);
status.push(['PASS',parseInt(passed_count)],['FAIL',parseInt(failed_count)],['SKIP',parseInt(skipped_count)]);
var data = google.visualization.arrayToDataTable(status);
var options = {
pieHole: 0.6,
legend: 'none',
chartArea: {width: "95%",height: "90%"},
colors: ['#2ecc71', '#fc6666'],
colors: ['#2ecc71', '#fc6666', '#ffa500'],
};
var chart = new google.visualization.PieChart(document.getElementById(ChartID));
Expand Down Expand Up @@ -824,6 +850,12 @@ def generate_report(opts):
retrieve: true,
"order": [[ Number(sortCol), "desc" ]],
dom: 'l<".margin" B>frtip',
"aoColumnDefs": [ {
"aTargets": [ -1 ],
"mRender": function ( data, type, full ) {
return $("<div/>").html(data).text();
}
} ],
buttons: [
{
extend: 'copyHtml5',
Expand Down
30 changes: 22 additions & 8 deletions robotframework_metrics/suite_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def start_suite(self, suite):
if not suite_test_list:
pass
else:
stats = suite.statistics
try:
stats = suite.statistics.all
except:
stats = suite.statistics
table_tr = self.soup.new_tag('tr')
self.tbody.insert(0, table_tr)

Expand All @@ -32,24 +35,35 @@ def start_suite(self, suite):
if suite_status == "PASS":
table_td = self.soup.new_tag('td', style="color: green")
table_td.string = suite_status
else:
elif suite_status == "FAIL":
table_td = self.soup.new_tag('td', style="color: red")
table_td.string = suite_status
else:
table_td = self.soup.new_tag('td', style="color: orange")
table_td.string = suite_status

table_tr.insert(1, table_td)

table_td = self.soup.new_tag('td')
table_td.string = str(stats.all.total)
table_td.string = str(stats.total)
table_tr.insert(2, table_td)

table_td = self.soup.new_tag('td')
table_td.string = str(stats.all.passed)
table_td = self.soup.new_tag('td', style="color: green")
table_td.string = str(stats.passed)
table_tr.insert(3, table_td)

table_td = self.soup.new_tag('td')
table_td.string = str(stats.all.failed)
table_td = self.soup.new_tag('td', style="color: red")
table_td.string = str(stats.failed)
table_tr.insert(4, table_td)

table_td = self.soup.new_tag('td', style="color: orange")
try:
skip_count = stats.skipped
except:
skip_count = 0
table_td.string = str(skip_count)
table_tr.insert(5, table_td)

table_td = self.soup.new_tag('td')
table_td.string = str(suite.elapsedtime / float(1000))
table_tr.insert(5, table_td)
table_tr.insert(6, table_td)
10 changes: 6 additions & 4 deletions robotframework_metrics/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ def visit_test(self, test):
if test_status == "PASS":
table_td = self.soup.new_tag('td', style="color: green")
table_td.string = test_status
else:
elif test_status == "FAIL":
table_td = self.soup.new_tag('td', style="color: red")
table_td.string = test_status

else:
table_td = self.soup.new_tag('td', style="color: orange")
table_td.string = test_status
table_tr.insert(2, table_td)

table_td = self.soup.new_tag('td')
table_td.string = str(test.elapsedtime / float(1000))
table_tr.insert(3, 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 = self.soup.new_tag('td', style="word-wrap: break-word;max-width: 250px; white-space: pre-wrap;text-align:left")
table_td.string = test.message
table_tr.insert(4, table_td)

if self.showtags == "True":
table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width:100px; white-space: normal;text-align:left")
table_td = self.soup.new_tag('td', style="word-wrap: break-word;max-width:100px; white-space: pre-wrap;text-align:left")
table_td.string = str(test.tags)
table_tr.insert(5, table_td)
5 changes: 4 additions & 1 deletion robotframework_metrics/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TestStats(ResultVisitor):
total_suite = 0
passed_suite = 0
failed_suite = 0
skipped_suite = 0

def start_suite(self, suite):
suite_test_list = suite.tests
Expand All @@ -15,5 +16,7 @@ def start_suite(self, suite):

if suite.status == "PASS":
self.passed_suite += 1
else:
elif suite.status == "FAIL":
self.failed_suite += 1
else:
self.skipped_suite += 1
2 changes: 1 addition & 1 deletion robotframework_metrics/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.1.8"
__version__ = "3.1.9"

0 comments on commit 993540e

Please sign in to comment.