From 2f9db91f9e63e7b746770b17c2c9204ff663a7de Mon Sep 17 00:00:00 2001 From: duerpei Date: Sat, 22 Oct 2022 16:55:45 +0800 Subject: agl-test-framework: optimize the generated html report Optimize the generated html report, make its format more beautiful and readable. Bug-AGL: SPEC-4345 Signed-off-by: duerpei Change-Id: I0b779e0998ded00b348e23f2c1ac5b8acf5b8fd8 --- plugins/agl_test_report.py | 107 +++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 77 deletions(-) (limited to 'plugins/agl_test_report.py') diff --git a/plugins/agl_test_report.py b/plugins/agl_test_report.py index 5896722..ad7b9e6 100644 --- a/plugins/agl_test_report.py +++ b/plugins/agl_test_report.py @@ -1,5 +1,6 @@ import json import shutil +import subprocess import plugins.agl_test_conf as conf @@ -103,58 +104,6 @@ def write_data_to_json(THIS_TEST,test_set_status,summary,case_status): #Write the "data" to the json file write_data_to_file(data, "json") -def get_report_html(THIS_TEST,test_set_status,summary,case_status): - html = "" - - # - html = html + "" - html = html + "" - html = html + THIS_TEST + "test report" - html = html + "" - html = html + "" - - # - html = html + "" - html = html + "

" + THIS_TEST + " test report" + "

" - html = html + "

" + "Status :" + test_set_status + "

" - html = html + "

" + "Total: " + str(summary[0][1]) - html = html + " Pass: " + str(summary[1][1]) - html = html + " Xpass: " + str(summary[2][1]) - html = html + " Fail: " + str(summary[3][1]) - html = html + " Xfail: " + str(summary[4][1]) - html = html + " Skip: " + str(summary[5][1]) + "

" - html = html + "

Details :

" - - #
- html = html + "" - html = html + "" - html = html + "" - html = html + "" - html = html + "" - - #Add content to the table - bgcolor = 0 - for test_case in case_status: - if bgcolor == 0: - html = html + "" - bgcolor = 1 - else: - html = html + "" - bgcolor = 0 - html = html + "" - html = html + "" - html = html + "" - - html = html + "
test casestatus
" + test_case + "" + case_status[test_case] + "
" - html = html + "

" - html = html + "Detail log :" - #TODO update the link address for log.zip - html = html + "log.zip" - html = html + "" - html = html + "" - - return html - def write_to_html_file(THIS_TEST,html): html_path = conf.get_html_filename(THIS_TEST) html_file = open(html_path,"w") @@ -162,6 +111,11 @@ def write_to_html_file(THIS_TEST,html): html_file.close() def create_gen_web_page(filename, tlpname, html_data): + #Get timestamp + date_F = subprocess.getoutput("date +%F") + html_data["date_F"] = date_F + date_T = subprocess.getoutput("date +%T") + html_data["date_T"] = date_T # here, jinja2 module should be installed first from jinja2 import Environment,FileSystemLoader env = Environment(loader=FileSystemLoader(conf.get_tpl_dir())) @@ -190,38 +144,37 @@ def change_json_to_html(test_set_name): json_file = conf.get_json_filename(test_set_name) html_file = conf.get_html_filename(test_set_name) #read data from json file - html_data = dict() + summary_data = dict() with open(json_file,'r') as f: - html_data = json.load(f) + summary_data = json.load(f) f.close() #format json data to html data - html_data["case_status_html"] = format_case_status_table(html_data["case_status"]) + html_data = format_html_data(summary_data) #save data to html file write_data_to_file(html_data, "html") -def format_case_status_table(case_status): - html_data = "" - #init table title - bgcolor = conf.BGCOLOR_TABLE_TITLE - color = conf.COLOR_TABLE_TITLE - html_data += "\t\n" - html_data += "\t\t test case \n" - html_data += "\t\t status \n" - html_data += "\t\n" - +#def format_case_status_table(case_status): +def format_html_data(summary_data): #init all rows - bgcolor = conf.BGCOLOR_DARK + case_status = summary_data["case_status"] + html_data = "" for key in case_status: - if ( bgcolor == conf.BGCOLOR_DARK ): - html_data += "\t\n" - bgcolor = conf.BGCOLOR_LIGHT - else: - html_data += "\t\n" - bgcolor = conf.BGCOLOR_DARK - html_data += "\t\t" + key + "\n" - html_data += "\t\t" + case_status[key] + "\n" - html_data += "\t\n" - return html_data - + html_data += "\t\t\t\n" + html_data += "\t\t\t\t\n" + html_data += "\t\t\t\t" + html_data += str.capitalize(case_status[key]) +"\n" + html_data += "\t\t\t\t" + key + "\n" + html_data += "\t\t\t\t\n" + html_data += "\t\t\t\n" + summary_data["case_status_html"] = html_data + + #Create summry status in html + status_html = "" + status_html += "\t\t

test suite status : " + status_html += str.capitalize(summary_data["test_status"]) + "

" + summary_data["test_suite_status_html"] = status_html + + return summary_data -- cgit 1.2.3-korg