Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function UTILS() {
- // Returns a random number
- this.rand = length => Math.floor(Math.random() * length);
- // Returns a random string
- this.text = (maxWords=1, maxLength=8) => {
- const chars = [
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
- 'abcdefghijklmnopqrstuvwxyz',
- '0123456789',
- ].join('');
- const word = () => [...Array(this.rand(maxLength))]
- .map(() => chars.charAt(this.rand(chars.length)))
- .join('');
- return [...Array(this.rand(maxWords))]
- .map(word)
- .join(' ');
- };
- // Accordint to a (normal) server response, set an environment variable
- this.setEnvironmentData = (body, name, prop='id') => {
- const { data } = JSON.parse(body);
- const title = `setEnvironmentData: [${name}]`;
- if (!data || !data.length) return console.log(`${title} NO DATA`);
- const item = data[this.rand(data.length)];
- console.log(`${title} ${item[prop]}`);
- pm.environment.set(name, item[prop]);
- return item;
- }
- }
Add Comment
Please, Sign In to add comment