HttpRunner三:debugtalk的简单使用,通过函数返回username和password

创建项目时,默认会自动生成一个debugtalk.py文件,可以在该文件中写函数,获取接口请求中需要的数据。

本次代码中只是分别定义获取username和password的函数,用于返回登录接口中需要用的参数。

调用debugtalk.py文件中函数的方式:${函数名(参数)}

1、debugtalk.py文件中的代码:

def get_name(): return "benben"def get_password(): return "123456"

2、api/demo_api.yml文件中调用的代码:

name: demo apibase_url: http://127.0.0.1:8000#variables:# username: ${ENV(username)}# password: ${ENV(password)}request: url: /user/login/ method: POST headers: Content-Type: "application/json" json: username: ${get_name()} password: ${get_password()}validate: - eq: ["status_code", 200]

 

相关文章