全文目录,一步到位
1.前言简介
文章初稿.
格式
以及使用细节稍后补充, 感谢zjr测试
的大力支持
1.1 专栏传送门
2. python使用
2.1 简介
2.1.1
1、下载JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html](http://www.oracle.com/technetwork/java/javase/downloads/index.html
配置jdk环境
2.打开高级系统设置→环境变量
3.新建,变量名为:JAVA_HOME;变量值:C:\Program Files\Java\jdk1.8.0_271 变量值实际是安装后的JDK路径。
4.找到Path,双击或者点击编辑进行编辑
5.新建一个:%JAVA_HOME%\bin点击确定进行保存。
6.测试是否配置成功,Windows命令输入javac出现如图所示表示jdk配置成功。
7.输入 "java -version" 可以查看JDK版本
1、安装allure报告插件
<1>下载allure插件:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.13.2/
下载好以后,解压,放到一个目录里,记住目录位置
<2>配置allure环境变量
allure文件的路径配置到环境变量-path里。步骤略
D:\allure-2.12.0\bin
2、之后再pip命令安装allure插件
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple allure-pytest
3、两行命令,生成allure测试报告
先cd到根目录
pytest aisce_test.py --alluredir=allure # 生成allure 数据 "aisce_test.py"文件名随着项目名更改
allure generate ./allure/ -o ./reports --clean # 生成allure报告到reports文件夹里 “allure” “reports”文件名可以更改
"""
2.1.2 代码
import allure
import pytest
import requests
import random
data = {
"code": "0",
"password": "123456",
"username": "pzy",
"uuid": "code-key519afa3acffb451eaf09d427efe1a139"
} # todo: 定义变量
project_url = "https://test.***.com" # todo: 定义一个全局的url地址
@allure.feature("登录")
class TestCRMEB():
@pytest.fixture(scope='function', autouse=True) # todo: True 都执行,False都不执行
def login(self):
response = requests.post(url=project_url + "/login", json=data) # todo:登录接口
self.token_ = response.json()['token'] # todo:获取token /test/list
@allure.feature("查询")
def test_task_select(self):
response_task_select = (requests.post(url=project_url + "/test/list",
headers={"Authorization": "Bearer " + self.token_},
json={"year": 2024, "month": "06", "deptId": "", "userId": "",
"status": 1, "port": 2}))
assert response_task_select.status_code == 200
assert response_task_select.json()['msg'] == 'success'
# print(response_task_select.json())#todo:输出打印json
self.id = response_task_select.json()['data'][0]['id']
@allure.feature("新增")
def test_task_add(self):
response_task_add = (requests.post(url=project_url + "/test/insert",
headers={"Authorization": "Bearer " + self.token_},
json={"taskName": "测试任务" + str(random.randint(0, 100)),
"startTime": "2024-01-01 00:00:00", "endTime": "2025-12-31 23:59:59",
"period": 1, "startMonth": "2024-01", "endMonth": "2025-12",
"number": "1", "type": 1,
"staffs": [{"deptId": "", "type": 2, "userId": "684700931502497792",
"userName": "贾东晨业务员"}],
"standards": [{
"img": "https://***/2024/unknown/1/845bbde7-eb03-4f04-b2f6-b7eb6d8724fd.jpg",
"title": "测试", "remark": "测试"}]}
))
assert response_task_add.status_code == 200
assert response_task_add.json()['msg'] == 'success'
@allure.feature("增加")
def test_task_reward(self):
self.test_task_select()
response_task_reward = (
requests.post(url=project_url + "/test/update",
headers={"Authorization": "Bearer " + self.token_},
json={"id": "" + self.id, "level1Price": "10", "level2Price": "10", "level3Price": "-10",
"level4Price": "-10"}))
assert response_task_reward.status_code == 200
assert response_task_reward
@allure.feature("删除")
def test_task_delete(self):
self.test_task_select()
# print(self.id)
response_task_delete = (
requests.get(url=project_url + "/test/delete?id=" + self.id,
headers={"Authorization": "Bearer " + self.token_}))
assert response_task_delete.status_code == 200
assert response_task_delete.json()['msg'] == 'success'
@allure.feature("筛选")
def test_task_sift(self):
response_task_sift = (requests.post(url=project_url + "/test/list",
headers={"Authorization": "Bearer " + self.token_},
json={"year": 2024, "month": "06", "deptId": "",
"userId": "455763267652096000", "status": 1, "port": 2}))
assert response_task_sift.status_code == 200
assert response_task_sift.json()['msg'] == 'success'
if __name__ == '__main__':
pytest.main()
2.2
2.2.1
2.2.2
2.3
2.3.1
2.3.2
2.4
2.4.1
2.4.2
3. 基础语法总结案例
3.1
3.1.1
3.1.2
3.2
3.2.1
3.2.2
4. 文章的总结与预告
4.1 本文总结
4.2 下文预告
作者pingzhuyan 感谢观看