Skip to content

Commit 28e5ffd

Browse files
authored
update tr api logic to report durations (#604)
* update tr api logic to report durations * lint * lint
1 parent 4503a18 commit 28e5ffd

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

modules/browser_object_navigation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ def open_bookmark_in_new_private_window_via_context_menu(
585585
"""
586586
self.panel_ui.element_clickable("bookmark-by-title", labels=[bookmark_title])
587587
self.panel_ui.context_click("bookmark-by-title", labels=[bookmark_title])
588-
self.context_menu.click_on("context-menu-toolbar-open-in-new-private-window")
588+
self.context_menu.click_and_hide_menu(
589+
"context-menu-toolbar-open-in-new-private-window"
590+
)
589591
return self
590592

591593
@BasePage.context_chrome

modules/page_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,15 @@ def get_css_zoom(self):
905905
return float(css_zoom)
906906

907907
# If zoom property is not explicitly set, check the transform scale
908-
css_transform_scale = self.driver.execute_script("""
908+
css_transform_scale = self.driver.execute_script(
909+
"""
909910
const transform = window.getComputedStyle(document.body).transform;
910911
if (transform && transform !== 'none') {
911912
return transform;
912913
} else {
913914
return null;
914-
""")
915+
"""
916+
)
915917

916918
# Parse the transform matrix to extract the scale factor (e.g., matrix(a, b, c, d, e, f))
917919
if css_transform_scale:

modules/testrail.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ def update_test_cases(
387387
testrail_suite_id,
388388
test_case_ids=[],
389389
status="passed",
390+
more_results={},
390391
):
391392
"""Given a project id, a run id, and a suite id, for each case given a status,
392393
update the test objects with the correct status code"""
@@ -404,6 +405,13 @@ def update_test_cases(
404405
for test_case_id in test_case_ids
405406
]
406407
}
408+
for test_case_id, new_item in more_results.items():
409+
if test_case_id in test_case_ids:
410+
for result in data.get("results"):
411+
if result.get("case_id") == test_case_id:
412+
new_field, new_data = new_item.items()
413+
result[new_field] = new_data
414+
407415
return self._update_test_run_results(testrail_run_id, data)
408416

409417
# Private Methods

modules/testrail_integration.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ def mark_results(testrail_session: TestRail, test_results):
216216
result.get("test_case") for result in test_results[category][run_id]
217217
]
218218

219+
# Organize durations
220+
durations = test_results[category][run_id].get("durations")
221+
durations_info = {
222+
tc: {"elapsed": f"{durations.get(tc)}s"} for tc in durations
223+
}
224+
219225
# Don't set passed tests to another status.
220226
test_cases = [tc for tc in all_test_cases if current_results.get(tc) != 1]
221227
logging.warn(
@@ -227,6 +233,7 @@ def mark_results(testrail_session: TestRail, test_results):
227233
testrail_suite_id=suite_id,
228234
test_case_ids=test_cases,
229235
status=category,
236+
more_results=durations_info,
230237
)
231238

232239

@@ -251,6 +258,7 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
251258
cases_in_suite = suite_info.get("cases")
252259
cases_in_suite = [int(n) for n in cases_in_suite]
253260
results = suite_info.get("results")
261+
durations = suite_info.get("durations")
254262
plan_title = expected_plan.get("name")
255263

256264
suite_entries = [
@@ -355,7 +363,11 @@ def organize_entries(testrail_session: TestRail, expected_plan: dict, suite_info
355363
if not test_results[category].get(run_id):
356364
test_results[category][run_id] = []
357365
test_results[category][run_id].append(
358-
{"suite_id": suite_id, "test_case": test_case}
366+
{
367+
"suite_id": suite_id,
368+
"test_case": test_case,
369+
"duration": durations.get(test_case),
370+
}
359371
)
360372

361373
return test_results
@@ -469,6 +481,7 @@ def collect_changes(testrail_session: TestRail, report):
469481
last_suite_id = None
470482
last_description = None
471483
results_by_suite = {}
484+
durations_by_suite = {}
472485
full_test_results = {}
473486
tests = [
474487
test
@@ -498,9 +511,20 @@ def collect_changes(testrail_session: TestRail, report):
498511
outcome = test.get("call").get("outcome")
499512
logging.info(f"TC: {test_case}: {outcome}")
500513

514+
duration = round(
515+
test.get("setup").get("duration")
516+
+ test.get("call").get("duration")
517+
+ test.get("teardown").get("duration")
518+
)
519+
501520
if not results_by_suite.get(suite_id):
502521
results_by_suite[suite_id] = {}
503522
results_by_suite[suite_id][test_case] = outcome
523+
524+
if not durations_by_suite.get(suite_id):
525+
durations_by_suite[suite_id] = {}
526+
durations_by_suite[suite_id][test_case] = duration
527+
504528
if suite_id != last_suite_id:
505529
# When we get the last test_case in a suite, add entry, run, results
506530
if last_suite_id:
@@ -515,6 +539,7 @@ def collect_changes(testrail_session: TestRail, report):
515539
"config_id": config_id,
516540
"cases": cases_in_suite,
517541
"results": results_by_suite[last_suite_id],
542+
"durations": durations_by_suite[last_suite_id],
518543
}
519544

520545
full_test_results = merge_results(
@@ -535,6 +560,7 @@ def collect_changes(testrail_session: TestRail, report):
535560
"config_id": config_id,
536561
"cases": cases_in_suite,
537562
"results": results_by_suite[last_suite_id],
563+
"durations": durations_by_suite[last_suite_id],
538564
}
539565

540566
logging.info(f"n run {last_suite_id}, {last_description}")

tests/bookmarks_and_history/test_open_bookmark_in_private_window_via_toolbar_context_menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from selenium.webdriver import Firefox
33

4-
from modules.browser_object import ContextMenu, Navigation, PanelUi, TabBar
4+
from modules.browser_object import Navigation, TabBar
55
from modules.page_object_generics import GenericPage
66

77

0 commit comments

Comments
 (0)