創建項目時,默認會自動生成一個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 api base_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]
