Pass Javascript result into variables in Parasoft
Hi Team,
i have created variable called "test" in Responder suite as a Integer.
Scenario 1:
If I use the below Javascript I am able to pass the result for every hit by configuring tag value into response fields ${test}
function number(input, context)
{
var text = "";
var possible = "0123456789";
for (var i=0; i<5; i++)
text += possible.charAt(Math.floor(Math.random()*possible.length));
context.setValue("time", text);
}
Result: 54678 (Some Random number)
Scenario 2:
The same way If I use the below Javascript I am not able pass the result for every hit by configuring tag value into response fields ${test}
function number(input, context)
{
var tzoffset = new Date().toISOString().slice(0,19);
var tzoffset1 = tzoffset.substr(2);
var dateTime = tzoffset1.replace(/[-T:, .Z]/g, '').substring(0,n || 20); // YYYYMMDD
context.setValue("Script-CurrentDateAndTime", dateTime);
}
Result: 190924113301 (Date and time)
Can you help me how can I fix the issue
Comments
Hi,
Do you have an example pva file that you could share? For the second scenario what value were you expecting instead of the number that was printed?
Just a thought - what is the format of the payload? Is the payload defined by a schema? I'm wondering if the field is defined as an int field, and it's not being populated since the value being generated is larger than the int type supports? I think I saw something like that once.
@williammccusker, The expected result is "Result: 190924113301 (Date and time)" but when I pass this result into the variable called "test" I am not getting the result., I am getting the default value(Here its 0-configured in Responder suite) instead
@jakubiak, Ya the field accept int field. I am validating virtual service with SOAP UI now., Not started with application integration testing.
Both XML Schema and JSON Schema (including OpenAPI) allow you to specify the size of the integer, whether it is 32-bit or 64-bit or a generic number. I recommend checking if there is a defect in the schema.