Skip to content

Commit

Permalink
Adding execution start/end times to the HTML report header
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalinn committed Aug 23, 2024
1 parent b2daf59 commit 9257d57
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version: 4.0.1
ENHANCEMENTS:

* Changing core implementation to perform parallel executions, by using **concurrent.futures.ProcessPoolExecutor** instead of **multiprocessing.Pool**. This change was done to avoid BehaveX to crash when running in parallel and a test scenario crashes. `Issue #114 <https://github.com/hrcorval/behavex/issues/114>`_
* Adding execution start time and end time to the HTML report header.
* Improved progress bar to create a new line after completion.

FIXES:
Expand Down
16 changes: 16 additions & 0 deletions behavex/global_vars.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os
import time


class GlobalVars:
Expand All @@ -25,6 +26,8 @@ def __init__(self):
self._steps_definitions = {}
self._rerun_failures = False
self._progress_bar_instance = None
self._execution_start_time = time.time()
self._execution_end_time = None

@property
def execution_path(self):
Expand Down Expand Up @@ -74,5 +77,18 @@ def progress_bar_instance(self):
def progress_bar_instance(self, progress_bar_instance):
self._progress_bar_instance = progress_bar_instance

@property
def execution_start_time(self):
return self._execution_start_time

@property
def execution_elapsed_time(self):
return time.time() - self._execution_start_time

@property
def execution_end_time(self):
if not self._execution_end_time:
self._execution_end_time = time.time()
return self._execution_end_time

global_vars = GlobalVars()
3 changes: 3 additions & 0 deletions behavex/outputs/bootstrap/css/behavex.css
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,6 @@ ul.list-unstyled.scenario-step > li {
.table-scenario{
table-layout: fixed;
}
.hoverable-text:hover{
color: #FFFFFF;
}
10 changes: 9 additions & 1 deletion behavex/outputs/jinja/base.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@
<div class="navbar-header">
<a class="navbar-brand">BehaveX</a>
</div>
<div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<!-- icon behavex-->
<li class="nav-item {% if menu == 'report' %}active{% endif %}">
<a class="nav-link" href="{{ path_report}}">Test Report</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">
<div class="navbar-text" style="padding: 0;margin: 0;margin-top: 4px;">
<small class="hoverable-text"><b>Start time:</b> {{ execution_start_time }}</small><br>
<small class="hoverable-text">&nbsp;&nbsp;<b>End time:</b> {{ execution_end_time }}</small>
</div>
</li>
</ul>
</div>
</div>
</nav>
Expand Down
6 changes: 5 additions & 1 deletion behavex/outputs/report_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import absolute_import

import os
import time
from collections import OrderedDict

import csscompressor
Expand Down Expand Up @@ -116,6 +117,8 @@ def export_result_to_html(
totals, summary = export_to_html_table_summary(features)
tags, scenarios = get_value_filters(features)
steps_summary = gather_steps_with_definition(features, steps_definition)
execution_start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(global_vars.execution_start_time))
execution_end_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(global_vars.execution_end_time))
parameters_template = {
'environments': environment,
'features': features,
Expand All @@ -125,7 +128,8 @@ def export_result_to_html(
'joined': joined,
'report': report,
'tags': list(tags),
'scenarios': scenarios,
'execution_start_time': execution_start_time,
'execution_end_time': execution_end_time
}
parameters_template.update(metrics_variables)
template_handler = TemplateHandler(global_vars.jinja_templates_path)
Expand Down
18 changes: 5 additions & 13 deletions behavex/outputs/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,15 @@ def gather_errors(scenario, retrieve_step_name=False):

def pretty_print_time(seconds_float, sec_decimals=1):
seconds_float = round(seconds_float, sec_decimals)
minutes, seconds = divmod(seconds_float, 60)
hours, minutes = divmod(minutes, 60)

hours, remainder = divmod(seconds_float, 3600)
minutes, seconds = divmod(remainder, 60)
seconds = (
int(seconds) if float(seconds).is_integer() else round(seconds, sec_decimals)
)

def _pretty_format(cant, unit):
return '{}{}'.format(cant, unit) if cant > 0 else ''

time_string = '{} {} {}'.format(
_pretty_format(int(hours), 'h'),
_pretty_format(int(minutes), 'm'),
_pretty_format(seconds, 's'),
)
time_string = '0s' if time_string.strip() == '' else time_string
return time_string
return f'{cant}{unit}' if cant > 0 else ''
time_string = f'{_pretty_format(int(hours), "h")} {_pretty_format(int(minutes), "m")} {_pretty_format(seconds, "s")}'
return "0s" if time_string.strip() == '' else time_string


def normalize_path(path):
Expand Down
6 changes: 4 additions & 2 deletions behavex/progress_bar.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import sys
import time

from behavex.global_vars import global_vars


class ProgressBar:
def __init__(self, prefix, total, bar_length=20, print_updates_in_new_lines=False):
self.prefix = prefix
self.total = total
self.bar_length = bar_length
self.current_iteration = 0
self.start_time = time.time()
self.start_time = global_vars.execution_start_time
self.print_in_new_lines = print_updates_in_new_lines

def start(self, start_increment=0):
Expand All @@ -33,7 +35,7 @@ def _print_progress_bar(self, new_line=False):
percent = 100 * (self.current_iteration / float(self.total))
filled_length = int(self.bar_length * self.current_iteration // self.total)
bar = '█' * filled_length + '-' * (self.bar_length - filled_length)
elapsed_time = time.time() - self.start_time
elapsed_time = global_vars.execution_elapsed_time
elapsed_formatted = time.strftime("%M:%S", time.gmtime(elapsed_time))
progress_bar_content = f"\r{prefix}{percent:.0f}%|{bar}| {self.current_iteration}/{self.total} [{elapsed_formatted}]\r"
if self.print_in_new_lines or new_line or percent == 100:
Expand Down
4 changes: 2 additions & 2 deletions behavex/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def launch_behavex():
json_reports = []
execution_codes = []
results = None
time_init = time.time()
time_init = global_vars.execution_start_time
config = conf_mgr.get_config()
features_path = os.environ.get('FEATURES_PATH')
parallel_scheme = get_param('parallel_scheme')
Expand Down Expand Up @@ -243,7 +243,7 @@ def launch_behavex():
lock,
show_progress_bar)
wrap_up_process_pools(process_pool, json_reports, scenario)
time_end = time.time()
time_end = global_vars.execution_end_time

if get_param('dry_run'):
msg = '\nDry run completed. Please, see the report in {0}' ' folder.\n\n'
Expand Down

0 comments on commit 9257d57

Please sign in to comment.