python +appium生成测试报告相关操作

1、代码

import unittest
import os
from selenium import webdriver
from time import sleep
import HTMLTestRunner
import time


class Dttest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print('start setup')
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['deviceName'] = '1baa0bc4'
        desired_caps['platformVersion'] = '6.0.1'
        desired_caps['appPackage'] = 'com.laoyuegou.android'  # 测试app包名
        desired_caps['appActivity'] = 'com.laoyuegou.android.main.activity.ReSplashActivity'  # 测试appActivity


        cls.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)


    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
        print('tearDown')


    def test_sleep(self):#用例
        sleep(10)
        print('sleep passed')


    def test_clicktap1(self):#用例
        self.driver.find_element_by_name('爱物').click()
        sleep(5)
        print('click passed')


    def test_clicktap2(self):#用例
        self.driver.find_element_by_name('推荐').click()
        sleep(5)
        print('click passed')


if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(Dttest('test_sleep'))#需要测试的用例就addTest,不加的就不会运行
    suite.addTest(Dttest('test_clicktap1'))
    suite.addTest(Dttest('test_clicktap2'))
    #unittest.TextTestRunner(verbosity=1).run(suite)
    timestr = time.strftime('%Y-%m-%d %X',time.localtime(time.time()))#本地日期时间作为测试报告的名字
    filename = '/Users/lizhen/'+timestr+'.html'#这个路径改成自己的目录路径
    fp = open(filename,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
        stream=fp,
        title='result',
        description='report'
    )
    runner.run(suite)

    fp.close()

1、注意点:

下载HTMLTestRunner.py,如果使用的是python3,则将该文件添加到python3对应的文件下

查看自己的python安装路径



你可能感兴趣的:(python +appium生成测试报告相关操作)