From a4a691ce2387cb065abe55d7b65f803698e96e1b Mon Sep 17 00:00:00 2001 From: Jonas <32525495+JoSglch@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:05:22 +0100 Subject: [PATCH] Feature/limit step report output size (#224) * feat: limit step report output size --- .../test_stepreport/stepreport_example.py | 58 +++++++++++++++++++ .../test_result/templates/report_template.css | 5 ++ .../templates/report_template.html.j2 | 48 ++++++++++----- .../templates/report_template_script.js | 40 +++++++++++++ 4 files changed, 136 insertions(+), 15 deletions(-) create mode 100644 src/pykiso/test_result/templates/report_template_script.js diff --git a/examples/test_stepreport/stepreport_example.py b/examples/test_stepreport/stepreport_example.py index 3eb127ca..6eed2062 100644 --- a/examples/test_stepreport/stepreport_example.py +++ b/examples/test_stepreport/stepreport_example.py @@ -109,3 +109,61 @@ def test_run(self): self.assertAlmostEqual(voltage, 4, delta=1, msg="Check voltage device") logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!") + + +@pykiso.define_test_parameters( + suite_id=1, + case_id=3, +) +class WrapLongTextTest(pykiso.BasicTest): + """This test shows wrapping of long results into foldable html elements""" + + def setUp(self): + """Set header information and check setup conditions""" + super().setUp() + # additional data to include in the step-report + self.step_report.header["Version_device"] = "2022-1234" + + def test_run(self): + """Write long results to the step report to show how foldable html + elements get used to make the report overview more readable + """ + logging.info( + f"--------------- RUN: {self.test_suite_id}, {self.test_case_id} ---------------" + ) + + # data to test + device_on = True + actual_dummy_result = {"result": True} + expected_dummy_result = { + "result": "pykiso is an integration test framework. With it, it is possible to write: Whitebox integration tests directly on my target device, Graybox integration tests to make sure the communication-link with my target device is working as expected, Blackbox integration tests to make sure my external device interfaces are working as expected", + } + + # check that it works with multiple tables + self.step_report.current_table = "First table" + + self.assertEqual( + expected_dummy_result, + expected_dummy_result, + msg="The very long message should be wrapped", + ) + + self.step_report.current_table = "Second table" + + with self.subTest("Non critical checks"): + # This check will fail but the test continues + self.assertFalse(device_on, msg="Some check") + + # assert with custom message + # assert msg overwritten when step_report_message not null + self.step_report.message = "Big data message" + + self.assertEqual( + expected_dummy_result, expected_dummy_result, msg="Check big data" + ) + + self.assertEqual( + expected_dummy_result, actual_dummy_result, msg="Check big data" + ) + + logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!") diff --git a/src/pykiso/test_result/templates/report_template.css b/src/pykiso/test_result/templates/report_template.css index 427cf993..fdc81b09 100644 --- a/src/pykiso/test_result/templates/report_template.css +++ b/src/pykiso/test_result/templates/report_template.css @@ -61,6 +61,11 @@ body { text-transform: uppercase; } + summary { + text-decoration: underline; + cursor: pointer; + } + /* Media Queries*/ @media screen and (max-width: 600px) { diff --git a/src/pykiso/test_result/templates/report_template.html.j2 b/src/pykiso/test_result/templates/report_template.html.j2 index 85c45189..96680473 100644 --- a/src/pykiso/test_result/templates/report_template.html.j2 +++ b/src/pykiso/test_result/templates/report_template.html.j2 @@ -4,32 +4,31 @@
- {# For each TestClass #} + {# For each TestClass -#} {% for class_name, class_content in ALL_STEP_REPORT.items() -%} {{class_content["description"] | replace("\n", "
\n") }}
{{class_content["description"] | replace("\n", "
\n") }}
- {# Add additional information from header key #} + {# Add additional information from header key -#} {% for data in [class_content["time_result"], class_content["header"]] -%} {% for key, value in data.items() -%} {{key}}: {{value}} {%- endfor %} {%- endfor %}
- - {# For each test (setUp, run, tearDown) #} - {% for test_name, test_content in class_content["test_list"].items() -%} + {#- For each test (setUp, run, tearDown) -#} + {% for test_name, test_content in class_content["test_list"].items() %} {% set test_success = is_test_success(test_content) -%}Step | {% for column_name in test_content[0].keys() if column_name != "succeed" -%}{{column_name}} | @@ -46,7 +45,7 @@
---|---|
{{loop.index}} | - {# Loop over each cell of the row -#} + {#- Loop over each cell of the row -#} {% for col_value in row.values() -%} - {# Set the value and apply colors to the cell -#} + {#- Set the value and apply colors to the cell #}
- {{col_value}}
+ {# Use a if content is too long for better results overview and synchronize toggling them per row -#}
+ {% if col_value | string | length > 100 -%}
+
+
+ {%- else -%}
+ {{col_value | string | truncate(53, true, leeway = 0)}}++
+ {{col_value}}
+
+
+ {{col_value}}
+
+ {%- endif %}
|
{%- endfor %}