Hi Support team,
Can you please help me on creating a function for data driven test and need to be passed in the collection variable in each iteration.
A Pre-request script creates unique value need to be generated using time stamp and time stamp need to suffix to the predefined text
eg -1:
abc1-timestamp
xyz2-timestamp
/Generates time stamp/
var moment = require(âmomentâ);
var current_unixtimestamp = moment.utc().valueOf();
pm.collectionVariables.set(âcurrent_unixtimestampâ, moment.utc().valueOf());
console.log(current_unixtimestamp);
var moment = require(âmomentâ);
pm.sendRequest(âhttp://worldtimeapi.org/api/timezone/America/danmarkshavnâ, function(err, res) {
var startdate = moment.utc().utcOffset(res.json().utc_offset).format(âYYYY-MM-DDTHH:mm:ssâ);
console.log(âGMT start date&timeâ);
pm.collectionVariables.set(âstartdateâ, startdate);
console.log(startdate);
var istartdate = moment.utc().utcOffset(res.json().utc_offset).add(1, 'month').startOf('month').format('YYYY-MM-DDTHH:mm:ss');
console.log('GMT Next month startdate');
pm.collectionVariables.set('istartdate', istartdate);
console.log(istartdate);
var ienddate = moment.utc().utcOffset(res.json().utc_offset).add(1, 'month').format("YYYY-MM-DDTHH:mm:ss");
pm.collectionVariables.set('ienddate', ienddate);
console.log('GMT End date&time');
console.log(ienddate);
});
/* Generates unique value and suffixing to the pre-defined text */
const itext1 = âabcâ;
pm.collectionVariables.set(âitextvalâ, itext1 .valueOf() + pm.collectionVariables.get(âcurrent_unixtimestampâ));
var i1 = pm.collectionVariables.get(âitextvalâ);
console.log(i1 );