SoapUI - how to assert a JSON element containing a custom property - json

I use SoapUI NG Pro (ReadyAPI-1.1.0.) and try to use the UI to set all my required assertions.
What I try to do is to check if a list (JSON) contains an element that is defined in a soapUI custom property. To get all elements from the list I use the path: $.devices[*].deviceName. Now I like to check if the string from the customer property ${#Project#devname.1} is part of the list.
To write the assertion I found two possibilities, but both of them do not really work.
Use JsonPath Match: The menu servers an input field for the path and one for the expected result and a check box named “Allow Wild…”. I filled the path with $.devices[*].deviceName and the expected result with ${#Project#devname.1}. I also checked the check box to support wildcards. The result is a positive assertion. SoapUI does what I expect. BUT! If I save the project and reopen it, the check box is not checked any more. I have to go over all my assertions and check the boxes again. This is not a solution because I have about 100 of these assertions.
Use JsonPath RegEx Match: A nice way not use the broken “Allow Wild…” checkboxes should be to use a regular expression instead. Therefore I use the “JsonPath RegEx Match” and put the right path $.devices[*].deviceName into the input field and used this regular expression: ${#Project#devname.1}. Sadly this does not work, because SoapUI does not expand the Custom Properties before applying the regular expression. I did not find anything in the documentation explaining how to use custom properties in regular expressions. Could you help here?
In any case. What is a good solution for this type of assertions?

You can try to use JsonPath Match assertion with expression
$.devices[?(#.deviceName=='${#Project#devname.1}')].deviceName.
It will try to find device with deviceName == devname.1. If exists = true, if not - "Comparison failed for path "...", expecting [%your deviceName%], actual was [[]]"

Related

Regular Expression extractor in Jmeter not capturing value,

I am writing a regular expression extractor for a dynamic value id from the response data as below
I wrote the expression like this
But this is not capturing the value. This id value is to be used in the next request.
If i use the template as $0$, then it captures the value as %202197
Please help to correct the mistake I have made
I tried with template $0$, and match number 0 and 1, but I am getting the same expression
When I try with $1$ as template,the value is not identified at all
Your response seems to be JSON
JSON is not a regular language hence using regular expressions for parsing it is not the best idea
Consider switching to JSON Extractor, the relevant configuration would be something like:
More information: How to Use the JSON Extractor For Testing
If you want to proceed with regular expressions for any reason consider changing your regular expression part from [0-9]+ to (\d+)

Azure DevOps Pipeline Json Variable Substitution - Microsoft.Hosting.Lifetime

How can I change the value of Logging:LogLevel:Microsoft.Hosting.Lifetime using a Json Variable Substitution task in Azure DevOps?
This article...
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops&tabs=Classic
...states:
If a variable name includes periods ("."), the transformation will attempt to locate the item within the hierarchy. For example, if the variable name is first.second.third, the transformation process will search for:
"first" : {
"second": {
"third" : "value"
}
}
as well as "first.second.third" : "value".
Neither of these would be able to target a nested value with periods (.) in the name? Right?
Neither of these would be able to target a nested value with periods
(.) in the name? Right?
Sorry but I'm afraid you can't be able to do that with JSON variable substitution for now. The official document has stated that the JSON variable substitution option doesn't support variables whose names contain periods. It's not supported by design, and it's already documented in the Notes.
As alternative workarounds:
You can define the variable name in another format, something like Logging:LogLevel:Microsoft_Hosting_Lifetime.
Try using Replace Token task to change the value of Logging:LogLevel:Microsoft.Hosting.Lifetime. This task should work for your scenario. For more details you can check this issue.
Also you can submit a feature request about JSON variable substitution option on our UserVoice site, which is our main forum for product suggestions. The product team would provide the updates if they view it. Thank you for helping us build a better Azure DevOps.

How to retrieve the JSON value from multiple array response data using regular expression extractor in jmeter?

{
"response":
{
"responseData":
{
"createdDate":"2016-04-23 14:39:35",
"modifiedDate":"2016-04-23 14:39:35",
"catalogID":1009
}
}
}
Here is sample JSON data for reference. I need to extract the value of catalogID=1009. How to extract the value of catalogID?? can anyone please share your idea???
What is the regular expression to retrieve the catalogID??
Use the following regular expression extractor configuration:
Reference Name: variable name of your choice, i.e. catalogID
Regular Expression: "catalogID":(\d+)
Template: $1$
Refer extracted value as ${catalogID} where required.
Few tips:
You can use View Results Tree listener in RegExp Tester mode to test your regular expressions against real response:
See How to debug your Apache JMeter script article for more details.
There is JSON Path Extractor available via JMeter Plugins which allows using JSON Path language (more handy than regular expressions when it comes to JSON), for example the relevant query to get "catalogID" will be as simple as:
$..catalogID[0]
There is also an online JSON Path Expression Tester
If you want to use regex, use
"catalogID":(.+?)
or
"catalogID":(\d+) <-- For only digits
You can also install the plugin JSONPath for jmeter and use this instead
$.response[0].responseData[0].catalogID
More info
I have found the solution for this question.
Here you want to extract the integer value means then use this requalar expression like "catalogID":(.*?),
String means "catalogID":"(.*?)",
Lets do it!

Confusing RegEx results

why is the following regex:
"_id":"(.+?)"}\],"componentType":"(.+?)"
for this string:
"name":"in","_id":"a05d91a7-6be0-c252-08e9-bf94cc0be36e","value":"5.6"}],"_id":"e986915c-22db-429f-9fe7-ae2e2ddfa779","refId":"de9ff045-21ce-4833-af34-30f50c129840","failId":"8b723736-a391-fd7e-8d23-7cc72e568f48"},{"outputs":[{"metadata":{"label":{"value":"Output Integer","capco":"U"},"desc":{"value":"Output
Integer.","capco":"U"}},"name":"f7018f5c-057c-6ab9-7300-875c712b87b7","_id":"daad7ae7-356b-57ca-037e-0c4bcb307201"}],"componentType":"model","metadata":{"signature":"ab7e00a928dc79af806b828e1831a95e","zOrder":1,"label":{"lang":"en","value":"BBBBBBBBBBB","capco":"U"},"geom":{"w":150,"x":203,"h":60,"y":324}
pulling everything from the a05d91a7 UUID to the componentType at the bottom, and not from the _id at the bottom? I have (as far as I'm aware) nothing which indicates pulling additional content between the id (.+?) pattern and the componentType pattern?
What I'm trying to pull specifically is the following:
"_id":"daad7ae7-356b-57ca-037e-0c4bcb307201"}],"componentType":"model"
to be clear, the UUID is variable, hense the (.+?)
"_id":"([^"]*)"}],"componentType":"(.+?)"
Use this.See demo.
https://regex101.com/r/uF4oY4/38
The problem with your regex is .*? can expand based on what condition it needs to match ahead.when you use [^"]* its a negation based approach and cannot go beyond a " in any case.
There is a dedicated JMeter Test Element - JSON Path Extractor which adds JSON support to JMeter.
See Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for details on the plugin installation and some JSONPath language reference - it is much simpler than regular expressions, less fragile and more human-readable

JSON output to the browser -> providing an order

So I've read that you cannot expect a default order when requesting json. I've seen this in action making a call to a little api that I built, that will return a jumbled, random order of elements each time I make a different call.
How does a site like ticketfly's api ( call it here http://www.ticketfly.com/api/events/upcoming.json?venueId=57 ) always ensure that the json returned is in a specific order?
The event ids always first, etc.
Thanks for shedding some light on the situation.
If you are in control of the endpoint API then you can hardcode the order in which you render the properties. Though I have to ask why exactly do you need the JSON properties in a particular order? You will finally be accessing the properties via there property names so the order in which they appear in the JSON should not ideally matter.
EDIT : Since your bosses insist on this (what can one say now?):
You can try and see if any of the following suits your needs:
Try hardcoding the display order in the view's representation. This means you will need to echo/print each property name explicitly in the view script. In PHP it could be something like echo $variable_representing_json["id"]; and so forth. Note that with this approach you needn't change the original JSON representation.
If you want the original JSON representation to be changed then depending on how you are doing the process it varies in difficulty:
If it's string concatenation that you are using to represent the json then hard-code the order in which the json properties get concatenated in the string.
In some languages the display order of properties is actually a representation of the order in which the properties were defined. In simple words if $var is an empty json representation then you should define $var["id"] = {some_val} first to display it first.
If you are using a framework for processing the JSON data it may have its own quirks irrespective of how you define your representation. In such cases you will have to try and see if you can work around the issue or if it gives any helper methods.