python+Appium自动化:BSTestRunner执行测试用例,生成测试报告

定义执行用例开始、结束,写入公共模块中,脚本如下:

myunit.py

import unittest
from TB_test.common.TB_caps import appium_desired
import logging

class startend(unittest.TestCase):

    def setUp(self):
        logging.info("=====setUp=====")
        self.driver=appium_desired()

    def tearDown(self):
        logging.info("=====tearDown=====")
        self.driver.quit()

  

测试用例:

test_login.py

import unittest
from TB_test.common.myunit import startend
from TB_test.businessView.loginView import LoginView
import logging,time

class TestLogin(startend):
    #登录信息文件配置地址
    csv_file='../data/account_data.csv'
    def test_login_right(self):
        logging.info("=====test_login_right=====")
        l=LoginView(self.driver)
#调用配置文件 data=l.get_csv_data(self.csv_file,1) l.login_action(data[0],data[1]) self.assertTrue(l.cheak_login()) def test_login_error(self): logging.info("=====test_login_error=====") l=LoginView(self.driver)
#调用配置文件 data=l.get_csv_data(self.csv_file,2) l.login_action(data[0],data[1]) self.assertTrue(l.cheak_login()) time.sleep(5) if __name__ == '__main__': unittest.main()

执行测试用例:

runcase.py

import unittest
from BSTestRunner import BSTestRunner
import time,logging

#用例路径、报告存放路径
test_dir = '../testcase'
report_dir = '../reports'
#加载测试用例
discover = unittest.defaultTestLoader.discover(test_dir,pattern="test_*.py")
print(discover)

#报告命名
now=time.strftime("%y-%m-%d %H_%M_%S")
report_name=report_dir+'/'+now+'testreport.html'

#运行测试用例,生成报告

with open(report_name,"wb")as f:
    runner = BSTestRunner(stream=f,title=u'自动化测试报告,测试结果如下:',description=u'用例执行情况:')
    logging.info("======start runcase======")
    runner.run(discover)

执行用例完成后到报告地址中可查获,注意导入BSTestRunner模块,需提前下载,放置python-lib路径中即可。

猜你喜欢

转载自www.cnblogs.com/bugbreak/p/12517338.html