Automating things with Postman

Why, what and how

HTTP, API and other magic words

browser

server

Request

Response

frontend

Backend

API

HTTP

Headers

Body

Why do we need to test API?

  • There is no UI at all
  • There is UI but it still makes sense…
    • Because of higher speed of testing
    • Single end-point testing
    • We are able to differ UI-related and API-related issues

Postman to rescue!

There is no UI at all

There is UI but it still makes sense…

Because of higher speed of testing

Single end-point testing

We are able to differ UI-related and API-related issues

Problem

CTRL + C

CTRL + V

*A lot of requests – intro based on project experience

*Tons of parameters that should be changed consistently - screenshot

Human factor

Frustration – meme pictures

SHOWTIME!!!!

In-between outcomes

Just replace common parts with variables

Environments – for linked constants

Flow-related variables – in global scope

How to change

How to check(postman console)

Collection run and data from CSV

my_variable,my_another_variable

1,0

42,”test”

SHOWTIME

Comma-separated format only – frustration picture

All data will be available under data.* variables

SHOWTIME

Tips on variables naming

  • Naming matters:
    • dyn_* for dynamically set variables
    • group linked variables with common prefix(user_name + user_pass)
    • use project name as a prefix for global variables

Why? – screenshot with lot of different variables listed

dyn_ for dynamically set

data_ if variable might be set through CSV

Don’t serialize whole object – serialize each field instead(data_user_login) - example

Any questions?

Bonus: pre-request and post-request scripts

Pre-request

Request

Post-request(Tests tab)

Setting, changing variables

  • Testing response
  • Changing variables
    • Cookies
    • XSRF token
  • Handling redirects
  • Selecting next request to send

But it’s javascript!!!

JUST ASK

JS based - logo

A lot of libraries available – screenshot of doc

No debugger ☹ • •♍❒♏♏■•♒□♦ □♐ ♏❒❒□❒ ❍♏••♋♑♏

✉☺◆•♦ ♋•& ♎♏❖♏●□•♏❒✏ – ♐◆■■⍓ •♓♍♦◆❒♏

•♏♦ ❖♋❒♓♋♌●♏ ♌⍓ ♍□♎♏☎♏•♑• ♍□□&♓♏ ❖♋●◆♏• ♐♏♦♍♒ ✠•☼☞ ♦□&♏■ ♏♦♍✆

✉❄♏•♦•☎•♦♋♦◆•• ♒♏♋♎♏❒•• ♎♋♦♋• ☺•⚐☠ □❒ ✠•☹ •♦❒◆♍♦◆❒♏ ❖♋●♓♎♋♦♓□■✆

✉☟♋■♎●♓■♑ ♐●□•• •♏♦☠♏⌧♦☼♏❑◆♏•♦

Bonus: Variables in scripts

Data from CSV is available in data[] array

Should we keep 2 versions of each scripts?

Just import all data into variables in pre-request script:

if (data) {

_.each(data, function (value, key) {

postman.setGlobalVariable("data_" + key, value);

});

}

All variables contains string

Postman.getGlobalVariable(‘age’)> 12

Don’t forget parseInt(), parseFloat() to operate numbers

JS based - logo

A lot of libraries available – screenshot of doc

No debugger ☹ • •♍❒♏♏■•♒□♦ □♐ ♏❒❒□❒ ❍♏••♋♑♏

✉☺◆•♦ ♋•& ♎♏❖♏●□•♏❒✏ – ♐◆■■⍓ •♓♍♦◆❒♏

•♏♦ ❖♋❒♓♋♌●♏ ♌⍓ ♍□♎♏☎♏•♑• ♍□□&♓♏ ❖♋●◆♏• ♐♏♦♍♒ ✠•☼☞ ♦□&♏■ ♏♦♍✆

✉❄♏•♦•☎•♦♋♦◆•• ♒♏♋♎♏❒•• ♎♋♦♋• ☺•⚐☠ □❒ ✠•☹ •♦❒◆♍♦◆❒♏ ❖♋●♓♎♋♦♓□■✆

✉☟♋■♎●♓■♑ ♐●□•• •♏♦☠♏⌧♦☼♏❑◆♏•♦

Bonus: A couple use-cases

  • Authorization
  • Different environments(say different URLs)
  • Generating request data on-the-fly
  • Don’t check response manually!

Bonus: what else do we need?

  • Reusable functions
  • Using several environments simultaniously(Role_Admin && Prod_Env_v11)
  • Variables in variables(e.g. ${${user_role}_pass})

Any questions?