Steps:
====
#1. add a JavaScript object and place the following code
testExec.setStateValue("ExpectedID","123");
testExec.setStateValue("ExpectedESIGN","false");
#2. save the below json in notepad in c drive
{
"eSign": false,
"id": "123"
}
#3. Add Read a File(Disk,URL or Classpath) Step (continuation with #1) and browser the above file path
- save as RESPONSEJSON
#4. Add Java Script Step and add following code:
import java.io.*;
import java.util.*;
import java.lang.*;
import java.lang.Integer;
strActualID = testExec.getStateValue("ActualID");
strExpectedID = testExec.getStateValue("ExpectedESIGN");
strActualESIGN = testExec.getStateValue("ActualESIGN");
strExpectedESIGN = testExec.getStateValue("ExpectedID");
if(!strExpectedESIGN.equals(strActualESIGN)){
testExec.setStateValue("Result","Failed");
}
else{
testExec.setStateValue("Result","Passed");
}
if(!strActualID.equals(strExpectedID)){
testExec.setStateValue("Result1","Failed");
}
else{
testExec.setStateValue("Result1","Passed");
}
#5. Add a Output log Message step: and se the following:
ActualID = {{ActualID}}
ActualESIGN = {{ActualESIGN}}
Expected esign = {{ExpectedESIGN}}
Expected Id = {{ExpectedID}}
{{Result}}
{{Result1}}
#6. Run the script, see that {{Result}} & {{Result1}} displays as Failed.
instead of Passed.
Can you [please me how to solve this..
the output displays as
ActualID = 123
ActualESIGN = false
Expected esign = false
Expected Id = 123
Failed
Failed
It looks like you're explicitly trying to set string values in your testExec.getStateValue statements. However, getStateValue will generate variables of the same type as the property, and your JSON is setting eSign to a boolean. Comparing the boolean false to the string "false" will always fail.
What happens if you change your getStateValue to this:
strExpectedID = testExec.getStateString("ExpectedESIGN", "defaultExpected");
strActualESIGN = testExec.getStateString("ActualESIGN", "defaultActual");
or what about:
strExpectedID = String.valueOf(testExec.getStateValue("ActualESIGN"));