pytest_多用例执行(1)

一、首先创建测试套件

# -*- coding:utf-8 -*-
from __future__ import print_function
import pytest
import allure

class TestAppSuite(object):
pass

if __name__ == '__main__':
# pytest.main(['-s', '-q','./personal/test_my_car.py', '--alluredir', './appreport/','--clean'])
pytest.main(['-s', '-q', '--alluredir', './appreport/', '--clean'])
# pytest.main()

二、在当前目录下创建第一个测试脚本
# -*- coding:utf-8 -*-
import time
import allure
from apppytest.baseutil.DriverUtil import connect_device_usb


@allure.feature('App自动化测试用例_我的信用卡') # feature定义功能
@allure.story('打开我的信用卡页面') # story定义用户场景
def test_open_my_car():
driver = ''
try:
driver = connect_device_usb()
driver(resourceId="packagename:id/tv_my_car").click(timeout=3)
time.sleep(5)
with allure.step("检查页面标题"): # 将一个测试用例分成几个步骤,将步骤打印到测试报告中,步骤2
allure.attach('页面标题1', driver(resourceId="packagename:id/tv_title").get_text())

driver(text="我的信用卡").click(timeout=3)
with allure.step("打开我的信用卡"):
time.sleep(30)
allure.attach('我的信用卡标题2', driver(resourceId="packagename:id/tv_titlecommon").get_text())

except Exception as e:
print("exception>>",e)
finally:
driver.app_stop("packagename")
time.sleep(3)
三、在当前目录下创建第二个测试脚本
# -*- coding:utf-8 -*-
import time
import allure
from apppytest.baseutil.DriverUtil import connect_device_usb


@allure.feature('App自动化测试用例_我的钱包') # feature定义功能
@allure.story('打开我的钱包页面') # story定义用户场景
def test_open_my_wallet():
driver = ''
try:
driver = connect_device_usb()
driver(resourceId="packagename:id/tv_my_car").click(timeout=3)
time.sleep(5)
with allure.step("检查页面标题"): # 将一个测试用例分成几个步骤,将步骤打印到测试报告中,步骤2
allure.attach('页面标题1', driver(resourceId="packagename:id/tv_title").get_text())

driver(text="我的钱包").click(timeout=3)
with allure.step("打开我的钱包"):
time.sleep(15)
allure.attach('我的钱包标题2', driver(resourceId="packagename:id/tv_titlecommon").get_text())

except Exception as e:
print("exception>>",e)
finally:
driver.app_stop("packagename")
time.sleep(3)
四、执行用例TestAppSuite.py

五、生成html格式测试报告

allure generate  appreport/ -o  appreport/html --clean

posted @ 2019-03-29 17:15  jiguanghover  阅读(1271)  评论(0编辑  收藏  举报