looking to use Neoload for API testing.
Web request is simple but has a large amount of JSON included in each header.
JSON contains beginning and end parts but also a variable number of lines in the middle.
The JSON payload needs to be different and also need to have varying number of lines. As it's an api there need to be a large number of requests that can be used once only.
Tried several ways to load this. First tried to create a file variable with each entry as a a separate JSON payload (built using a PERL script.) Works ok in small volumes but will not support the final load as the file becomes too large - it'll be several GB!.
Next tried to create a file variable that has a list of multiple files each containing a JSON payload, Then use javascript to load the contents into a string variable.
Javascript is:
var dataFile = context.variableManager.getValue("dataFile.payloadFile");
var dataPath = context.variableManager.getValue("dataPath");
//logger.debug("dataFile=" + dataFile);
//logger.debug("dataPath=" + dataPath);
var payloadFile = dataPath + "/" + dataFile;
logger.debug("payloadFile=" + payloadFile);
// reads file contents
var file = new java.io.File(payloadFile);
var inppt = new java.io.StreamReader(new java.io.FileReader(file));
var dataPayload = inppt.readLine();
inppt.close();
logger.debug("dataPayload=" + dataPayload);
// Inject the computed value in a runtime variable
context.variableManager.setValue("dataPayload",dataPayload);
This works for 1 or 2 iterations then crashes.
Also tried to build dynamically using a javascript to build 'on the fly'. (Done similar before in other tests.). Javascript is:
var vendorName = context.variableManager.getValue("vendor.vendorName");
if (vendorName == null) {
context.fail("Variable 'vendor.vendorName' not found");
}
var vendorGST = context.variableManager.getValue("vendor.vendorGST");
if (vendorName == null) {
context.fail("Variable 'vendor.vendorName' not found");
}
var vendorID = context.variableManager.getValue("vendor.vendorID");
if (vendorID == null) {
context.fail("Variable 'vendor.vendorID' not found");
}
var lineSeq = context.variableManager.getValue("lineSeq");
if (lineSeq == null) {
context.fail("Variable 'lineSeq' not found");
}
var declarationDate = context.variableManager.getValue("DeclarationDate");
if (declarationDate == null) {
context.fail("Variable 'DeclarationDate'' not found");
}
var jsonPayload = '{ "pmsSoftwareName": "Planit Test Harness", "pmsSoftwareVersion": " 0.0.3",';
jsonPayload = jsonPayload + '"vendor": {"vendorName": "' + vendorName + '","vendorGST": "' + vendorGST + '","vendorID": "' + vendorID + '","vendorPhone": null },';
jsonPayload = jsonPayload + '"comment": "Invoice ' + lineSeq + '", "lines": [';
//Get Total Number of Extracted Values
var lineTotal = context.variableManager.getValue("lineTotal");
if (lineTotal == null) {
context.fail("Variable 'lineTotal' not found");
}
lineTotal = parseInt(lineTotal);
lineTotal = 10;
function pad(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
//Loop through each value and add them to the string
for(var i = 1; i <= lineTotal; i++) {
//get all the values for this item
var claimId = "VF00455";
var accidentDate = "2017-10-" + pad(parseInt((27*Math.random())+ 1),2);
var serviceCodes = "ACU1";
var serviceDate = "2018-10-" + pad(parseInt((27*Math.random())+ 1),2);
var purchaseOrderNumber = "";
var hoursClaimed = 1;
var minutesClaimed = 1;
var invoiceComment = "Invoice: " + lineSeq + "; Line: " + i;
var invoiceAmount = 0.01;
var NHINumber = "BAB2456";
var dateOfBirth = "1990-10-" + pad(parseInt((27*Math.random())+ 1),2);
var claimantFirstName = "Bill";
var claimantFamilyName = "Bloggs";
var providerID = "J99966";
var providerFirstName = "ProviderFirstName";
var providerSurname = "ProviderSurname";
//Build line item string
var lineString = ' { "claimId": "' + claimId + '","accidentDate": "' + accidentDate + '","lineDetails": { "serviceCodes": ["' + serviceCodes + '"],';
lineString = lineString + '"serviceDate": "' + serviceDate + '","purchaseOrderNumber": null, "billing": {"billingMethod": "time", "hoursClaimed": ' + hoursClaimed;
lineString = lineString + ', "minutesClaimed": '+ minutesClaimed + ' }, "invoiceComment": "' + invoiceComment + '", "invoiceAmount": ' + invoiceAmount + ' },';
lineString = lineString + '"patient": { "nhi": "' + NHINumber + '", "dateOfBirth": "' + dateOfBirth + '", "firstName": "' + claimantFirstName
lineString = lineString + '", "middleName": null, "surname": "' + claimantFamilyName + '" },' + '"provider": { "providerId": "' + providerID + '", "firstName": "';
lineString = lineString + providerFirstName + '", "middleName": null,"surname": "' + providerSurname + '", "facilityId": null } } ';
//add comma except on last line item
if(lineTotal != i) {
lineString = lineString + ",";
}
// logger.debug("lineString= " + lineString);
jsonPayload = jsonPayload + lineString;
}
var contractId = "79/45";
var jsonPayloadEnd = ' ], "contractId": "' + contractId + '", "declaration": { "declarationDate": "' + declarationDate + '" } }';
jsonPayload = jsonPayload + jsonPayloadEnd ;
//logger.debug("jsonPayload="+ jsonPayload);
// Inject the computed value in a runtime variable
context.variableManager.setValue("jsonPayload",jsonPayload);
This too works for a couple of iterations and fails.
Using Neoload 6.6 - also tried 6.0 in case it was a version problem.
Suggestions?