3、httprunner基本用法

2023-12-30 12:08
文章标签 用法 基本 httprunner

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

1、.env文件

base_url,配置信息等可以写在里面然后用 ${ENV()} 引用

在这里插入图片描述

login.yml

config:name: 登录幕布variables: {}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: ${ENV(PASSWORD)}phone: ${ENV(PHONE)}method: POSTurl: https://api2.mubu.com/v3/api/user/phone_loginvalidate:-   eq:- status_code- 200-   eq:- body.code- 0

2、debugtalk.py

可以利用debugtalk.py写动态计算的方法(类似pytest中的conftest.py)等,然后直接用 ${函数名()} 调用

debugtalk.py

import time
import os
from httprunner import __version__from testcases.login_test import TestCaseLoginpath = os.path.dirname(__file__) + '/cookies'def get_httprunner_version():return __version__def sum_two(m, n):return m + ndef sleep(n_secs):time.sleep(n_secs)def get_token():if (os.path.exists(path)):with open(path,mode='r',encoding='utf-8') as f:token=f.read()print(f'获取的token为:{token}')return tokenelse:with open(path,mode='w'):TestCaseLogin().test_start()print("生成token")def set_token(login_response):with open(path,'w') as f:f.write(login_response.json['data']['token'])def get_file_name():return ['利用debugtalk创建的文件夹1','利用debugtalk创建的文件夹2']if __name__ == '__main__':# get_token()print(os.path.dirname(__file__))

create_dir_test.py

# NOTE: Generated By HttpRunner v3.1.6
# FROM: har\create_dir.yml
import pytest
from httprunner import Parameters
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
#取别名,防止pytest 把导入的以Test开头的用例也执行了
from testcases.login_test import TestCaseLogin as Loginclass TestCaseCreateDir(HttpRunner):config = Config("HttpRunner实现幕布接口-文件夹add操作")\.verify(False).export(*['folder_id'])teststeps = [# Step(#     RunTestCase("运行前置用例-登录")#     .call(Login)#     .export(*['token'])  #1、运行Login用例,把token变量导出在当前用例使用,这里不写export的话,Login用例中的Config使用export也可# ),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": "测试toke通过文件传递22"}).extract().with_jmespath('body.data.folder.id',"folder_id").validate().assert_equal("status_code", 200).assert_equal("body.code", 0)),]if __name__ == "__main__":TestCaseCreateDir().test_start()

这篇关于3、httprunner基本用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Python中多线程和多进程的基本用法详解

《Python中多线程和多进程的基本用法详解》这篇文章介绍了Python中多线程和多进程的相关知识,包括并发编程的优势,多线程和多进程的概念、适用场景、示例代码,线程池和进程池的使用,以及如何选择合适... 目录引言一、并发编程的主要优势二、python的多线程(Threading)1. 什么是多线程?2.

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

Python itertools中accumulate函数用法及使用运用详细讲解

《Pythonitertools中accumulate函数用法及使用运用详细讲解》:本文主要介绍Python的itertools库中的accumulate函数,该函数可以计算累积和或通过指定函数... 目录1.1前言:1.2定义:1.3衍生用法:1.3Leetcode的实际运用:总结 1.1前言:本文将详

MyBatis-Flex BaseMapper的接口基本用法小结

《MyBatis-FlexBaseMapper的接口基本用法小结》本文主要介绍了MyBatis-FlexBaseMapper的接口基本用法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具... 目录MyBATis-Flex简单介绍特性基础方法INSERT① insert② insertSelec

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

深入解析Spring TransactionTemplate 高级用法(示例代码)

《深入解析SpringTransactionTemplate高级用法(示例代码)》TransactionTemplate是Spring框架中一个强大的工具,它允许开发者以编程方式控制事务,通过... 目录1. TransactionTemplate 的核心概念2. 核心接口和类3. TransactionT

数据库使用之union、union all、各种join的用法区别解析

《数据库使用之union、unionall、各种join的用法区别解析》:本文主要介绍SQL中的Union和UnionAll的区别,包括去重与否以及使用时的注意事项,还详细解释了Join关键字,... 目录一、Union 和Union All1、区别:2、注意点:3、具体举例二、Join关键字的区别&php

C++中使用vector存储并遍历数据的基本步骤

《C++中使用vector存储并遍历数据的基本步骤》C++标准模板库(STL)提供了多种容器类型,包括顺序容器、关联容器、无序关联容器和容器适配器,每种容器都有其特定的用途和特性,:本文主要介绍C... 目录(1)容器及简要描述‌php顺序容器‌‌关联容器‌‌无序关联容器‌(基于哈希表):‌容器适配器‌:(

使用Python进行文件读写操作的基本方法

《使用Python进行文件读写操作的基本方法》今天的内容来介绍Python中进行文件读写操作的方法,这在学习Python时是必不可少的技术点,希望可以帮助到正在学习python的小伙伴,以下是Pyth... 目录一、文件读取:二、文件写入:三、文件追加:四、文件读写的二进制模式:五、使用 json 模块读写

oracle中exists和not exists用法举例详解

《oracle中exists和notexists用法举例详解》:本文主要介绍oracle中exists和notexists用法的相关资料,EXISTS用于检测子查询是否返回任何行,而NOTE... 目录基本概念:举例语法pub_name总结 exists (sql 返回结果集为真)not exists (s