Service Virtualization

  • 1.  Scripted Assertion not working Devtest 8.4

    Posted Nov 24, 2017 01:12 PM

    i have written below scripted assertion but result is always false.

     


    String c=testExec.getStateValue("state").toString();
    if(c.equalsIgnoreCase("true"))
    {
    return false;
    }
    else
    {
    return true;
    }

     

    here state is a property which will have value true or false from previous step. but eventhough the value of state is either true or false assertion is always false.



  • 2.  Re: Scripted Assertion not working Devtest 8.4
    Best Answer

    Posted Nov 26, 2017 12:52 PM

    If you are using JSR223 Javascript then the returned value is that of the last assignment, and not of the value supplied by a return statement - this is just the way things work under JSR223.

     

    Try something along the lines of 

     

    String c=testExec.getStateValue("state").toString();
    if(c.equalsIgnoreCase("true")) 
    {
    retval = false;
    }
    else
    {
    retval = true;
    }

    returnval = retval;  /* Value returned is that last assigned */



  • 3.  Re: Scripted Assertion not working Devtest 8.4

    Posted Nov 28, 2017 01:44 PM

    i tried below script and getting below error

     

     

    The assertion of type "Assert by Script Execution" had outcome:
    Script, string c="true";
    boolean b=false;
    if(c.equalsIgnoreCase("true"))
    {
    b =true;

    }
    return b;
    execution error so we assume false: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.string() is applicable for argument types: (java.lang.String) values: [true]
    Possible solutions: toString(), toString(), print(java.io.PrintWriter), sprintf(java.lang.String, [Ljava.lang.Object;), print(java.lang.Object), sprintf(java.lang.String, java.lang.Object)



  • 4.  Re: Scripted Assertion not working Devtest 8.4

    Posted Nov 28, 2017 01:31 PM

    i am using groovy. still getting value as false

     

     



  • 5.  Re: Scripted Assertion not working Devtest 8.4

    Posted Nov 29, 2017 02:47 AM

    The problem is the class of variable c. The script should read

    String c="true";
    boolean b=false;
    if(c.equalsIgnoreCase("true"))
    {
    b =true;
    }
    return b;

     

    Then you will get 

     

    Correct return value