๐Ÿ’กJavaScript for QA๐Ÿ’ก

Did you know that you could execute JavaScript in #Postman?

- before your request ๐Ÿš€
- after your response ๐Ÿ›ฌ

Read this thread to know more๐Ÿ‘‡๐Ÿพ [1/10]
From their website - "๐˜—๐˜ฐ๐˜ด๐˜ต๐˜ฎ๐˜ข๐˜ฏ ๐˜ค๐˜ฐ๐˜ฏ๐˜ต๐˜ข๐˜ช๐˜ฏ๐˜ด ๐˜ข ๐˜ฑ๐˜ฐ๐˜ธ๐˜ฆ๐˜ณ๐˜ง๐˜ถ๐˜ญ ๐˜ณ๐˜ถ๐˜ฏ๐˜ต๐˜ช๐˜ฎ๐˜ฆ ๐˜ฃ๐˜ข๐˜ด๐˜ฆ๐˜ฅ ๐˜ฐ๐˜ฏ ๐˜•๐˜ฐ๐˜ฅ๐˜ฆ.๐˜ซ๐˜ด ๐˜ต๐˜ฉ๐˜ข๐˜ต ๐˜ข๐˜ญ๐˜ญ๐˜ฐ๐˜ธ๐˜ด ๐˜บ๐˜ฐ๐˜ถ ๐˜ต๐˜ฐ ๐˜ข๐˜ฅ๐˜ฅ ๐˜ฅ๐˜บ๐˜ฏ๐˜ข๐˜ฎ๐˜ช๐˜ค ๐˜ฃ๐˜ฆ๐˜ฉ๐˜ข๐˜ท๐˜ช๐˜ฐ๐˜ณ ๐˜ต๐˜ฐ ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต๐˜ด ๐˜ข๐˜ฏ๐˜ฅ ๐˜ค๐˜ฐ๐˜ญ๐˜ญ๐˜ฆ๐˜ค๐˜ต๐˜ช๐˜ฐ๐˜ฏ๐˜ด." [2/10]
In these examples, we are using the famous console.log in the Pre-request Script and Tests tab

Look at the third picture, to see the console output after we make the request. [3/10]
Let us create an API test that will take a dynamic cost param, and we'll assert that the response had that same value.

๐ŸŒŸPre-Request Script๐ŸŒŸ
- 1. Use Math JavaScript object to generate a random number
- 2. Postman environmental variable to save the value for later
[4/10]
In the previous tweet, we created a random cost environmental variable, now we can use that in our request.

๐ŸŒŸRequest๐ŸŒŸ
- 1. Let the cost param in our request use the `cost` environmental variable - using {{cost}} [5/10]
Now we need to assert once the response returns.

๐ŸŒŸTests๐ŸŒŸ
- 1. Use the pm.test function to create a test
- 2. Get the cost environment variable-expected value
- 3. Get the response using `pm.response.json()`-actual value
- 4. Compare actual and expected [6/10]
Let's run out the test, and see what happens.๐Ÿง

๐ŸšจResults๐Ÿšจ
- 1. The test failed, since the API returned cost as a string but our actual cost is a number
- 2. We did note that the two values were 77 (both actual and expected)
- 3. This could be a ๐Ÿ›...๐Ÿ‘€ [7/10]
โœ… We dynamically created a random cost using JavaScript in our Pre-Request script

โœ… Then use that value in our Request

โœ… And finally used that to assert something in our response.

๐ŸŽ‰ Where we potentially found an issue. Should cost be a string or an integer? [8/10]
๐Ÿ“ In closing, JavaScript is baked in a lot of tools that QA uses on a daily

Understanding JavaScript can be very helpful/beneficial, especially if you want to #LevelUpYourAutomation [9/10]
โ“Let me know if this tweet was helpful. Did you learn anything? Have a great day!

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Dimitri Harding ๐Ÿ‡ฏ๐Ÿ‡ฒ

Dimitri Harding ๐Ÿ‡ฏ๐Ÿ‡ฒ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!