jmeter regex extractor for response header in html - 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

Related

How to encode JMeter response body (JSON) to UTF-8?

I use a script where I upload a picture to the website and it returns me all the written data in JSON format.
We use this app to recognize name/surname on different documents, we have Russian documents as well.
However, JMeter returns me something like:
{
"message": "recognized",
"birth_date": "1993",
"native_name": "\u0406\u042e\u041b\u0414\u0410",
"patronymic": "\u0410\u0410\u0410\u0410\u0410"
}
I tried to change encoding in jmeter.properties and system.properties as well, but it didn`t help. Also I tried to change the encoding via PostProcessor in one string, but no result.
By the way, in Postman I get normal result via 'Beautify' section.
Can anyone help with that issue? Maybe any examples of big PostProcessors, which can do it?
It depends on what you're trying to achieve, if you just need these values in their "text" human-readable representation you can get them using i.e. Groovy's JsonSlurper
If you want to substitute the original response with its unescaped equivalent - here is another Groovy's one-liner:
prev.setResponseData(org.apache.commons.lang.StringEscapeUtils.unescapeJava(prev.getResponseDataAsString()),'UTF-8')
put it into JSR223 PostProcessor's "Script" area and it will do the trick for you
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

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).

building dynamic urls in Karate and writing json output to a file

How to build dynamic urls in Karate feature file? I tried something like this and didn't work.
Feature: PMS API Status Check
Background:
* url baseUrl
* def spirit = 'SANRS'
Scenario: Get guest details.
Given path "'#(spirit)'/reservation/all"
Url is not evaluating to SANRS and goes as spirit. Also how do I change write the json response to a file. I see we can read the file using read(fileName) but did not see examples for writing to a file.
The '#(foo)' notation applies only to JSON, XML or the right-hand-side of a match statement.
Please use it like a normal JS expression:
Given path spirit, 'reservation', 'all'
Please do look at the documentation and examples !
Yes, there is no example for writing to a file, because this is not recommended for tests. If you really want to do this - just write a custom Java or JavaScript function, refer to the docs for "Calling Java".

StringIndexOutOfBoundsException in JMeter request

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:

Pentaho HTTP Post using JSON

I'm brand new to Pentaho and I'm trying to do the following workflow:
read a bunch of lines out of a DB
do some transformations
POST them to a REST web service in JSON
I've got the first two figured out using an input step and the Json Output step.
However I have two problems doing the final step:
1) I can't get the JSON formatted how I want. It insists on doing {""=[{...}]} when I just want {...}. This isn't a big deal - I can work around this since I have control over the web service and I could relax the input requirements a bit. (Note: this page http://wiki.pentaho.com/display/EAI/JSON+output gives an example for the output I want by setting no. rows in a block=1 and an empty JSON block name, but it doesn't work as advertised.)
2) This is the critical one. I can't get the data to POST as JSON. It posts as key=value, where the key is the name I specify in the HTTP Post field name (on the 'Fields' tab) and the value is the encoded JSON. I just want to post the JSON as the request body. I've tried googling on this but can't find anyone else doing it, leading me to believe that I'm just approaching this wrong. Any pointers in the right direction?
Edit: I'm comfortable scripting (in Javascript or another language) but when I tried to use XmlHttpRequest in a custom javascript snippet I got an error that XmlHttpRequest is not defined.
Thanks!
This was trivial...just needed to use the REST Client (http://wiki.pentaho.com/display/EAI/Rest+Client) instead of the HTTP Post task. Somehow all my googling didn't discover that, so I'll leave this answer here in case someone else has the same problem as me.
You need to parse the JSON using a Modified JavaScript step. e.g. if the Output Value from the JSON Output is called result and its contents are {"data"=[{...}]}, you should call var plainJSON = JSON.stringify(JSON.parse(result).data[0]) to get the JSON.
In the HTTP Post step, the Request entity field should be plainJSON. Also, don't forget to add a header for Content-Type as application/json (you might have to add that as a constant)