pytest_多用例执行(1)

本文介绍了一个使用pytest和allure进行App自动化测试的例子。包括创建测试套件、编写两个具体的功能测试用例(打开我的信用卡页面与我的钱包页面),并详细展示了如何通过allure生成测试报告。

一、首先创建测试套件

# -*- 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

转载于:https://www.cnblogs.com/jiguanghover/p/pytest.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值