HttpRunner 请教下格式哪里有问题

Yellow · December 27, 2019 · Last by Yellow replied at December 30, 2019 · 973 hits

错误信息:

httprunner.exceptions.ParamsError: Invalid API defined in modifySettingCrossAbroad.yml

文件内容:

- config:
name: modify Setting CrossAbroad
base_url: ${ENV(base_url)}
variables:
Cookies: ${get_cookies()}
verify: False

- test:
name: /portal/vdcSettingManage/modifySettingCrossAbroadClose
variables: {}
request:
headers:
Content-Type: application/json;charset=UTF-8
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Cookie: $Cookies
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/79.0.3945.79 Safari/537.36
json:
id: 2
settingType: CROSS_BOARD
switchs: CLOSE
method: POST
url: /portal/vdcSettingManage/modifySetting
validate:
- eq:
- status_code
- 200
- eq:
- headers.Content-Type
- application/json;charset=UTF-8
- eq:
- content.code
- '00000'
- eq:
- content.msg
- SUCCESS
- eq:
- content.data
- true

- test:
name: /portal/vdcSettingManage/modifySettingCrossAbroadOpen
variables: {}
request:
headers:
Content-Type: application/json;charset=UTF-8
Cookie: $Cookies
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
json:
id: 2
settingType: CROSS_BOARD
switchs: OPEN
method: POST
url: /portal/vdcSettingManage/modifySetting
validate:
- eq:
- status_code
- 200
- eq:
- headers.Content-Type
- application/json;charset=UTF-8
- eq:
- content.code
- "00000"
- eq:
- content.msg
- SUCCESS
- eq:
- content.data
- true
共收到 7 条回复 时间 点赞

${ENV(base_url)} 或 ${get_cookies()}?

  • eq: - content.data - true

。。。这个后面是数组么?

不是的,我其他的用例文件里面也调用了变量和方法,都是没有问题的。

恒温 回复

是的,已经换成这种写法了

validate:
- eq: [status_code,200]
- eq: [headers.Content-Type,application/json;charset=UTF-8]
- eq: [content.code,'00000']
- eq: [content.msg,SUCCESS]
- eq: [content.data,true]

麻烦知道错误原因的解答一下,非常感谢。

$ httprunner modifySettingCrossAbroad.yml
INFO HttpRunner version: 2.2.5
!!!!!!!!!! exception stage: parse tests !!!!!!!!!!
httprunner.exceptions.FunctionNotFound: get_cookies is not found.

方便把你的完整项目放到 github 上吗?估计是内容不全,所以我本地被另一个问题挡住了,重现不了你的问题,无法进行更详细的分析定位。

陈恒捷 回复

谢谢,问题已经找到了,是因为我把这个用例文件放在了api目录下导致的问题。

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up