Search code examples
javascriptjavajmeterbeanshell

Bean shell scripting to check if response A or B is present in response text in jmeter


How to verify if response A or B is present in response text in jmeter using beanshell script assertion


Solution

  • Beanshell Assertion provides the following pre-defined variables:

    • ResponseData - byte array, contains parent sampler response
    • Failure - boolean, indicates whether assertion (and the sampler(s) in scope) is/are successful or not
    • FailureMessage - a String which can be used to provide a custom error message

    Example code which checks if response contains A and if doesn't - the sampler gets failed.

    String response = new String(ResponseData);
    
    Failure = !response.contains("A");
    FailureMessage = "Response didn't contain A"; 
    

    More information: How to Use JMeter Assertions in Three Easy Steps