AnsweredAssumed Answered

Dynamic json path validation assertions

Question asked by venkatraman.geethalakshmi on Nov 19, 2015

HI,

 

Has anybody tried out validating JSON PATH Assertions using Java scripts.

Assertions Key and Value are provided to the test case from input data sheet as [ Assertion1_Key, Assertion1_Value,Assertion2_Key, Assertion2_Value...... AssertionN_key,AssertionN_Value] in a single row for a particular scenario.

 

Since KEY and VALUE are dynamic values i cannot use JSON PATH Assertions for validation.

 

EXAMPLE:

Assertion1_Key = $.phoneNumbers[1].type

Assertion1_Value=home

 

JAVASCRIPT:

var obj = {     

 

  "phoneNumbers": [

     {

       "type"  : "iPhone",

       "number": "0123-4567-8888"

     },

     {

       "type"  : "home",

       "number": "0123-4567-8910"

     }

 

  ]

 

};

var key="$.phoneNumbers[1].type";

var value="home";

var qry;

qry = jsonPath(obj,"{{key}}").toJSONString();

if(qry.equalsIgnoreCase("{{value}}"))

{

testExec.setStateValue("Result","Pass");

}

else

{

testExec.setStateValue("Result","Fail");

}

 

Observing below error while executing. I have imported json-path-0.8.0.jar,json-smart-1.1.jar,commons-lang-2.6.jar & json-path-0.5.4.jar to hotdeploy folder.

 

sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "jsonPath" is not defined. (<Unknown source>#19) in <Unknown source> at line number 19

----------------------------------------------------------------------------

| Trapped Exception: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "jsonPath" is not defined. (<Unknown source>#19) in <Unknown source> at line number 19

| Trapped Message:   javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "jsonPath" is not defined. (<Unknown source>#19) in <Unknown source> at line number 19

 

 

Please help in this regard.

 

Thanks,

Geethalakshmi

Outcomes