Skip to content

Commit

Permalink
QE-13613 numerical sorting of duration in flat.html report (#369)
Browse files Browse the repository at this point in the history
JIRA - QE-13613
  • Loading branch information
ddl-kavya authored Nov 13, 2023
1 parent 9b4f234 commit aaea654
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.175.0
- Change - left pad duration with zeroes for better alphabetical sorting in flat.html report

## 0.174.0
- Chore - prevent secrets from being merged to main
- Chore - stabilize CI by reducing workers
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cucu"
version = "0.174.0"
version = "0.175.0"
license = "MIT"
description = "Easy BDD web testing"
authors = ["Domino Data Lab <[email protected]>"]
Expand All @@ -23,7 +23,6 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Testing :: BDD",
]
Expand Down
16 changes: 13 additions & 3 deletions src/cucu/reporter/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def process_tags(element):
element["tags"] = " ".join(prepared_tags)


# function to left pad duration with '0' for better alphabetical sorting in html reports.
def left_pad_zeroes(elapsed_time):
int_decimal = str(round(elapsed_time, 3)).split(".")
int_decimal[0] = int_decimal[0].zfill(3)
padded_duration = ".".join(int_decimal)
return padded_duration


def generate(results, basepath, only_failures=False):
"""
generate an HTML report for the results provided.
Expand Down Expand Up @@ -285,14 +293,16 @@ def generate(results, basepath, only_failures=False):
encoding="utf-8",
)

scenario["duration"] = scenario_duration
scenario["duration"] = left_pad_zeroes(scenario_duration)
feature_duration += scenario_duration

if feature_started_at is None:
feature["started_at"] = ""

feature["total_steps"] = sum([x["total_steps"] for x in scenarios])
feature["duration"] = sum([x["duration"] for x in scenarios])
feature["duration"] = left_pad_zeroes(
sum([float(x["duration"]) for x in scenarios])
)

feature["total_scenarios"] = total_scenarios
feature["total_scenarios_passed"] = total_scenarios_passed
Expand All @@ -308,7 +318,7 @@ def generate(results, basepath, only_failures=False):
]
grand_totals = {}
for k in keys:
grand_totals[k] = sum([x[k] for x in reported_features])
grand_totals[k] = sum([float(x[k]) for x in reported_features])

package_loader = jinja2.PackageLoader("cucu.reporter", "templates")
templates = jinja2.Environment(loader=package_loader) # nosec
Expand Down
6 changes: 3 additions & 3 deletions src/cucu/reporter/templates/feature.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a class="nav-link" href="index.html" title="go to index report">Index</a>
</li>
<li class="align-middle">
<div style="padding: 8px">Started {{ feature['started_at'] }} for {{ '{:.3f}'.format(feature['duration']) }}s</div>
<div style="padding: 8px">Started {{ feature['started_at'] }} for {{ feature['duration'] }}s</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -42,7 +42,7 @@
<th>Scenario</th>
<th class="text-center">Steps</th>
<th class="text-center">Status</th>
<th class="text-center">Duration</th>
<th class="text-center">Duration (s)</th>
</tr>
</thead>
{% for scenario in scenarios %}
Expand All @@ -60,7 +60,7 @@
</td>
<td class="text-center">{{ scenario['total_steps'] }}</td>
<td class="text-center"><span class="status-{{ scenario['status'] }}">{{ scenario['status'] }}</span></td>
<td class="text-center">{{ '{:.3f}'.format(scenario['duration']) }}s</td>
<td class="text-center">{{ scenario['duration'] }}</td>
</tr>
{% endif %}
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions src/cucu/reporter/templates/flat.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<th>Scenario</th>
<th class="text-center">Total Steps</th>
<th class="text-center">Status</th>
<th class="text-center">Duration</th>
<th class="text-center">Duration (s)</th>
</tr>
</thead>
{% for feature in features %}
Expand All @@ -35,7 +35,7 @@
<td><a href="{{ urlencode(escape(feature['name'])) }}/{{ urlencode(escape(scenario['name'])) }}/index.html"><span>{{ escape(scenario['name']) }}</span></a><br>{{ scenario['tags'] }}</td>
<td class="text-center">{{ scenario['total_steps'] }}</td>
<td class="text-center"><span class="status-{{ scenario['status'] }}">{{ scenario['status'] }}</span></td>
<td class="text-center">{{ '{:.3f}'.format(scenario['duration']) }}s</td>
<td class="text-center">{{ scenario['duration'] }}</td>
</tr>
{% endif %}
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions src/cucu/reporter/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<th class="text-center">Failed<br/>{{ grand_totals['total_scenarios_failed'] }}</th>
<th class="text-center">Skipped<br/>{{ grand_totals['total_scenarios_skipped'] }}</th>
<th class="text-center">Status<br/>&nbsp;</th>
<th class="text-center">Duration<br/>{{ '{:.3f}'.format(grand_totals['duration']) }}s</th>
<th class="text-center">Duration (s)<br/>{{ '{:.3f}'.format(grand_totals['duration']) }}s</th>
</tr>
</thead>
{% for feature in features %}
Expand All @@ -36,7 +36,7 @@
<td class="text-center">{{ feature['total_scenarios_failed'] }}</td>
<td class="text-center">{{ feature['total_scenarios_skipped'] }}</td>
<td class="text-center"><span class="status-{{ feature['status'] }}">{{ feature['status'] }}</span></td>
<td class="text-center">{{ '{:.3f}'.format(feature['duration']) }}s</td>
<td class="text-center">{{ feature['duration'] }}</td>
</tr>
{% endfor %}
</table>
Expand Down
4 changes: 2 additions & 2 deletions src/cucu/reporter/templates/scenario.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<button class="btn btn-md btn-light" title="scroll to bottom" onclick="window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });" class="nav-link">⬇️ </button>
</li>
<li class="align-middle">
<div style="padding: 8px">Started {{ scenario["started_at"] }} for {{ '{:.3f}'.format(scenario['duration']) }}s</div>
<div style="padding: 8px">Started {{ scenario["started_at"] }} for {{ scenario['duration'] }}</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -75,7 +75,7 @@
{% endif %}
</td>
<td style="text-align: right; margin-top: auto;" class="col-2">
<pre style="display: inline; color: gray;">Offset and Duration</pre>
<pre style="display: inline; color: gray;">Offset and Duration (s)</pre>
</td>
</tr>
{% for step in steps %}
Expand Down

0 comments on commit aaea654

Please sign in to comment.