zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Mac上搭建Web服务器
    从零开始学ios开发(三):第一个有交互的app
    从零开始学ios开发(二):Hello World!
    C#核心语法
    WP8的新功能-通过一个程序来启动另一个程序
    .NET Web开发技术简单整理
    windows phone 下拉刷新
    使用X.509数字证书加密解密实务(一)-- 证书的获得和管理
    使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
    使用X.509数字证书加密解密实务(二)-- 使用RSA证书加密敏感数据
  • 原文地址:https://www.cnblogs.com/jiguanghover/p/pytest.html
Copyright © 2011-2022 走看看