JMeter how to use SampleResult.getFirstAssertionFailureMessage() - jmeter

In BeanShell Assertion, I want to check whether current HTTP Sampler failed, if it failed, then collect the failure information.
SampleResult.isSuccessful() is used to check the whole Sampler status first.
If it doesn't return true, then call SampleResult.getFirstAssertionFailureMessage().
However, error message points HTTPSampleResult doesn't have this method.
ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``//PostProcessors are executed before any assertions import org.apache.jmeter.sam . . . '' : Typed variable declaration : Error in method invocation: Method getFirstAssertionFailureMessage() not found in class'org.apache.jmeter.protocol.http.sampler.HTTPSampleResult'
HTTPSamperResult api:http://jmeter.apache.org/api/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.html
SamperResult api: https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
In my script, method isSuccessful(), getSampleLabel(true), getSamplerData(), getResponseDataAsString() work fine, but not getFirstAssertionFailureMessage().
It really confuses me, does it mean HTTPSampleResult can only invoke part of the methods from SampleResult?
If yes, how can we identify the method list?

It should work fine given you use JMeter version for which this JavaDoc is actual. If you're looking into the website - you should be running the latest version available at JMeter Downloads page.
For instance it works fine in JMeter 5.0
Also be aware that according to JMeter Best Practices you should be using JSR223 test elements and Groovy language for scripting so consider migrating to JSR223 Assertion.

Related

Unable to pass Jmeter recording test when running the test in real website- one section get fail?

I want to do load test as well as performance test a website and I have recorded user step by step action through jmeter recording by proxy setting. And when I run this recorded test it gets passed all the sections except one section.
During recording steps, it gets filled all the required fields like POST, GET, PATH etc by default as well as like token, session id etc in the HTTP header manager. When user login again its get unique session id and token through Regular Expression Extractor. But my test gets failed when the user wants to accept a task it says unauthorized. I have attached screenshot.
This image showing all the steps user will do from login to logout.
Here steps 2.9 section gets fail.
Here its showing the response from the server.
Please let me know where am I doing wrong.
There are multiple possible issues with your test:
Location of the Regular Expression Extractor and other Post and Pre-Processors. According to JMeter Scoping Rules they are applied to all your Samplers so please double check if this is something you're looking for. If you want to apply the Post-Processor to a single sampler - you need to move it to be a child of the particular sampler
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider converting your Beanshell test elements into JSR223 ones
Since JMeter 3.0 there is JSON Extractor which you should be using instead of the plugins
In general HTTP status 401 means Unauthorized so double check that your test is doing what it is supposed to be doing using View Results Tree listener. You might also want to double check JMeter Variables values using Debug Sampler as it might be the case that the variables are being overwritten with something you don't expect due to the aforementioned Scoping Rules potential issue

Response Assertion - JMeter

I want the request to pass in both the cases if response contains "status":0 or "status":"0".
But if I include both this assertions in response assertion, it will take it as 'and'. It will pass only if both are satisfied. Please help me out of this.
If you use JMeter 3.2 (or later)
Reference: Response Assertions in JMeter 3.2 - New and Improved
If you use previous JMeter versions it still can be done but you will have to go for regular expressions

Error while executing checkout script in JMeter

[404-Not found]
Hello All,
I'm running one script having Checkout functionality but my script gets fail at particular page instance giving me "404 - Not found" error in logs.
But while executing manually I'm able to go to the page successfully.Below is the error message. Do i need to pass cookies in the same while execution.
Any help will be appreciated
Most likely this is due to missing or not properly working correlation. You can record the test scenario using HTTP(S) Test Script Recorder but it will be only a "skeleton" of the test containing hard-coded values like IDs or URLs or whatever.
So given you checked something out and recorded the relevant request(s) next time you will try to replay the recorded script you will get an error as the item has already been checked out, so basically you need to find another one to work with.
Normally the situation is worked around as follows:
Record the test 2 times
Identify request parameters which are changing
Using JMeter PostProcessors (the most commonly used is Regular Expression Extractor, however it may vary depending on your response data nature) convert hard-coded recorded values into JMeter Variables
Use Debug Sampler and View Results Tree listener combination to inspect:
JMeter Variables values
Request details
Server responses

BeanShell PreProcessor

I've a few BeanShellScripts inside my JMeter Project. I would like to use a few of them inside my project. I'm using command inside BeanShell PreProcessor to invoke another BeanShellProcessor in my project:
${__BeanShell(Name_Of_My_Script)}
But I realized that It's opening them a few times, so sometimes the request is sending with wrong value. Is there any another command or option to do this?
I don't think that it's a right way to execute Beanshell via function. As per JMeter Beanshell manual Beanshell Script attribute should be
A beanshell script (not a file name)
More correct way is storing your another Pre-Processor script code into a JMeter Variable, i.e. SCRIPT2 and call it as ${__BeanShell(${SCRIPT2})}.
You won't need to escape anything as the function automatically parses input script.
See How to use BeanShell guide for more details on Beanshell scripting.
It's working quite well if you use Module Controller which indicate a current Simple Controller with Beanshell script to run. Inside Simple Controller should be BeanShell Sampler.

How to get jmeter object in Jmeter

Is it possible to get the Jmeter object(ex: Xpath assertion) and disable it.
What I'm trying to achieve is when I update something, if the update request fails I want to disable the assertion.
I've been looking for something like this too, but more for "if request A fails, then goto request C", rather then disabling an assertion.
Once the script begins executing, the only items that change within the script are variables and jmeter properties. I'm not aware of a property that is defined for "enable request", but you may be able to create one:
http://jmeter.apache.org/usermanual/functions.html#__property
http://jmeter.apache.org/usermanual/functions.html#__setProperty
Just curious - why would you want to disable the assertion on a failed request? Generally it's the assertion that determines if a request fails or not (provided you receive a valid HTTP response code), so I'm wondering how you have your script set up.

Resources