需要在html页面中生成一个报告,其中包含测试用例的摘要。有30多个屏幕,我需要在每个屏幕名称的末尾显示屏幕名称和测试用例数量的通过百分比。我正在使用python和javascript以及html。
我尝试了以下代码:
def screen_name(self,screenName):
try:
if(self.accord==0):
self.htmlapp.write("<button class=\"accordion1\">"+screenName+ "<span id =\"Pass_Percentage\" style=\"float:right;color:#2E8B57\"> </span></button>")
self.accord=1
debug_report.log("HTMLModule", "screen_name", "INFO", "screenname is passed as an argument")
#return screenName
else:
self.htmlapp.write("<button class=\"accordion2\">"+screenName+"<span id =\"Pass_Percentage\" style=\"float:right;color:#2E8B57\"> </span></button>")
self.accord=0
debug_report.log("HTMLModule", "screen_name", "INFO", "screenname is passed as an argument")
return screenName
except BaseException as Err:
debug_report.log("HTMLModule", "screen_name", "Info", "exception in screenname function")
debug_report.log("HTMLModule", "screen_name", "Error Info", Err)
return UNKNOWN_ERROR
def resultstableend(self,):
try:
self.Pass_Percentage = int(self.pass_count * 100 / (self.pass_count + self.fails_count))
print('pass=',self.pass_count,"\nfail=",self.fails_count,"\npass_percentage=",self.Pass_Percentage)
self.htmlapp.write("<script>document.getElementById(\"Pass_Percentage\").innerText=\"" + str(self.Pass_Percentage) + "%""\";</script>")
self.htmlapp.write("</table><br></div>")
self.htmlapp.write("</div>")
except BaseException as Err:
debug_report.log("HTMLModule", "resultstableend", "Info", "exception in resultstableend function")
debug_report.log("HTMLModule", "resultstableend", "Error Info", Err)
预期结果:(说) SCREENNAME-1 100% SCREENNAME-2 80% 实际结果: SCREENNAME-1 80% SCREENNAME-2
在第二次迭代中,将screenname-1百分比替换为screenname-2百分比,而screenname-2不显示任何内容。 如果有人指导我,我会很高兴。