当前位置:网站首页>pytest接口自动化测试框架 | 项目实战(pytest+allure+数据驱动)
pytest接口自动化测试框架 | 项目实战(pytest+allure+数据驱动)
2022-07-16 21:18:00 【COCOgsta】
视频来源:B站《冒死上传!pytest接口自动化测试框架(基础理论到项目实战及二次开发)教学视频【软件测试】》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
/run.py
# 测试报告 unittest pytest 自带的测试 allure
# 好看 付
# 配置环境
# 1.安装allure-pytest pip install allure-pytest 生成测试数据
# 2.下载commandline 压缩包 解压在某个目录 /Users/guoliang/SynologyDrive/SourceCode/software/allure-2.13.5/bin
# 3.配置环境变量 sudo vim ~/.bash_profile
# 生成测试报告 执行用例
import os
import pytest
# alluredir 生成数据 数据文件夹allure-result
# 生成测试报告
# allure generate 执行测试数据 -o 生成测试报告
if __name__ == '__main__':
pytest.main(['py_test.py', '--alluredir', './allure-result'])
os.system('allure generate ./allure-result -o ./reports')/py_test.py
import time
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from config.loadyaml import *
class TestCase:
# 测试登录 测登录之前要做的事情 打开浏览器 访问
# http://39.98.138.157/shopxo/index.php?s=/index/user/logininfo.html
def setup(self):
self.driver = webdriver.Chrome()
self.driver.get("http://39.98.138.157/shopxo/index.php?s=/index/user/logininfo.html")
# 测完了之后 关闭浏览器
def teardown(self):
time.sleep(3)
self.driver.quit()
# 测试登录 成功 输入框输入用户名 密码框输入密码 登录按钮点击一下
# 测试用例失败 用户名不正确 密码正确 操作步骤是一样的 只是数据不同
# 不写死 数据给我 分离 pytest yaml数据 不好的地方 规则比较多
# - 列表[] : 字典 [{'uname':'guoliang', 'upas':'123456'}]
# shop的数据
@pytest.mark.parametrize('udata', loadyaml('./data/login.yaml'))
def test_02(self, udata):
print(udata['uname'])
self.driver.find_element(By.NAME, 'accounts').send_keys(udata['uname'])
self.driver.find_element(By.NAME, 'pwd').send_keys(udata['upas'])
self.driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/form/div[3]/button').click()
# 填充东西 我想要去实现 测试登录 用例 正常用例 异常用例
# 断言
# 预期结果 实际结果
# 优化 1.断言
# 1. 关键字驱动 常用的操作 项目的基本操作 点击 提前封装起来 后面去使用直接使用
# 刷花
# def 刷花():
# 刷花
# 刷花()
# 项目结构
# 2. 项目里面 页面 公司框架 维护 扩展 登录页 下单页 支付页 首页
# 测试数据 分离数据 正常 异常
# 3. 生成测试报告 1.2句代码 html css js代码
# 邮件
# 登录 下单 支付流程 线性代码 加需求 建需求
# 简单:
# 1.测试登录 登录步骤写出来
# 2.数据 用yaml文件分离出来
# 3.不能直接使用 读取yaml文件
# 4.获取数据 传进来 @pytest.mark.parametrize/config/loadyaml.py
# 专门取yaml文件数据
import yaml
# 封装 方便调用
# 打开我的文件数据 r可读
def loadyaml(filename):
stream = open(filename, 'r')
# 读取文件数据
data = yaml.load(stream, yaml.FullLoader)
return data/data/login.yaml
-
uname: guoliang
upas: 123456
-
uname: guoliang2
upas: 123456
-
uname: guoliang3
upas: 123456边栏推荐
- Germany Rexroth proportional valve 4wrpeh6c5b40l-3x/m/24f1
- Mysql相关命令
- 作为一款时序数据库,TDengine 是如何实现并开源其分布式集群功能?
- ROS create workspace process
- 性能测试中问题反思和心得
- Supervised learning week 3: logistic regression option_ Lab harvest record
- Send papers! AI, machine learning, CV boss scientific research project enrollment!
- [fluent -- actual combat] dart language quick start
- Progress [detailed summary]
- EF Core学习笔记:一对多关系配置
猜你喜欢
Cache design

9、学会查看GC日志

Tableqa technology of Ali Dharma academy makes tables speak

Do you want to switch to software testing? A comprehensive analysis

What will the future responsive web design look like under the endless demand of terminal device adaptation?

Reflection and experience on problems in performance testing

三种常用时序数据库对比调研-InfluxDB、Prometheus、IotDB

7、常见的垃圾回收器

深入剖析斐波拉契数列

Buffer Pool 核心原理
随机推荐
[decision tree] use decision tree to diagnose breast cancer
T-infinite Road
EF core learning notes: one to many relationship configuration
Mysql的索引深度讲解
Leetcode daily question (947. most stones removed with same row or column)
【C语言】strlen函数的讲解和模拟实现
Reflection and experience on problems in performance testing
How does go ensure the order of concurrent reads and writes Memory model
6. JVM generational model -- garbage collection in the old age
Raspberry pie uses opencv for image tracking, face recognition, etc
嘘!摸鱼神器,别让老板知道!| 语音实时转文本,时序快速出预测,YOLOv6在就能用,一行命令整理CSV | ShowMeAI资讯日报
Developers must see | devweekly issue 1: what is time complexity?
Buffer Pool 核心原理
App的回归测试,有什么高效的测试方法?
Learning record: FSMC - extended external SRAM
The difference between NPM and NPX
[development of large e-commerce projects] cache distributed lock redisson concise & integration lock redisson resolve deadlock read / write lock lock lock semaphore-44
How to learn MySQL efficiently and systematically?
There is no simpler and more practical single person pose estimation than this
过拟合 欠拟合