#结果:
[13/Dec/2021 16:58:38] INFO - 打开Ie浏览器
[13/Dec/2021 16:58:41] WARNING - Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000225D5855040>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /session/0729ca65-d469-4de4-8fb5-bad9eb737391/url
[13/Dec/2021 16:58:43] WARNING - Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000225D586BD30>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /session/0729ca65-d469-4de4-8fb5-bad9eb737391/url
[13/Dec/2021 16:58:45] WARNING - Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000225D586BEB0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /session/0729ca65-d469-4de4-8fb5-bad9eb737391/url
[13/Dec/2021 16:58:47] INFO - it's over
运行脚本
now_path = os.getcwd() # 获取当前路径
report_path = os.path.abspath(os.path.dirname(os.getcwd())) + r'\report' # HTML报告存储路径
log_path = os.path.abspath(os.path.dirname('test_login.py')) # LOG日志存储路径
if not os.path.exists(report_path):
os.mkdir(report_path)
case_path = os.getcwd()
def load_case(casepath=case_path, rule='test_ie.py'):
discover = unittest.defaultTestLoader.discover(casepath, pattern=rule)
return discover
def run_case(test_case):
now = time.strftime("%Y-%m-%d_%H_%M_%S")
report =report_path + './' + now + 'result.html'
print("测试报告生成地址:%s" % report)
file_path = open(report, 'wb')
runner = HTMLTestRunnerCN.HTMLTestReportCN(stream=file_path, verbosity=2, title=u'web登录自动化', description=u"用例执行结果")
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.info(test_case)
log_dir = os.path.abspath(os.path.dirname(os.getcwd()))
log_file_path = log_dir + r'\logs'
# log_file_name = now + ".log"
log_file_name = os.path.join(log_file_path, now + ".log")
print(log_file_path)
file_handle = logging.FileHandler(log_file_name, 'a', encoding='utf-8')
formatter = logging.Formatter('%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s')
file_handle.setFormatter(formatter)
logger.addHandler(file_handle)
runner.run(test_case)
file_path.close()
if __name__ == "__main__":
run_case(test_case=load_case())