TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Postman Random APIs to Generate Unique Test Inputs
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Software Testing

Postman Random APIs to Generate Unique Test Inputs

Last updated: Jun 01, 2024 12:45 pm
By Meenakshi Agarwal
Share
7 Min Read
Random API for Postman to Generate Random Inputs for Testing
SHARE

This tutorial will guide you through 4 different ways (as Random API for Postman) to generate random inputs for your API testing. You can use them for test data generation in Postman. These methods include using built-in Postman features and incorporating an external library (Faker) for more advanced scenarios, and two more.

Contents
Method 1: Randomuser(dot)me as Random API for PostmanStep 1: Create a New Request in PostmanStep 2: Use Dynamic Inputs in REST API RequestsStep 3: Automate Testing with CollectionsMethod 2: Use External Libraries As Random API for PostmanStep 1: Install the ‘Faker’ LibraryStep 2: Use Dynamic Inputs in REST API RequestsStep 3: Automate Advanced Testing with CollectionsMethod 3: Use Postman Random Functions for In-Place Data GenerationStep 1: Utilize Built-in Random Functions in Pre-request ScriptStep 2: Use Dynamic Inputs in REST API RequestsStep 3: Automate Testing with CollectionsMethod 4: Postman Dynamic Variables with TimestampsStep 1: Leverage Timestamps for UniquenessStep 2: Use Dynamic Variables in REST API RequestsStep 3: Automate Advanced Testing with CollectionsBefore You Leave

Prerequisites

Please make sure the following two things to start using the Postman.

  1. Postman Installed
    Make sure you have Postman installed on your machine. If not, download and install it from Postman’s official website.
  2. Active Internet Connection
    Ensure you have a stable internet connection to access both built-in and external sources for random data.

Below we have explained the four methods. You can easily follow these for using Postman APIs to generate random test data.

Method 1: Randomuser(dot)me as Random API for Postman

This method involves using the Randomuser(dot)me website to generate random data for testing. It allows fetching details like names, emails, and more, making it easy to simulate diverse scenarios in Postman for API testing.

Step 1: Create a New Request in Postman

// Postman Pre-request Script
const response = pm.sendRequest({
  url: "https://randomuser.me/api/",
  method: "GET",
});

const randomUserData = JSON.parse(response.body);

// Set variables for reuse
pm.environment.set("randomFirstName", randomUserData.results[0].name.first);
pm.environment.set("randomLastName", randomUserData.results[0].name.last);
// Add more variables as needed

Step 2: Use Dynamic Inputs in REST API Requests

In your REST API testing requests, replace static data with variables:

{
  "firstName": "{{randomFirstName}}",
  "lastName": "{{randomLastName}}",
  // Add more fields as needed
}

Step 3: Automate Testing with Collections

Create a Postman collection to run the Randomuser(dot)me request and subsequent REST API testing requests in a sequence.

Method 2: Use External Libraries As Random API for Postman

In Method 2, we use tools like Faker to create specific and realistic random data in Postman. This adds more detail to our testing scenarios, making them closer to real-world situations.

Step 1: Install the ‘Faker’ Library

// Postman Pre-request Script
const faker = require('Faker');

// Set vars for reuse
pm.environment.set('randEmail', faker.internet.email());
pm.environment.set('randPhone', faker.phone.phoneNumber());
// Add more vars as needed

Step 2: Use Dynamic Inputs in REST API Requests

Replace static data in your REST API requests with variables:

{
  "email": "{{randEmail}}",
  "phone": "{{randPhone}}",
  // Add more fields as needed
}

Step 3: Automate Advanced Testing with Collections

Create a Postman collection to run the Faker library script and subsequent REST API testing requests in a sequence.

Method 3: Use Postman Random Functions for In-Place Data Generation

In Method 3, we used the standard JS Math library. It provides simple functions to efficiently generate random data within Postman, easing up the testing process.

Step 1: Utilize Built-in Random Functions in Pre-request Script

// Postman Pre-request Script for Method 3
const getRandStr = (length) => {
  const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  let rc = "";
  for (let i = 0; i < length; i++) {
    const randIdx = Math.floor(Math.random() * charset.length);
    rc += charset.charAt(randIdx);
  }
  return rc;
};

// Set variables for reuse
pm.variables.set("randFirstName", getRandStr(8));
pm.variables.set("randLastName", getRandStr(10));

Step 2: Use Dynamic Inputs in REST API Requests

In your REST API testing requests, directly use the generated random data:

{
  "firstName": "{{randFirstName}}",
  "lastName": "{{randLastName}}",
  // Add more fields as needed
}

Step 3: Automate Testing with Collections

Create a Postman collection to run requests utilizing in-place generated random data for REST API testing.

Method 4: Postman Dynamic Variables with Timestamps

In Method 4, in place of a random API for Postman, we used dynamic variables (e.g. timestamp) for testing. Using timestamps is a reliable way to generate random inputs.

Step 1: Leverage Timestamps for Uniqueness

In this method, we’ll leverage timestamps to create unique and random-like data.

// Postman Pre-request Script for Method 4
const timestamp = new Date().getTime();  // Get current timestamp in msec

// Set variables for reuse
pm.variables.set("customTimestamp", timestamp);

Step 2: Use Dynamic Variables in REST API Requests

In your REST API testing requests, directly use the generated timestamp:

{
  "customTimestamp": "{{customTimestamp}}",
  // Add more fields as needed
}

Step 3: Automate Advanced Testing with Collections

Create a Postman collection to run requests utilizing dynamic variables with timestamps for REST API testing.

In this method, we are using the timestamp as a unique identifier for advanced data generation. The timestamp provides a high level of uniqueness. Hence, it is suitable for scenarios where unique or random-like values are required.

Must Read:
1. What is Regression Testing? How to Do It? Provide Examples.
2. What is Penetration Testing? How to Do It? Provide Examples.
3. What is the Software Development Life Cycle (SDLC)?
4. What is the Software Testing Life Cycle (SDLC)?
5. How to Generate Report in Selenium Webdriver?
6. How to Generate Extent Report in Selenium?
7. How to Zoom In/Out in Selenium Webdriver Using Java?

Before You Leave

Congratulations! You’ve seen four different Random API approaches for Postman and generate random inputs for REST API testing. With these details, you can further explore by changing parameters, data points, and libraries to suit your specific testing needs.

Feel free to try, even change this approach, and see how it fits into your testing process. We hope this tutorial gave you a unique perspective on using Random APIs for Postamn. If you have any further questions or concerns, please let us know.

Lastly, we need your support to continue. If you like our tutorials, share this post on social media like Facebook/Twitter.

Happy testing!

You Might Also Like

The Difference Between Usability and User Acceptance Testing

3 Ideas to Improve Customer Satisfaction for Software Product

20 SQL Tips and Tricks for Performance

How to Generate Random Numbers in R

Amazon’s 16 Leadership Principles – Your Guide to Success

TAGGED:Random Data Generation Made Easy

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
Loading
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article How to Zoom In and Zoom Out in Selenium WebDriver How to Zoom In and Zoom Out in Selenium WebDriver
Next Article How do I Merge Two Extent Reports? How do I Merge Two Extent Reports?

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x