Home > Mobile >  How to refer to a word created via $randomWord in Postman
How to refer to a word created via $randomWord in Postman

Time:08-26

I have a query that generates a key with a random name:

curl --location --request PUT 'https://apitest.backendless.com/A1DA5DF0-8D22-BAC4-FF56-9A0074DC9B00/8834B7F8-88BD-4472-9051-71BE31A3EE5B/hive/rootKeys/set/{{$randomWord}}' \
--header 'Content-Type: application/json' \
--data-raw '["123", true]'

The query itself returns the length of the new key. In the tests, I check that the key length is actually returned:

let response = pm.response.json();

pm.test("Created new key", () => {
    pm.expect(response, "Error").to.eql(2)
});

But I still need to check the completeness of this key (that is, check that the key was created with the specified values). The question is, how do I refer to this word that was generated via {{$randomWord}}?

CodePudding user response:

You can use replaceIn() to get dynamic variables in postman.

  • Step 1: In Pre-req tab, get value from {{$randomWord}} --> save it to variables/environment scope.
let randomWord = pm.variables.replaceIn("{{$randomWord}}");
pm.variables.set("randomWord", randomWord);
  • Step 2: Use it in postman UI. In this case, it's in URL

enter image description here

  • Step 3: Get it in Test tab and do your work.
let rdWord = pm.variables.get("randomWord");
//do your assertion
  • Related