简体   繁体   中英

Can we print success message/Assertion Result from Response Assertion in BeanShell PostProcessor using Jmeter?

I am using 'BeanShell PostProcessor' to get the request and response data for generating the result file But I am not able to get the asseration result form Response assertion, Here I have added response assertion inside of sampler, i want to print that success message in logs
whether it is failed/pass like: Success message/Assertion result - True/False Please find the screen shot: 在此处输入图像描述 I will be able to print the all data in excel except 'Success Message(pass/fail)(true/false) Please find the screen shot: 在此处输入图像描述

As per JMeter Test Elements Execution Order :

  1. Configuration elements
  2. Pre-Processors
  3. Timers
  4. Sampler
  5. Post-Processors (unless SampleResult is null)
  6. Assertions (unless SampleResult is null)
  7. Listeners (unless SampleResult is null)

You cannot get AssertionResult from the PostProcessor as the Assertion hasn't been executed yet, you need to switch to a Listener .

Also, forget about Beanshell , since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language , the relevant Groovy code to print Assertion results and failure messages to the jmeter.log file would be something like:

prev.getAssertionResults().each { assertionResult ->
    log.info('Failure: ' + assertionResult.isFailure())
    log.info('Failure message: ' + assertionResult.getFailureMessage())
}

Demo:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM