Service Virtualization

  • 1.  Need help Scripted Assertion in JavaScript

    Posted May 02, 2017 03:32 AM

    Hi All,

     

    I am need to DevTest , am working in a project which need service testing ,we are trying to do with the help of DevTest. In which i need to compare the response with multipe match criteria to perform the next specific operation based on the response. to achive that i need to write Javascript. 

    Script given below

    if(testExec.getStateValue("ResponseValue1").equals(testExec.getStateValue("Expected_Result1")))
    {
    Return True;
    }
    else
    {
    Return False;

    this is a sample here getting syntax error in the return statement. 

     

    Kindly help on this.



  • 2.  Re: Need help Scripted Assertion in JavaScript

    Posted May 02, 2017 03:41 AM

    JavaScript does not have a concept of a ‘return’ statement outside of functions. The return value of a JavaScript based Scripted Assertion is the value of the expression evaluated last.

    Instead of the entire if statement, I suggest to try 

    testExec.getStateValue("ResponseValue1").equals(testExec.getStateValue("Expected_Result1"))

    and see if that works.

    Please see DevTest 8.0 - Scripting Guide - V1.1.pdf  for more details and some guidance.



  • 3.  Re: Need help Scripted Assertion in JavaScript

    Posted May 02, 2017 05:55 AM

    Thanks Ulrich.

     

    I have checked that,but it was not working, eventhough response value and expected result is matching, still the assertion result is coming as false. Please help on this.

     

    Also how can we handle a multiple match criteria in a single condition.

     

    Please help.



  • 4.  Re: Need help Scripted Assertion in JavaScript
    Best Answer

    Posted May 02, 2017 06:43 AM

    Please review the content of the two properties again. Maybe there are any white space characters that are different. 

    You can handle multiple match criteria by following code snippet/example, for instance:

    retval = "false";
    val1 = "1";
    val2 = "2";
    if (val1.equals("1") && val2.equals("2")) {
       retval = "correct";
    }
    else {
       retval = "wrong";
    }
    "correct".equals(retval);

     

    There are likely more elegant ways to do that, but this works for me. 



  • 5.  Re: Need help Scripted Assertion in JavaScript

    Posted May 02, 2017 08:14 AM

    Many Thanks Ulrich...

    working fine now.



  • 6.  Re: Need help Scripted Assertion in JavaScript

    Broadcom Employee
    Posted May 02, 2017 05:32 AM

    Do you mean "JavaScript", or do you mean "Java scripting"? If you mean "JavaScript", then Ulrich's response is valid. If you mean "Java scripting", and you're actually using BeanShell in your scripted assertion, then make sure your "return" lines don't use capital letters.

     

    Or, you could use one of the built-in assertions instead of a scripted assertion. "Ensure properties are equal" is the same as the one you've shown in your script snippet. You can add multiple assertions to a step to cope with your multiple match criteria requirements.