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

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

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

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

load rdf/json from URL using DotNetRDF

I'm new to the World of triplets :-) I'm trying to use DotNetRDF to load the SOLR searchresult into a Graph using DotNetRDF.
The URL I'm getting data from is:
https://nvv.entryscape.net/store/search?type=solr&query=rdfType:https%5C%3A%2F%2Fnvv.entryscape.net%2Fns%2FDocument+AND+context:https%5C%3A%2F%2Fnvv.entryscape.net%2Fstore%2F1
The format is supposed to be "RDF/JSON". No matter what parser or what I try - I only get "invalid URI". Have tried to load from the URL and also tried downloadning the result to a file and load from file, same error.
I'm using VS2017 and have "nugetted" the latest version of DotNetRdf.
Please help me, what am I missing?
Regards,
Lars Siden
It looks like the JSON being returned by that endpoint is not valid RDF/JSON. It does appear to contain some RDF/JSON fragments but they are wrapped up inside another JSON structure. The RDFJSONParser in dotNetRDF requires that your entire JSON document be a single, valid chunk of RDF/JSON.
The value at resource.children[*].metadata is an RDF/JSON object. So is the value at resource.children[*].info. The rest is wrapper using property names that are not valid IRIs (hence the parser error message).
Unfortunately there is no easy way to skip over the rest of the JSON document and only parse the valid bits. To do that you will need to load the JSON document using Newtonsoft.JSON and then serialize each valid RDF/JSON object you are interested in as a string and load that using the RDFJSONParser's Load(IGraph, TextReader) or Parse(IRdfHandler, TextReader) method.

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:

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