Skip to content

Commit

Permalink
Merge pull request #21 from adiralashiva8/send_statistics_email
Browse files Browse the repository at this point in the history
Send statistics email
  • Loading branch information
adiralashiva8 authored Sep 4, 2018
2 parents f2ebd59 + ce0c966 commit de25c01
Show file tree
Hide file tree
Showing 22 changed files with 645 additions and 347 deletions.
Binary file removed Image_Dashboard_Metrics_1.JPG
Binary file not shown.
Binary file removed Image_Dashboard_Metrics_2.JPG
Binary file not shown.
Binary file removed Image_Keyword_Metrics_New.JPG
Binary file not shown.
Binary file removed Image_RF_Report_Log.JPG
Binary file not shown.
Binary file removed Image_RF_Report_Report.JPG
Binary file not shown.
Binary file removed Image_Suite_Metrics_New.JPG
Binary file not shown.
Binary file removed Image_Test_Metric_New.JPG
Binary file not shown.
Binary file added Images/Dashboard_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Dashboard_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Dashboard_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Email_Statistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Email_Statistics_Email.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Keyword_Metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Robot_Logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Suite_Metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Test_Metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 65 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,81 @@
# Robot Framework Metrics Report

Creates HTML metrics report based on robotframework output.xml
Creates HTML Metrics report based on robotframework output.xml

---

*How it Works:*

1. Read output.xml file using robotframework API (robot.result.model)
2. Get Test Case Name , Keyword Name, Status, Start Time, End Time and Elapsed time values using api
2. Get Suite, Test Case , Keyword , Status, Start Time, End Time and Elapsed time values using api
3. Convert data to html report using Beautifulsoup

---

*How to use in project:*

