Service Virtualization

Expand all | Collapse all

error in beanshell scripting

Jump to Best Answer
  • 1.  error in beanshell scripting

    Posted 07-24-2018 11:04 AM
      |   view attached

    running the script attached in devtest but getting below error 

     

    ============================================================================
    | Error in Script
    ============================================================================
    | Step: Execute script (JSR-223)~2
    ----------------------------------------------------------------------------
    | Message: bsh.EvalError: Sourced file: inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' : Typed variable declaration : Operator: '"<"' inappropriate for objects : at Line: 26 : in file: inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' : ;
    in inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' at line number 26

    It is unable to take the recognize the property used , is that i need to import a specific class before running the script 

    Attachment(s)

    zip
    Script.txt.zip   646B 1 version


  • 2.  Re: error in beanshell scripting

    Posted 07-24-2018 01:32 PM

    Hi,

     

    I looks like you're using a scripted assertion.  Scripted assertions must return a boolean, but "return Logistic;" returns a String.  Hence, the exception.

     

    --Mike



  • 3.  Re: error in beanshell scripting

    Posted 07-24-2018 06:07 PM

    Hi,

        The variable "SalesOrder" is coming as String and in the for the variable, "i" is an integer.You need to typecast variable   "SalesOrder"  in the for loop to an integer.

     

    Vish

     



  • 4.  Re: error in beanshell scripting

    Posted 07-25-2018 04:05 AM

    @mikegavaghan i am using the Execute script JSR-233 and its returning the a Boolean expression, also  instead of this "for (int i = 1; i < SalesOrder; i++) " if i am using "for (int i = 1; i < 7; i++) " in the script it is working as required and sending the Boolean as true, it is not taking the value of sales order from the properties 



  • 5.  Re: error in beanshell scripting
    Best Answer

    Posted 07-25-2018 04:37 AM

    Hi,

     

    I defined the two properties like:
    Key            Value
    flOperation    GenericLogisticsServiceRequest.1
    flSalesOrder   5
    in project.coing file and created a test case which includes only "Execute Script(JSR-223) step" and wrote beanshell script like:

     

    // Beanshell start

    // This script should return a boolean result indicating the assertion is true or false
    import java.text.*;
    import java.util.*;

    String Logistic = "";

     

    var floperation = testExec.getStateValue("flOperation");
    // var SalesOrder = testExec.getStateString("flSalesOrder","");
    var SalesOrders = testExec.getStateString("flSalesOrder","");
    int SalesOrder = Integer.parseInt( SalesOrders );


    if (floperation.equals("GenericLogisticsServiceRequest.1")) {

     

    //    String buildLogistic(String Logistic, SimpleDateFormat sdf) {
        String buildLogistic(String Logistic) { 
               
               
             
                for (int i = 1; i < SalesOrder; i++) {  
                    Random rand = new Random();
                    int randomValue = rand.nextInt(20);
                    Logistic = Logistic +
                            "<ns0:SalesOrderResponseLine>"+"\n"+
                "<ns0:OrigSysLineRef>"+"{{request_Activity_ActyItem_ActySpecification_MessageData_SalesOrderMessageRequestData_SalesOrderRequestOrderHeader_SalesOrderRequestLine_OrigSysLineRef_"+(i)+"}}"+"</ns0:OrigSysLineRef>"+"\n"+
             "</ns0:SalesOrderResponseLine>";
                   
        }
                   
                return Logistic;
            }

    //    String app = buildLogistic( Logistic, sdf);
        String app = buildLogistic( Logistic );
        testExec.setStateValue("flLogisticNewOrder",app);
      }
    return true;

    // Beanshell end

     

    Then I got a property named flLogisticNewOrder with value as:
    <ns0:SalesOrderResponseLine>
    <ns0:OrigSysLineRef>{{request_Activity_ActyItem_ActySpecification_MessageData_SalesOrderMessageRequestData_SalesOrderRequestOrderHeader_SalesOrderRequestLine_OrigSysLineRef_1}}</ns0:OrigSysLineRef>
    </ns0:SalesOrderResponseLine><ns0:SalesOrderResponseLine>
    <ns0:OrigSysLineRef>{{request_Activity_ActyItem_ActySpecification_MessageData_SalesOrderMessageRequestData_SalesOrderRequestOrderHeader_SalesOrderRequestLine_OrigSysLineRef_2}}</ns0:OrigSysLineRef>
    </ns0:SalesOrderResponseLine><ns0:SalesOrderResponseLine>
    <ns0:OrigSysLineRef>{{request_Activity_ActyItem_ActySpecification_MessageData_SalesOrderMessageRequestData_SalesOrderRequestOrderHeader_SalesOrderRequestLine_OrigSysLineRef_3}}</ns0:OrigSysLineRef>
    </ns0:SalesOrderResponseLine><ns0:SalesOrderResponseLine>
    <ns0:OrigSysLineRef>{{request_Activity_ActyItem_ActySpecification_MessageData_SalesOrderMessageRequestData_SalesOrderRequestOrderHeader_SalesOrderRequestLine_OrigSysLineRef_4}}</ns0:OrigSysLineRef>
    </ns0:SalesOrderResponseLine>

     

    Maybe this result will help you.

     

     

    Thank you,



  • 6.  Re: error in beanshell scripting

    Posted 07-25-2018 04:51 AM

    Thanku Yusuke yes with the above script its working