4、httprunner参数化

2023-12-30 12:08
文章标签 参数 httprunner

本文主要是介绍4、httprunner参数化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、parameters参数

运行次数是笛卡尔积的计算方式,如下将运行2*2=4次

yml方式

config:name: 登录幕布variables: {}parameters:phone: ['13104978922','13722349423']password: ['123456','2345']verify: false
teststeps:
-   name: /v3/api/user/phone_loginrequest:headers:accept: application/json, text/plain, */*accept-encoding: gzip, deflate, braccept-language: zh-CN,zh;q=0.9content-length: '69'content-type: application/json;charset=UTF-8data-unique-id: 7b70bf17-50f2-470e-ae20-ecbbd0d6190fjwt-token: ''origin: https://mubu.comreferer: https://mubu.com/sec-ch-ua: '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"'sec-ch-ua-mobile: ?0sec-ch-ua-platform: '"Windows"'sec-fetch-dest: emptysec-fetch-mode: corssec-fetch-site: same-siteuser-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36version: 3.0.0-2.0.0.1824x-request-id: 8a061286-b850-40a2-b680-6a0314367fedjson:callbackType: 0password: $passwordphone: $phonemethod: POSTurl: https://api2.mubu.com/v3/api/user/phone_loginvalidate:-   eq:- status_code- 200-   eq:- body.code- 0

py文件方式

# NOTE: Generated By HttpRunner v3.1.6
# FROM: testcases\ddt\create_dir.ymlimport pytest
from httprunner import Parametersfrom httprunner import HttpRunner, Config, Step, RunRequest, RunTestCaseclass TestCaseCreateDir(HttpRunner):@pytest.mark.parametrize("param", Parameters({"newfile": ["新增文件夹1", "新增文件夹2", "新增文件夹3"]}))def test_start(self, param):super().test_start(param)config = Config("HttpRunner实现幕布接口增删改查").verify(False)teststeps = [Step(RunRequest("幕布-新增文件夹").post("https://api2.mubu.com/v3/api/list/create_folder").with_headers(**{"accept": "application/json, text/plain, */*","accept-encoding": "gzip, deflate, br","accept-language": "zh-CN,zh;q=0.9","content-length": "33","content-type": "application/json;charset=UTF-8","data-unique-id": "7b70bf17-50f2-470e-ae20-ecbbd0d6190f","jwt-token": "${get_token()}","origin": "https://mubu.com","referer": "https://mubu.com/","sec-ch-ua": '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',"sec-ch-ua-mobile": "?0","sec-ch-ua-platform": '"Windows"',"sec-fetch-dest": "empty","sec-fetch-mode": "cors","sec-fetch-site": "same-site","user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36","version": "3.0.0-2.0.0.1824","x-request-id": "195dee55-182a-4eb7-a307-714fa3f72dd1",}).with_json({"folderId": "0", "name": "$newfile"}).validate().assert_equal("status_code", 200).assert_equal("body.code", 0)),]if __name__ == "__main__":TestCaseCreateDir().test_start()

二、debugtalk.py方式

直接使用${函数名()} 调用

# NOTE: Generated By HttpRunner v3.1.6
# FROM: har\create_dir.yml
from typing import Dictimport pytest
from httprunner import HttpRunner, Config, Step, RunRequest, Parameters
#取别名,防止pytest 把导入的以Test开头的用例也执行了
from testcases.login_test import TestCaseLogin as Loginclass TestCaseCreateDirDeTalk(HttpRunner):@pytest.mark.parametrize("param", Parameters({"filename": "${get_file_name()}"}))def test_start(self, param):super().test_start(param)config = Config("HttpRunner实现幕布接口-文件夹add操作")\.verify(False).export(*['folder_id','param'])teststeps = [Step(RunRequest("幕布-新增文件夹").post("https://api2.mubu.com/v3/api/list/create_folder").with_headers(**{"accept": "application/json, text/plain, */*","accept-encoding": "gzip, deflate, br","accept-language": "zh-CN,zh;q=0.9","content-length": "33","content-type": "application/json;charset=UTF-8","data-unique-id": "7b70bf17-50f2-470e-ae20-ecbbd0d6190f","jwt-token": "${get_token()}","origin": "https://mubu.com","referer": "https://mubu.com/","sec-ch-ua": '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',"sec-ch-ua-mobile": "?0","sec-ch-ua-platform": '"Windows"',"sec-fetch-dest": "empty","sec-fetch-mode": "cors","sec-fetch-site": "same-site","user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36","version": "3.0.0-2.0.0.1824","x-request-id": "195dee55-182a-4eb7-a307-714fa3f72dd1",}).with_json({"folderId": "0","name": "$filename"}).extract().with_jmespath('body.data.folder.id',"folder_id").validate().assert_equal("status_code", 200).assert_equal("body.code", 0)),]if __name__ == "__main__":TestCaseCreateDirDeTalk().test_start()

