微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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路径中即可。

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