只需要一份Yaml文件,即可实现UI自动化

  • Pytest + Selenium/Appium + Yaml + allure 实现的UI自动化测试框架
  1. 使用环境
    allure-pytest==2.13.5
    Appium-Python-Client==4.0.0
    Faker==25.8.0
    Jinja2==3.1.4
    PyMySQL==1.1.1
    pytest==8.2.2
    pytest-xdist==3.6.1
    PyYAML==6.0.1
    selenium==4.21.0
  2. 实现逻辑

    • 初始驱动,返回 driver 
    • 基于显示等待二次封装selenium、appium元素操作方法
    • testcase 目录下添加 conftest.py
      • 添加 pytest_collect_file 方法,收集测试用例。test 开头或结尾的 yaml 文件
      • 添加 pytest_generate_tests 方法,实现参数化
    • 处理 yaml 数据,替换变量
    • 动态创建 pytest 用例
    • 根据 yaml 文件设置的关键字,执行selenium、appium
    • 生成 allure 报告
  3. Yaml文件格式
    config:
      base_url: http://127.0.0.1:8000/login/action/
      variables:
        username: lixiaofeng
        password: 123456
        sql: select au.username  from auth_user au limit 1
      quote: 引用login文件
    test_user_login_case:
    test_message_case:
      test_step:
        - skip: 跳过
        - sleep: "2"
        - screenshot: 异常截图
        - click:
            type: xpath
            locate: //div[@class="navbar-header"]/div[2]/div[3]/button
        - click:
            type: xpath
            locate: //a[@href="/nb/message/"]
        - assert_text:
            type: xpath
            locate: //*[@id="layout-wrapper"]/div[2]/div/div/div[1]/div/div/h4
            text: 消息通知
        - click:
            type: xpath
            locate: //div[@class="pull-right"]/button
        - sleep: "2"
        - assert_text:
            type: id
            locate: prompt-title
            text: 确认要将所有通知标记为【已读】吗?
        - click:
            type: xpath
            locate: //div[@class="modal-content"]/div[3]/button[2]
        - sleep: "2"
        - step: 断言
        - assert_text:
            type: id
            locate: alert
            text: 暂无未读通知
        - screenshot: 成功截图
        - sleep: "3"
      story: 用例-添加模块管理
      title: 添加模块
      description: 该用例是针对 添加模块 的测试
    epic: 接口平台
    feature: 消息模块
  4. Allure报告
    • app

    • web

    • 本地趋势图

       

posted @ 2024-06-20 00:16  backlightズ  阅读(8)  评论(0编辑  收藏  举报