三、CSV方式

1、新建文件 testdata/userpwd.csv

phone,password
13822228765,12312
13822508211,baba139262265
13822508676,baba139262144

2、yml方式

config:name: 登录幕布variables: {}parameters:phone-password: ${P(testdata/userpwd.csv)}verify: false
teststeps:
-   name: /v3/api/user/phone_loginrequest:headers:accept: application/json, text/plain, */*accept-encoding: gzip, deflate, braccept-language: zh-CN,zh;q=0.9content-length: '69'content-type: application/json;charset=UTF-8data-unique-id: 7b70bf17-50f2-470e-ae20-ecbbd0d6190fjwt-token: ''origin: https://mubu.comreferer: https://mubu.com/sec-ch-ua: '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"'sec-ch-ua-mobile: ?0sec-ch-ua-platform: '"Windows"'sec-fetch-dest: emptysec-fetch-mode: corssec-fetch-site: same-siteuser-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36version: 3.0.0-2.0.0.1824x-request-id: 8a061286-b850-40a2-b680-6a0314367fedjson:callbackType: 0password: $passwordphone: $phonemethod: POSTurl: https://api2.mubu.com/v3/api/user/phone_loginvalidate:-   eq:- status_code- 200-   eq:- body.code- 0

2、py文件方式

# NOTE: Generated By HttpRunner v3.1.6
# FROM: testcases\ddt\login_ddt_csv.ymlimport pytest
from httprunner import Parametersfrom httprunner import HttpRunner, Config, Step, RunRequest, RunTestCaseclass TestCaseLoginDdtCsv(HttpRunner):@pytest.mark.parametrize("param", Parameters({"phone-password": "${P(testdata/userpwd.csv)}"}))def test_start(self, param):super().test_start(param)config = Config("登录幕布").verify(False)teststeps = [Step(RunRequest("/v3/api/user/phone_login").post("https://api2.mubu.com/v3/api/user/phone_login").with_headers(**{"accept": "application/json, text/plain, */*","accept-encoding": "gzip, deflate, br","accept-language": "zh-CN,zh;q=0.9","content-length": "69","content-type": "application/json;charset=UTF-8","data-unique-id": "7b70bf17-50f2-470e-ae20-ecbbd0d6190f","jwt-token": "","origin": "https://mubu.com","referer": "https://mubu.com/","sec-ch-ua": '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',"sec-ch-ua-mobile": "?0","sec-ch-ua-platform": '"Windows"',"sec-fetch-dest": "empty","sec-fetch-mode": "cors","sec-fetch-site": "same-site","user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36","version": "3.0.0-2.0.0.1824","x-request-id": "8a061286-b850-40a2-b680-6a0314367fed",}).with_json({"callbackType": 0, "password": "$password", "phone": "$phone"}).validate().assert_equal("status_code", 200).assert_equal("body.code", 0)),]if __name__ == "__main__":TestCaseLoginDdtCsv().test_start()

这篇关于4、httprunner参数化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/552799

相关文章

详解Spring Boot接收参数的19种方式

