BeautifulReport测试报告框架
BeautifulReport测试报告框架
##执行文件excute_case.py
import unittest
import os, datetime
from BeautifulReport import BeautifulReport
root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/')
print('root_dir路径',root_dir)
#test_dir = root_dir + '/testcases'
test_dir = root_dir + '/TestCases'
#report_dir = root_dir + '/test_report'
report_dir = root_dir + '/TestReport'
discover = unittest.defaultTestLoader.discover(test_dir, 'Test*.py', None)
now = datetime.datetime.now().strftime('%Y-%m-%d %H_%M_%S')
filename = '测试报告' + str(now)
BeautifulReport(discover).report(description='测试', filename=filename, log_path=report_dir)
##用例文件TestbfReport.py
import unittest, time,os
from selenium import webdriver
from selenium .webdriver.common.by import By
from BeautifulReport import BeautifulReport
class test_remote(unittest.TestCase):
def save_img(self, test_method):#失败截图方法(必须要定义在class中)
#root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))).replace('\\','/')
root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\','/')
img_path = root_dir + '/img'
self.driver.get_screenshot_as_file\
('{}/{}.png'.format(img_path, test_method))
def setUp(self):
self.driver = webdriver.Chrome()
time.sleep(5)
@BeautifulReport.stop #不执行该用例
def test_zhaolei(self):
self.driver.get('https://www.baidu.com')
self.driver.find_element(By.ID,'kw').send_keys('赵小虎')#元素定位新写法,通过By定位
self.driver.find_element(By.ID,'su').click()
time.sleep(5)
@BeautifulReport.add_test_img('test_zhoujielun')#失败后会有报错截图
def test_zhoujielun(self):
self.driver.get('https://www.baidu.com')
self.driver.find_element(By.ID,'su3').send_keys('周杰伦')#这里的id我故意写错来查看效果
self.driver.find_element(By.ID,'su').click()
time.sleep(5)
def test_ig(self):
self.driver.get('https://www.baidu.com')
self.driver.find_element(By.ID,'kw').send_keys('IG')
self.driver.find_element(By.ID,'su').click()
time.sleep(5)
'''
def tearDown(self):
self.driver.close()
'''
'''
if __name__ == '__main__':
unittest.main()
'''
参考文档:https://blog.csdn.net/qq_37969201/article/details/86689940