问答 httprunner 变量问题

peter · 2019年05月05日 · 最后由 debugerliu 回复于 2020年05月15日 · 2163 次阅读

学习 httprunner 接口测试,使用 csv 里的数据时,总是提示找不到变量代码如下
‘’‘- config:
name: testcase description
variables: {}
test:
name: /query
parameters:
- postid1: ${P(postid.csv)}
request:
headers:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
X-Requested-With: XMLHttpRequest
method: GET
params:
phone: ''
postid: $postid1
temp: '0.8965555064774655'
type: huitongkuaidi
url: http://www.kuaidi100.com/query
validate:
- eq:
- status_code
- 200
- eq:
- headers.Content-Type
- text/html;charset=UTF-8
’‘’

报错信息如下:
‘httprunner.exceptions.VariableNotFound: postid1’

共收到 7 条回复 时间 点赞

2.0 版本的参数化不能放在 API 层。只能放在 testsuite 层。

yjq 回复

多谢

yjq 回复

请问用例分成 testsuites 里 怎么组织测试用例呢?

- config:
    name: suite01
- testcases:
    testcase: testcases/chaxun002.yaml
    testcase: testcases/chaxun001.yaml

我这样写只能运行一个测试用例

5楼 已删除
yjq 回复

我也遇到这样的问题了,但是不明白你的解答,能再详细解释下吗

@peter 你的问题解决了吗~

做了更改 放到了 testsuite 层 还是报错。。。

yjq 回复

我在 API 层里面还是调用了变量环境里面的参数,单独运行确实不行,但是放在 testcases 里面就可以调用了,可以吗?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册