《详解SpringBoot接收参数的19种方式》SpringBoot提供了多种注解来接收不同类型的参数,本文给大家介绍SpringBoot接收参数的19种方式,感兴趣的朋友跟随小编一起看看吧... 目录SpringBoot接受参数相关@PathVariable注解@RequestHeader注解@Reque

Java向kettle8.0传递参数的方式总结

《Java向kettle8.0传递参数的方式总结》介绍了如何在Kettle中传递参数到转换和作业中,包括设置全局properties、使用TransMeta和JobMeta的parameterValu... 目录1.传递参数到转换中2.传递参数到作业中总结1.传递参数到转换中1.1. 通过设置Trans的

java如何调用kettle设置变量和参数

《java如何调用kettle设置变量和参数》文章简要介绍了如何在Java中调用Kettle,并重点讨论了变量和参数的区别,以及在Java代码中如何正确设置和使用这些变量,避免覆盖Kettle中已设置... 目录Java调用kettle设置变量和参数java代码中变量会覆盖kettle里面设置的变量总结ja

spring 参数校验Validation示例详解

《spring参数校验Validation示例详解》Spring提供了Validation工具类来实现对客户端传来的请求参数的有效校验,本文给大家介绍spring参数校验Validation示例详... 目录前言一、Validation常见的校验注解二、Validation的简单应用三、分组校验四、自定义校

SpringBoot中Get请求和POST请求接收参数示例详解

《SpringBoot中Get请求和POST请求接收参数示例详解》文章详细介绍了SpringBoot中Get请求和POST请求的参数接收方式,包括方法形参接收参数、实体类接收参数、HttpServle... 目录1、Get请求1.1 方法形参接收参数 这种方式一般适用参数比较少的情况,并且前后端参数名称必须

Andrej Karpathy最新采访:认知核心模型10亿参数就够了,AI会打破教育不公的僵局

夕小瑶科技说 原创  作者 | 海野 AI圈子的红人,AI大神Andrej Karpathy,曾是OpenAI联合创始人之一,特斯拉AI总监。上一次的动态是官宣创办一家名为 Eureka Labs 的人工智能+教育公司 ,宣布将长期致力于AI原生教育。 近日,Andrej Karpathy接受了No Priors(投资博客)的采访,与硅谷知名投资人 Sara Guo 和 Elad G

C++11第三弹:lambda表达式 | 新的类功能 | 模板的可变参数

🌈个人主页: 南桥几晴秋 🌈C++专栏: 南桥谈C++ 🌈C语言专栏: C语言学习系列 🌈Linux学习专栏: 南桥谈Linux 🌈数据结构学习专栏: 数据结构杂谈 🌈数据库学习专栏: 南桥谈MySQL 🌈Qt学习专栏: 南桥谈Qt 🌈菜鸡代码练习: 练习随想记录 🌈git学习: 南桥谈Git 🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈�

如何在页面调用utility bar并传递参数至lwc组件

1.在app的utility item中添加lwc组件: 2.调用utility bar api的方式有两种: 方法一,通过lwc调用: import {LightningElement,api ,wire } from 'lwc';import { publish, MessageContext } from 'lightning/messageService';import Ca

4B参数秒杀GPT-3.5:MiniCPM 3.0惊艳登场!

​ 面壁智能 在 AI 的世界里,总有那么几个时刻让人惊叹不已。面壁智能推出的 MiniCPM 3.0,这个仅有4B参数的"小钢炮",正在以惊人的实力挑战着 GPT-3.5 这个曾经的AI巨人。 MiniCPM 3.0 MiniCPM 3.0 MiniCPM 3.0 目前的主要功能有: 长上下文功能:原生支持 32k 上下文长度,性能完美。我们引入了

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出 在数字化时代,文本到语音(Text-to-Speech, TTS)技术已成为人机交互的关键桥梁,无论是为视障人士提供辅助阅读,还是为智能助手注入声音的灵魂,TTS 技术都扮演着至关重要的角色。从最初的拼接式方法到参数化技术,再到现今的深度学习解决方案,TTS 技术经历了一段长足的进步。这篇文章将带您穿越时