Created
November 6, 2023 15:23
-
-
Save belajargitbinar/509cc5a082715ab017c621d6f88b2e7c to your computer and use it in GitHub Desktop.
Postman Pre-request Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Generate a random name | |
| function generateRandomName() { | |
| const firstNames = ["John", "Alice", "Bob", "Emma", "David","Jhony"]; // Add more first names as needed | |
| const lastNames = ["Smith", "Johnson", "Doe", "Brown", "Wilson"]; // Add more last names as needed | |
| const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)]; | |
| const randomLastName = lastNames[Math.floor(Math.random() * lastNames.length)]; | |
| return `${randomFirstName} ${randomLastName}`; | |
| } | |
| const randomName = generateRandomName(); | |
| // Store the random name in an environment variable | |
| pm.environment.set('random_name', randomName); | |
| // Generate a random email address | |
| function generateRandomEmail() { | |
| const username = Math.random().toString(36).substring(2, 12); // Generate a random username | |
| const domain = 'example.com'; // Replace 'example.com' with your desired domain | |
| return `${username}@${domain}`; | |
| } | |
| const randomEmail = generateRandomEmail(); | |
| // Store the random email in an environment variable | |
| pm.environment.set('random_email', randomEmail); | |
| // Generate a random-looking Indonesian phone number | |
| function generateRandomIndonesianPhoneNumber() { | |
| const prefixOptions = ["0811", "0812", "0813", "0821", "0822", "0823", "0851", "0852", "0853", "0814", "0815", "0816", "0855"]; | |
| const selectedPrefix = prefixOptions[Math.floor(Math.random() * prefixOptions.length)]; | |
| const remainingDigits = Math.floor(Math.random() * 1000000000).toString().padStart(9, '0'); | |
| return selectedPrefix + remainingDigits; | |
| } | |
| const randomIndonesianPhoneNumber = generateRandomIndonesianPhoneNumber(); | |
| // Store the random Indonesian phone number in an environment variable | |
| pm.environment.set('random_indonesian_phone_number', randomIndonesianPhoneNumber); | |
| // Generate a random-looking Indonesian address | |
| function generateRandomIndonesianAddress() { | |
| const streets = ["Jalan Merdeka", "Jalan Pahlawan", "Jalan Raya", "Jalan Cendrawasih", "Jalan Budi Utomo", "Jalan Diponegoro"]; | |
| const cities = ["Jakarta", "Surabaya", "Bandung", "Yogyakarta", "Medan", "Semarang"]; | |
| const provinces = ["Jakarta", "East Java", "West Java", "Yogyakarta", "North Sumatra", "Central Java"]; | |
| const randomStreet = streets[Math.floor(Math.random() * streets.length)]; | |
| const randomCity = cities[Math.floor(Math.random() * cities.length)]; | |
| const randomProvince = provinces[Math.floor(Math.random() * provinces.length)]; | |
| return `${randomStreet}, ${randomCity}, ${randomProvince}`; | |
| } | |
| const randomIndonesianAddress = generateRandomIndonesianAddress(); | |
| // Store the random Indonesian address in an environment variable | |
| pm.environment.set('random_indonesian_address', randomIndonesianAddress); | |
| // Extract the city from the generated address | |
| const city = randomIndonesianAddress.split(', ')[1]; | |
| // Store the extracted city in an environment variable | |
| pm.environment.set('random_indonesian_city', city); | |
| // Define an array of random IT computer product names | |
| const computerProductNames = [ | |
| "Laptop", "Desktop Computer", "Monitor", "Keyboard", "Mouse", "Router", "External Hard Drive", | |
| "Webcam", "Printer", "Scanner", "Graphics Card", "Motherboard", "CPU", "RAM", "SSD", | |
| "Software License", "Tablet", "Server", "UPS", "Network Switch" | |
| ]; | |
| // Generate a random IT computer product name | |
| function generateRandomComputerProductName() { | |
| const randomIndex = Math.floor(Math.random() * computerProductNames.length); | |
| return computerProductNames[randomIndex]; | |
| } | |
| const randomComputerProductName = generateRandomComputerProductName(); | |
| // Store the random computer product name in an environment variable | |
| pm.environment.set('random_computer_product_name', randomComputerProductName); | |
| // Define an array of random product descriptions | |
| const productDescriptions = [ | |
| "High-performance and reliable", | |
| "Sleek and modern design", | |
| "Built to last with top-quality materials", | |
| "Versatile and easy to use", | |
| "Cutting-edge technology for superior performance", | |
| "Ergonomically designed for comfort", | |
| "Enhance your productivity with this product", | |
| "Experience the future of technology", | |
| "Affordable and feature-packed", | |
| "Innovative and stylish", | |
| "Ideal for both personal and professional use", | |
| "Eco-friendly and energy-efficient", | |
| "Seamless connectivity and compatibility", | |
| "Get the job done with ease", | |
| "Upgrade your setup with this exceptional product", | |
| "Stay ahead with the latest in tech", | |
| ]; | |
| // Generate a random product description | |
| function generateRandomProductDescription() { | |
| const randomIndex = Math.floor(Math.random() * productDescriptions.length); | |
| return productDescriptions[randomIndex]; | |
| } | |
| const randomProductDescription = generateRandomProductDescription(); | |
| // Store the random product description in an environment variable | |
| pm.environment.set('random_product_description', randomProductDescription); | |
| // Generate a random product price | |
| function generateRandomProductPrice(min, max, decimalPlaces) { | |
| const price = (Math.random() * (max - min) + min).toFixed(decimalPlaces); | |
| return parseFloat(price).toFixed(decimalPlaces); | |
| } | |
| const minPrice = 100000.00; // Define the minimum price | |
| const maxPrice = 5000000.00; // Define the maximum price | |
| const decimalPlaces = 0; // Define the number of decimal places | |
| const randomProductPrice = generateRandomProductPrice(minPrice, maxPrice, decimalPlaces); | |
| // Store the random product price in an environment variable | |
| pm.environment.set('random_product_price', randomProductPrice); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment