Service Virtualization

 View Only
  • 1.  Need help on Beanshell Assertion Scripting

    Posted May 06, 2022 10:49 AM
    how to write Beanshell script assertion any guide or doc could help us in understanding


  • 2.  RE: Need help on Beanshell Assertion Scripting

    Broadcom Employee
    Posted May 06, 2022 12:44 PM
    Hi Mounish,

    There is no specific doc available for creating a Beanshell script assertion but DevTest provides information on creating Filters and Assertions in our documentation.

    Are you looking to add an assertion based on the properties you set in your Beanshell code, then you can use one of the available assertions Assertions.

    There is also a tutorial Filters and Assertions available in our documentation which will provide steps to create Filter and Assertion.

    Prema


  • 3.  RE: Need help on Beanshell Assertion Scripting

    Broadcom Employee
    Posted May 10, 2022 02:04 AM
    Hi Mounish,

    Some practical pointers for scriptable Beanshell assertions (some are just
    general pointers for Beanshell scripts in DevTest):


    - The script needs to return either true or false when it is done
    computing/executing. So, either in some if- or else-clause or at the last
    line of the script there needs to be a: return <somebooleanexpression>;
    - There is only a small number of java classes loaded when the script
    executes, so you will easily get a ClassNotFound exception, so many of the
    java classes you will use need to be imported (or alternatively you use the
    full qualified package name of the class)
    - The testExec object is a central object in scripts as it allows you
    access to the state of the test (or to the state of the vsm which is
    basically just a test) and to all properties (
    https://techdocs.broadcom.com/us/en/ca-enterprise-software/devops/devtest-solutions/10-7/using/using-the-sdk/extending-devtest-solutions/extension-concepts/the-test-exec-class.html
    )
    - However, testExec properties are also available within scripts without
    retrieving them with a testExec.getStateValue("myPropertyName"), and you
    can just reference them by name. Some properties have a name (containing
    dots) which is not a valid java variable name, and those properties are
    available with the "." replaced with a "_", most notable variables are
    lisa_vse_request and lisa_vse_response (as opposed to
    testExec.getStateObject("lisa.vse.request") and
    testExec.getStateObject("lisa.vse.response")
    - Be aware that lisa_vse_response is an ArrayList object and to get to
    the actual TransientResponse object you need to "get" it from the array
    list, so to get to the body of a response would be:
    lisa_vse_response.get(0).getBodyAsString()
    Unfortunately, to make things more complicated, if the response selected
    from the .vsi is the "Response for Unknown Conversational Request" or
    "Response for Unknown Stateless request" that comes back as a plain Array,
    so in that case it needs to accessed as lisa_vse_response[0]. A
    production-ready script should always use a "typeof"-operator within a
    condition to determine if there was a matching before accessing the actual
    response and take appropriate actions if you get the old non-matching "The
    DevTest VSE service could not match your request ..." response


    Hope this helps,

    Cheers,

    Danny Saro

    Client Services Consultant

    Broadcom Software


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

    --
    This electronic communication and the information and any files transmitted
    with it, or attached to it, are confidential and are intended solely for
    the use of the individual or entity to whom it is addressed and may contain
    information that is confidential, legally privileged, protected by privacy
    laws, or otherwise restricted from disclosure to anyone else. If you are
    not the intended recipient or the person responsible for delivering the
    e-mail to the intended recipient, you are hereby notified that any use,
    copying, distributing, dissemination, forwarding, printing, or copying of
    this e-mail is strictly prohibited. If you received this e-mail in error,
    please return the e-mail to the sender, delete it from your computer, and
    destroy any printed copy of it.




  • 4.  RE: Need help on Beanshell Assertion Scripting

    Posted May 09, 2022 09:02 AM
    Hi Mounish,

    Could you elaborate the requirement, as there are different ways to handle conditions in Devtest. You can use Scripted assertions, or javascript steps to redirect the flow accordingly.

    If there is a specific requirement, the you can go for customer assertions & filters.

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------