1. Clone project or download here [link](https://github.com/adiralashiva8/robotframework-metrics/archive/master.zip)

```
git clone https://github.com/adiralashiva8/robotframework-metrics.git
```
2. Copy __rf_metrics_report_creator.py__ and __rf_metrics_executer.sh__ files to project (where output.xml file is available.)
> Note: __output.xml__ having timestamp is auto recognized by Metrics Report but output.xml, report.html and log.html need to be within same folder.
2. Copy __rf_metrics_report_creator.py__ file to project (where output.xml file is available.)
> Note: __output.xml__ file name having timestamp is recognized by Metrics Report
> output.xml, report.html and log.html need to be within same folder.
3. Install beautifulsoup: (to create html report - one time activity)
```
pip install beautifulsoup4
```
4. Execute __rf_metrics_executer.sh__ file
5. __Robotframework Metrics Report__ will be launched in new chrome tab
> Assumption __Python__ already installed in machine
4. Execute __rf_metrics_report_creator.py__ file
```
python rf_metrics_report_creator.py
```
5. RobotFramework Metrics Report __rf_metrics_result.html__ file will be created in current folder
If you were using latest python. Upgrade robotframework to generate report
> Update Robot Framework
``` pip install --pre --upgrade robotframework ```
---
*Sample Report:*
__DASHBOARD__
![Screenshot](Image_Dashboard_Metrics_1.JPG)
![Screenshot](Images/Dashboard_1.png)
![Screenshot](Images/Dashboard_2.png)
![Screenshot](Image_Dashboard_Metrics_2.JPG)
![Screenshot](Images/Dashboard_3.png)
__SUITE METRICS__
![Screenshot](Image_Suite_Metrics_New.JPG)
![Screenshot](Images/Suite_Metrics.png)
__TEST METRICS__
![Screenshot](Image_Test_Metric_New.JPG)
![Screenshot](Images/Test_Metrics.png)
__KEYWORD METRICS__
![Screenshot](Image_Keyword_Metrics_New.JPG)
![Screenshot](Images/Keyword_Metrics.png)
__ROBOT LOG__
__RF REPORT__
![Screenshot](Images/Robot_Logs.png)
![Screenshot](Image_RF_Report_Report.JPG)
__EMAIL STATISTICS__
![Screenshot](Images/Email_Statistics.png)
![Screenshot](Images/Email_Statistics_Email.png)
![Screenshot](Image_RF_Report_Log.JPG)
---
Expand All @@ -76,14 +92,38 @@ __RF REPORT__
'DateTime',
]
```
---
*Frequently Asked Queries*
- I dont have chrome browser, will Metrics Report works
> Yes, Generate report by executing ``` python rf_metrics_report_creator.py ``` command and open __rf_metrics_result.html__ in your prefered browser
- Can I change font style of report
> Yes, By changing __font-family:__ value in __rf_metrics_report_creator.py__ file
*Versions:*
1. V2.1 [link](https://github.com/adiralashiva8/robotframework-metrics/archive/V2.1.zip)
> Status: __Beta__
> 1. Dashboard
> 2. Suite Metrics
> 3. Test Metrics
> 4. Keyword Metrics
> 5. Robot Logs
> 6. Email
>
2. V2.0 [link](https://github.com/adiralashiva8/robotframework-metrics/archive/V2.0.zip)
> Status: __Stable__
> 1. Dashboard
> 2. Suite Metrics
> 3. Test Metrics
> 4. Keyword Metrics
> 5. Robot Logs
>
3. V1.0 [link](https://github.com/adiralashiva8/robotframework-metrics/archive/V1.0.zip)
> Status: __Stable__
> 1. Dashboard
> 2. Test Metrics
> 3. Keyword Metrics
>
---
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
124 changes: 123 additions & 1 deletion rf_metrics_report_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
#suiteMetrics {background-color: white;}
#testMetrics {background-color: white;}
#keywordMetrics {background-color: white;}
#emailStatistics {background-color: white;}
</style>
</head>
Expand Down Expand Up @@ -189,6 +190,10 @@
<i class="fa fa-file-text w3-xxlarge"></i>
<p> ROBOT LOGS</p>
</a>
<a href="#" onclick="openPage('statistics', this, 'orange');" class="tablink w3-bar-item w3-button w3-padding-large">
<i class="fa fa-envelope-o w3-xxlarge"></i>
<p> EMAIL STATISTICS</p>
</a>
</nav>
<!-- Navbar on small screens (Hidden on medium and large screens) -->
Expand All @@ -199,6 +204,7 @@
<a href="#" onclick="openPage('testMetrics', this, 'orange');executeDataTable('#tm',5)" class="tablink w3-bar-item w3-button" style="width:25% !important">TEST METRICS</a>
<a href="#" onclick="openPage('keywordMetrics', this, 'orange');executeDataTable('#km',5)" class="tablink w3-bar-item w3-button" style="width:25% !important">KEYWORD METRICS</a>
<a href="#" onclick="openPage('log', this, 'orange');" class="tablink w3-bar-item w3-button" style="width:25% !important">ROBOT LOGS</a>
<a href="#" onclick="openPage('statistics', this, 'orange');" class="tablink w3-bar-item w3-button" style="width:25% !important">EMAIL STATISTICS</a>
</div>
</div>
Expand Down Expand Up @@ -230,12 +236,18 @@
km_div["class"] = "tabcontent"
page_content_div.insert(150, km_div)

# Keywords div
# Logs div
log_div = soup.new_tag('div')
log_div["id"] = "log"
log_div["class"] = "tabcontent"
page_content_div.insert(200, log_div)

# Statistics div
statisitcs_div = soup.new_tag('div')
statisitcs_div["id"] = "statistics"
statisitcs_div["class"] = "tabcontent"
page_content_div.insert(300, statisitcs_div)

### ============================ START OF DASHBOARD ======================================= ####
total_suite = 0
passed_suite = 0
Expand Down Expand Up @@ -754,7 +766,117 @@ def start_keyword(self,kw):

### ============================ END OF LOGS ======================================= ####

### ============================ EMAIL STATISTICS ================================== ###

emailStatistics="""
<h4><b><i class="fa fa-envelope-o"></i> Email Statistics</b></h4>
<hr>
<h6><ul><li>Click 'Generate Statistics Email' button to get generate statistics email</li><li>Click 'Click Here To Download Email' link to download generated email</ul></h6>
<button id="create" class="btn btn-primary active" role="button" ><i class="fa fa-cogs"></i> Generate Statistics Email</button><br><br>
<a download="message.eml" class="btn btn-secondary active" role="button" id="downloadlink" style="display: none; width: 300px;font-weight: bold;"><i class="fa fa-download"></i> Click Here To Download Email</a>
<textarea id="textbox" class="col-md-12" style="height: 400px; padding:1em;">
To: [email protected]
Subject: Automation Execution Status
X-Unsent: 1
Content-Type: text/html
<html>
<head>
<style>
body, html, table,pre {
font-family: Calibri, Arial, sans-serif;
font-size: 1em;
}
.pastdue { color: crimson; }
table {
border: 1px solid silver;
padding: 6px;
margin-left: 30px;
}
thead {
text-align: center;
font-size: 1.1em;
background-color: #B0C4DE;
font-weight: bold;
color: #2D2C2C;
}
tbody td {
text-align: center;
}
</style>
</head>
<body>
<pre>Hi Team,
Following are the last build execution statistics.
</pre>
<table style="width: 600px;">
<thead>
<th style="width: 25%%;">Statistics</th>
<th style="width: 25%%;">Total</th>
<th style="width: 25%%;">Pass</th>
<th style="width: 25%%;">Fail</th>
</thead>
<tbody>
<tr>
<td style="text-align: left;font-weight: bold;padding-left: 40px;"> SUITE </td>
<td style="background-color: #F5DEB3;">%s</td>
<td style="background-color: #90EE90;">%s</td>
<td style="background-color: #F08080;">%s</td>
</tr>
<tr>
<td style="text-align: left;font-weight: bold;padding-left:40px;"> TESTS </td>
<td style="background-color: #F5DEB3;">%s</td>
<td style="background-color: #90EE90;">%s</td>
<td style="background-color: #F08080;">%s</td>
</tr>
<tr>
<td style="text-align: left;font-weight: bold;padding-left: 40px;"> KEYWORDS </td>
<td style="background-color: #F5DEB3;">%s</td>
<td style="background-color: #90EE90;">%s</td>
<td style="background-color: #F08080;">%s</td>
</tr>
</tbody>
</table>
<pre>
Please refer RF Metrics Report for detailed statistics.
Regards,
QA Team</pre>
</body>
</html>
</textarea>
""" % (total_suite,passed_suite,failed_suite,total,passed,failed,total_keywords,passed_keywords,failed_keywords)
statisitcs_div.append(BeautifulSoup(emailStatistics, 'html.parser'))



### ============================ END OF EMAIL STATISTICS ================================== ###



script_text="""
<script>
(function () {
var textFile = null,
makeTextFile = function (text) {
var data = new Blob([text], {type: 'text/plain'});
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
textFile = window.URL.createObjectURL(data);
return textFile;
};
var create = document.getElementById('create'),
textbox = document.getElementById('textbox');
create.addEventListener('click', function () {
var link = document.getElementById('downloadlink');
link.href = makeTextFile(textbox.value);
link.style.display = 'block';
}, false);
})();
</script>
<script>
function createPieChart(passed_count,failed_count,ChartID,ChartName){
var status = [];
Expand Down
Loading

0 comments on commit de25c01

Please sign in to comment.