目录
本文涵盖内容:
前期准备:
PO模式
计算器页面:
Pytest的fixture特性
Calculator目录下的conftest.py
具体的两个计算器用例
总结:
本文涵盖内容:
- PO模式设计
- allure装饰器及报告
- 运行用例截图(成功失败均截图,通过try except finally)
- 数据驱动
前期准备:
- cd appiumsample-codepython
- 创建文件夹 mkdir calculator
- cd calculator
- 创建pages和cases文件夹
- 拷贝文件
- cp appiumsample-codepythontestconftest.py conftest.py
- cp appiumsample-codepythontesthelpers.py helpers.py
- cd cases && mkdir officialexams && cp appiumsample-codepythontesttest_android_basic_interactions.py officialexamstest_android_basic_interactions.py
- cd appiumsample-codepython
- 创建文件夹 mkdir calculator
- cd calculator
- 创建pages和cases文件夹
- 拷贝文件
- cp appiumsample-codepythontestconftest.py conftest.py
- cp appiumsample-codepythontesthelpers.py helpers.py
- cd cases && mkdir officialexams && cp appiumsample-codepythontesttest_android_basic_interactions.py officialexamstest_android_basic_interactions.py
完整目录结构如下
PO模式
- 参考链接
简单点就是元素定位和数据断言分离(个人理解),driver通过pytest.fixture初始化
创建一个basepage.py,用来元素定位,具体内容如下图(按照自己所需添加元素定位)
计算器页面:
- 具体按钮的定位方法(都是通过id可定位到)
- 通过数据驱动,模拟用户点击按钮。比如:test_input='1+2',就会点击按钮1,按钮加号,按钮2
Pytest的fixture特性
- 想想如果将两个conftest中的scope改成class后会有什么区别
Calculator目录下的conftest.py
- 定义了一个driver
- 定义了一个locator, 主要用来调用元素定位的那些方法。
具体的两个计算器用例
执行- λ pytest cases --alluredir .allure-report
- λ allure serve .allure-report



