web自动化测试框架封装

POM封装

page object Model 页面对象设计模式

使用面向对象的思想,对必测页面进行封装,主要用在UI自动化测试

1.使用对象(python代码)代表页面(html代码)

2.使用对象的属性代表页面的元素

3.使用对象的代表页面的操作

1.分析被测页面

例如:登录、搜索、购买、支付

2.抽象Base page

本项目被测页面的共有特性

  • 都有特定的地址
  • 需要定位元素
  • 需要对元素进行交互
  • 需要获取系统提示

不同特性:

  • url中存在变量
  • 定位表达式可能也有变量

3.定义page

4.使用po编写测试用例

一、创建基本架构

--core    #框架核心代码

--logs  #日志文件

--report  #测试报告

--temps   #临时文件夹

--testcase  #测试用例

--main.py   #框架启动入口

--pytest.ini   #框架配置文件

--requirements.txt   #第三方依赖清单

--conftest.py   #全局夹具

--RADEME.md   #框架说明文档

 

二、填写基本内容

requirements.txt 

webdriver-helper   webdriver驱动
pytest  pytest测试框架
pytest-rerunfailures  失败重跑
allure-pytest  测试报告

pytest.ini 配置文件

[pytest]
addopts =
    --alluredir  ./temps
    --clean-alluredir
    --reruns 2

log_cli = 0
log_file = ./logs/test.log
log_file_level = info
log_file_format = %(levelname)-8s %(asctime)s [%(name)s:%(lineno)s] : %(message)s
log_file_data_format = %Y-%m-%d  %H:%m:%s

conftest 夹具

1 from webdriver_helper import get_webdriver
4 def driver():
5     d = get_webdriver()
6 
7     yield d
8 
9     d.quit()

 

posted @ 2023-05-10 16:39  许大维  阅读(84)  评论(0)    收藏  举报