gpt4 book ai didi

Trying to use a variable from Pre-Request Script in Test Tab, but getting an undefined error message(尝试使用测试选项卡中预先请求脚本中的变量,但收到未定义的错误消息)

转载 作者:bug小助手 更新时间:2023-10-24 19:01:16 25 4
gpt4 key购买 nike



I am currently learning Postman and I am trying to understand the following: I am trying to send a POST request and then test the response with some assertions I have written up under the test tab. I have some variables set up in the pre-request tab, which I use in the body when sending the request. However, one of my tests is failing when trying to make an assertion and I was wondering if somebody could point out what I am doing wrong.

我目前正在学习Postman,我正在尝试理解以下内容:我正在尝试发送POST请求,然后使用我在测试选项卡下编写的一些断言来测试响应。我在Pre-Request选项卡中设置了一些变量,我在发送请求时在正文中使用这些变量。然而,当我试图做出断言时,我的一项测试失败了,我想知道是否有人能指出我做错了什么。


This is my Pre-request script where I set the variables and their values.
enter image description here

这是我的预请求脚本,我在其中设置变量及其值。


This is the body that I am sending with the POST request
enter image description here

这是我随POST请求一起发送的正文


This assertion is failing. I am getting that {{randomTitle}} is not defined. I thought I could call that variable again since I it is in the Pre-request script.

这一断言正在失败。我得到的信息是:{{随机性标题}}未定义。我想我可以再次调用该变量,因为它在预请求脚本中。


enter image description here


更多回答
优秀答案推荐

Accessing variables using {{}} or {} in pre-request script or test script is not supported. Instead, use postman methods to get a variable value, and then use it.

不支持在预请求脚本或测试脚本中使用{{}}或{}访问变量。相反,使用邮递员方法获取变量值,然后使用它。


For instance in TestScript

例如,在测试脚本中


var random_title = pm.collectionVariables.get("randomTitle");

And then use random_title's value further in a test case.

然后在测试用例中进一步使用RANDOM_TITLE的值。


Note: if you are using different variables than collectionVariables, retrieval syntax would be different.

注意:如果您使用的变量不同于集合变量,则检索语法将不同。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com