StringIndexOutOfBoundsException in JMeter request - html

Why im getting this exception in POST request?
I'm trying to login with JMeter, but no matter i do it won't work.
I have Cookie Manager HC4CookieHandler/standard, Regular Expression Extractor too jsfViewState/name="javax.faces.ViewState" id="javax.faces.ViewState" value="(.+?)" checked Main and sub-samples/Body.
But still in POST login i'm getting this.
What i'm missing? Is it in regular expression value? javax.facesViewState has value "-2918962836342094824:7411539759421041608", but doesn't range "(.+?)" should catch it?

Looking into your request details it appears that you're sending ${jsfViewstate} instead of the numeric value so your Regular Expression Extractor doesn't seem to be capturing it from the response for some reason. The reasons could be in:
Parent sampler doesn't contain the javax.faces.ViewState input, it comes in sub-samples. In that case you will need to switch Regular Expression Extractor scope to "Main sample and sub-samples"
Response markup assumes that "ViewState" input is broken into 2 lines so your single-line regular expression cannot match it.
Some suggestions:
You can use Debug Sampler and View Results Tree listener combination to see JMeter Variables values
You can use "RegExp Tester" mode of the View Results Tree listener to test your regular expression against live response
See How to Debug your Apache JMeter Script guide for hints on getting to the bottom of JMeter script issues.
You can consider using XPath Extractor as an alternative.
Add XPath Extractor as a child of the first request
Configure it as follows:
Apply to: Main sample and sub-samples
Check Use Tidy
Reference Name: anything meaningful, i.e. jsfViewState
XPath query: //input[#id='javax.faces.ViewState']/#value
Disable (or delete) your Regular Expression Extractor
Refer extracted value as ${jsfViewState} where required
XPath Extractor Configuration:
Demo:

Related

I have been trying to compare all the contentid's of two api's in Jmeter

I have two api's which has the same contents but only the url changes, and I want to compare all the contents from both APIs using jmeter
I have used json extractor and extracted by using path as
$.. contentid given match no as -1 and checked the _All option
I have used beanshell assertion to compare the both APIs response, but one api has the all contentid's in random jumbled format so when I run the assertion I am getting error as assertion failed
For example response of one api has
{123,345,678,week,add}
And other api has
{add,123,678,week,345}
Can you help and possibly show how to compare them and get success
Take a look at JSONassert library, it allows comparing the JSON responses ignoring the attributes order and focusing only on content.
Also since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so it worth considering migrating to JSR223 Assertion.
More information: Introduction to JSONassert

Extracting value from Json response of POST request in Jmeter using Json Extractor

Post request Json Extractor Get request debug sampler error message I'm using Jmeter for stress testing of my application. Test plan that I'm building has a POST request which creates a user and the next PATCH request updates it. Basically I want to extract user_id from Json response received after POST request and add that id in the body of the next request. For that I use Json extractor in my POST request and when I check Debug Sampler the value is successfully stored. But when I try to use extracted user_id in any subsequent requests of the same thread it is not recognized. However when I tried to extract user_id of already created user with GET request then this user_id is normally recognized by other requests. I'm not sure whether Json extractor is not normally used with POST requests or I'm doing something wrong.
It's impossible to provide an answer without seeing the screenshot of your Test Plan or even better Schematic View (the option is available under "Tools" main menu entry since JMeter 5.1)
Given you're able to see the extracted value in the debug sampler I can think of 2 possible options:
Your syntax of referring the user_id variable is wrong, in JMeter the Variables are accessed like ${user_id}
Placement of your JSON Extractor is wrong, i.e. instead of putting it as a child of a specific sampler you have it at the same level as all Samplers therefore it's getting applied to the Debug Sampler as well and the extracted value gets overwritten. See Scoping Rules user manual section for more information

Is there a way to validate the whole JSON response using SOAPUI?

I tried using "COntains" option in SoapUI but it is not working so I tried Jsonpath ut I can't figure out how to.
Previously when I did XML request, I just use "COntains" and copy the whole response on the assertion.
But I cannot find to wor on it on JSON.
It looks like SOAPUI suggests to use JSONPath to validate responses.
To match an entire document you could simply search for the root $
and match it against the entire document (special formatting might throw a wrench here).

jmeter regex extractor for response header in html

I am trying to grab the values from the response header of my login sampler and then use it in the following samplers. However the response header I see is in HTML format as opposed to the colon-separated as most of the other posts have.
Here is my response header:
<authentication>
<token>6e36dcf1f5d84fcc7062b981891dd2b233bd8373d74f56f03a3bf328560976a2</token>
<anonymous>false</anonymous>
<parameters>
<header>
<userName>ps-subscriber2#mysite.com</userName>
<userType>SUBSCRIPTION_USER</userType>
<Authorization>6e36dcf1f5d84fcc7062b981891dd2b233bd8373d74f56f03a3bf328560976a2</Authorization>
</header>
</parameters>
</authentication>
I am trying different ways to extract the header values but none seem to be working:
And here is what i see in the Results Tree when I run the plan:
I am not well versed with regex which I think is the problem. Can someone help me with getting the regex correct?
It doesn't look like a header to me, it seems like you're testing an API hence I would suggest switching your Regular Expression Extractor to Body.
JMeter provides XPath Extractor which is designed to work with XML and XHTML data, consider switching to this test element instead of the Regular Expression Extractor. The relevant configuration will look like:
Reference Name: the same as for RegEx, i.e. userName
XPath query: //userName
If response is not XML/XHTML-compliant you will need to check Use Tidy box
You can use View Results Tree listener which has RegExp Tester and XPath Tester to evaluate your expressions against real response
References:
XPath Tutorial
XPath Language Specification

Jmeter and Json, extracting and using variables for another request

I'm new to JMeter and I'm probably missing something quite simple...
Note: I'm using a json add-on as well.
After making a request, I extract a value from the response. If I check the view results I'm able to see the correct value in the variable I created.
-Initial extraction of value-
-how I tried to use my new value for a new request-
If I try use the variable in another request, I receive an error because the variable is now the default value.
What am I doing incorrectly that makes the second post request to use the default value and not the value it captured (if I did that correctly).
Thanks
JSON Path Extractor is a Post Processor. It is not a Sampler. It should be the child element of the first request 'Create Order' in your test plan if you are going to extract from the 'Create Order' response. If it is in same level with other requests, the post processor will be executed for each and every samplers in the same level. That is why, You are able to see the value for the first time. Now Post processor tries to extract the value from the Debug Sampler as well. As Debug Sampler does not match your JSON extract condition, It sets the default value.
2 years later (March 2018), with Jmeter version 4.0, solution it's the same.
With the new interface, simply by dragging the json extractor on the http request, the json is limited to perform the extraction operation on it, maintaining the results.