Selenium第8课 生成html报告

一、跳过测试用例

1.无条件跳过,在用例上面加一个装饰器:@unittest.skip(提示语句)

2.条件为True时跳过,加装饰器:@unittest.skipIf((条件),(提示语句))

3.条件为False时跳过,加装饰器:@unittest.skipUnless((条件),(提示语句))

 

二、测试工程

1.目录分类:cases common report run_all_cases.py

2.run_all_cases.py里面查找所有用例:discover = unittest.defaultTestLoader.discover(start_dir="E://test...", pattern=test*.py)

3.生成测试报告:使用群文件,在common目录下新建一个HTMLreport.py,把群文件的内容复制进去,然后直接在run_all...里面导入使用:

from common.HTMLreport import HTMLTestRunner

reportpath = "E:\\test...\\report.html

fp = open(reportpath, "wb")

runner = HTMLTestRunner(fp)  # verbosity=2, title= , descreption , re_try= ,

runner.run(discover)

fp.close()

 

三、关于路径:

import os

curpath = os.path.realpath(__file__)  # 获取当前路径

curdir = os.path.dirname(curpath)  # 当前路径的上级文件夹名称

ke6 = os.path.join(os.path.dirname(curdir), "ke6")  # 路径拼接

 

四、时间戳:

import time

now = time.strftime("%Y-%m-%d %H:%M:%S")

time.time()

time.ctime()

 

五、文件读写IO

f = open("D:\\test.txt", "r")

r 读 w 写 a 追加 r+ 读写 w+ 先清除内容再读写 b 二进制定入

 

相关文章