0
0
Postmantesting~15 mins

Flow creation in Postman - Build an Automation Script

Choose your learning style9 modes available
Create and run a simple Postman flow to send a GET request and verify response
Preconditions (3)
Step 1: Open Postman and click on 'Flows' tab
Step 2: Click 'Create Flow' button
Step 3: Drag and drop a 'Request' node onto the canvas
Step 4: Configure the Request node with method GET and URL 'https://jsonplaceholder.typicode.com/posts/1'
Step 5: Drag and drop a 'Test' node onto the canvas
Step 6: Connect the Request node output to the Test node input
Step 7: In the Test node, add a test script to verify the response status code is 200
Step 8: Click 'Run' button to execute the flow
✅ Expected Result: The flow runs successfully, sending the GET request and the test node verifies the response status code is 200, showing a pass result
Automation Requirements - Postman Flows
Assertions Needed:
Verify response status code is 200
Best Practices:
Use clear and descriptive node names
Connect nodes logically to represent flow
Use built-in test scripts for assertions
Keep flow simple and modular
Automated Solution
Postman
const pm = require('postman-collection');

// Create a new flow
const flow = new pm.Flow({
  name: 'Simple GET Request Flow'
});

// Create a request node
const requestNode = flow.addNode('Request', {
  method: 'GET',
  url: 'https://jsonplaceholder.typicode.com/posts/1'
});

// Create a test node
const testNode = flow.addNode('Test', {
  testScript: `pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});`
});

// Connect request node to test node
flow.connect(requestNode, testNode);

// Run the flow
flow.run().then(() => {
  console.log('Flow executed successfully');
}).catch(err => {
  console.error('Flow execution failed:', err);
});

This script creates a Postman flow programmatically.

First, it creates a new flow named 'Simple GET Request Flow'.

Then, it adds a Request node configured to send a GET request to the specified URL.

Next, it adds a Test node with a test script that checks if the response status code is 200.

The Request node is connected to the Test node to ensure the test runs after the request.

Finally, the flow is executed with flow.run(), and success or failure is logged.

This approach follows best practices by keeping nodes clear and connecting them logically.

Common Mistakes - 3 Pitfalls
Not connecting the Request node to the Test node
Hardcoding URLs without using variables
Writing test scripts outside the Test node
Bonus Challenge

Now add data-driven testing with 3 different URLs to send GET requests and verify status 200

Show Hint