This is the response getting from postman post request
{
"response": {
"appInternalClientId": 122222222222222,
"appNumber": "6565765656",
"copyParams": {},
"taskStatusLabel": "Completed",
"applicationId": 564654545465,
"taskStatus": 30,
"status": 201
},
"id": 1305854,
"message": null,
"taskStatus": "Running",
"processingTime": 1000,
"status": 202
}
// k6 response after post request submit
{"id":1305882,"message":null,"taskStatus":"Running","processingTime":19212,"status":202}
It has to print “response”: information but k6 is not printing. how to get the response to be printed.
if I print resp1.body.id
getting undefined actually it should give above id information.
K6 - it is restricting the wherever response tag is there in the body and unable to print content from the body. do i need to add any imports. How to make it to get the complete response from post request as im getting from postman.
My Script
import http from "k6/http";
import { check, sleep } from "k6";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
import papaparse from "https://jslib.k6.io/papaparse/5.1.1/index.js";
import { SharedArray } from "k6/data";
const loginCredentials = new SharedArray('users', function () {
return papaparse.parse(open('./testData/abc_login_credentials.csv'), { header: true }).data;
});
const applicantsInfo = new SharedArray('userInfo', function () {
return papaparse.parse(open('./testData/submit_application_test_data_with_epoch_time.csv'), { header: true }).data;
});
export const options = {
stages: [{ duration: "10s", target: 1 }],
};
export default function () {
const baseURL = "https://abc/api/";
const xapikey =
"1gYaVyIbjwyclgmMpC1gYaVyIbjwyclgmMpC1gYaVyIbjwyclgmMpC1gYaVyIbjwyclgmMpC";
const randomUser = loginCredentials[Math.floor(Math.random() * loginCredentials.length)];
const primaryApplicantInfo = applicantsInfo[Math.floor(Math.random() * applicantsInfo.length)];
const coApplicantInfo = applicantsInfo[Math.floor(Math.random() * applicantsInfo.length)];
const payLoad = {
clientId: randomUser.companyID,
userId: randomUser.username,
password: randomUser.pwd,
};
//console.log("testData" + testData);
let res = http.get(baseURL + "about");
let cookieData = res.cookies;
//console.log(cookieData);
let AWSALB = cookieData.AWSALB[0].value;
let AWSALBCORS = cookieData.AWSALBCORS[0].value;
let JSESSIONID = cookieData.JSESSIONID[0].value;
let XSRFTOKENDEMO = cookieData["XSRF-TOKEN-DEMO"][0].value;
let XSRFTOKEN = cookieData["XSRF-TOKEN"][0].value;
const params = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-XSRF-TOKEN": XSRFTOKEN,
"x-api-key": xapikey,
JSESSIONID: JSESSIONID,
},
};
const resp_post = http.post(baseURL + "auth/login", payLoad, params);
check(resp_post, {
"is status 200": (r) => r.status === 200,
});
let res_about = http.get(baseURL + "about");
let cookieData_app_submit = res_about.cookies;
//console.log(cookieData_app_submit);
const params1 = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36",
"Accept": "application/json",
"AWSALB": cookieData_app_submit.AWSALB[0].value,
"AWSALBCORS": cookieData_app_submit.AWSALBCORS[0].value,
"X-XSRF-TOKEN": cookieData_app_submit["XSRF-TOKEN"][0].value,
"XSRF-TOKEN-DEMO": cookieData_app_submit["XSRF-TOKEN-DEMO"][0].value,
"x-api-key": xapikey,
},
body: {
async: true,
content: testData,
loanType: 1448155676576571,
}
};
var response = http.post(
baseURL + "portal/abc/submit",
params1.body,
params1.headers
);
console.log(response.body);
var taskid = parseInt(JSON.stringify(response.body).substring(9, 16));
let getResponse = http.get(
baseURL + "portal/status/" + taskid,
params1.headers
);
//console.log(baseURL+"portal/status/"+taskid)
console.log(getResponse.body);
console.log(getResponse.status_text);
console.log(getResponse.status);
check(response, {
"is status 200": (r) => r.status === 200,
});
}
export function handleSummary(data) {
return {
"summary.html": htmlReport(data),
stdout: textSummary(data, { indent: " ", enableColors: true }),
};
}