I have a testCase in cypress framework , in which i am comparing two JSONs
I have added a expect with deap.equal for comparing the diff with [] (empty array)
this is working as expected , but i want the diff(if not equal to []) to be visible as JSON array in Allure report not like a stringify JSON.
Is there a way i can do so?
I was looking for the feature in Allure docs but couldn't find any.
Related
JMeter has a way to generate a report on the % tests passing, using the Summary Report. But in that feature, if all other assertions in a HTTP request pass but even one fails, then the request is counted as 100% failing.
I am trying to find a way to get the percentage of the assertions that are failing. Is there any way to achieve this?
Will I have to create individual tests with single assertions for this or there is a better way to do this?
You can calculate it using JSR223 Listener and the code like:
def passed = prev.getAssertionResults().findAll { !it.isFailure() }.size()
def failed = prev.getAssertionResults().findAll { it.isFailure() }.size()
def failedPercentage = failed * 100.0f / (passed + failed)
vars.put('failedPercentage', failedPercentage as String)
Where:
prev stands for previous SampleResult
vars is for JMeterVariables
See Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on these and other JMeter API shorthands available for the JSR223 Test Elements
In order to add the failed assertions percentage to the .jtl results file you can add the next line to user.properties file:
sample_variables=failedPercentage
More information: Sample Variables
Once done you can even plot the percentage of failed assertions as a custom chart in the HTML Reporting Dashboard
I have to extract multiple correlating variables from a response (which is json) in JMeter. Part of the response is listed below:
I have tried $..[?(#.sType == '7')].tId but its not worked for me
To proceed with the next request, I have to extract tId (2309), on the basis of " Stype = 7 " There are several units, each unit has several children and each children has several contents. Each content id matches just one children id and each children id matches just one unit id. Ids have to be selected on a random basis.
I've tried to extract all ids from the response and use them randomly, but it doesn't work this way.
Posting incomplete JSON is some form of disregard to the community, you're supposed to create a minimal reproducible example yourself, I'll note your username and it will be the last time you're having support from me.
Coming back to your question:
Try something like:
topics.*[?(#.tSections[3].sType == 7)].tId
Demo:
More information:
JsonPath Filter Operators
API Testing With JMeter and the JSON Extractor
You cannot get parent of a JSON node using JSON Extractor. you will need to write custom code in groovy / javascript with for-loops
My jmeter application sends a request and expects the following json in the response.
{"external-profile":{"email":"myemail#gmail.com","firstname":"fn","lastname":"ln","portfolio":{"field1":[],"field2":[],"field3":[]}}}
field1, field2 and field3 could be empty arrays or might have some value. Is there a way to check that the message has field1,2,3 but ignore the value?
I tried doing this but it doesn't work - {"external-profile":{"email":"myemail#gmail.com","firstname":"fn","lastname":"ln","portfolio":{"field1":[\.*],"field2":[\.*],"field3":[\.*]}}}. To be honest, I don't know if this is the right way to specify regular expressions in jmeter.
Since JMeter 5.2 you have JSON JMESPath Assertion which provides keys function, using it you can validate the attributes names, example configuration:
And textual representations for easier copying and pasting:
JMESPath: join(',',keys("external-profile".portfolio))
Expected value: field1,field2,field3
However it will fail if the order of "fields" will be different so you might want to go for JSON Schema Validator instead, it can be used from JSR223 Assertion
In my test Plan, I extract a list of variables and stock them into a csv file, but I want to stock them into a list and use them in the next HTTP request
How to do it please ?
enter image description here
It is not possible to come up with the comprehensive answer without seeing what kind of "list" do you want to generate out of the JMeter Variables.
2 things are obvious:
CSV Data Set Config is initalized before beanshell test elements therefore you cannot use the data generated in beanshell this way.
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting
If the list needs to be something like [foo, bar, baz] you can do it like:
def list = []
vars.entrySet().each { var ->
if (var.getKey().startsWith('userID')) {
list.add(var.getValue())
}
}
vars.put('myList', list as String)
Once done you can reference the list as ${myList} where required.
In Jmeter after an HTTP request is made, I have a JSON response data like below and I like to get the list of all accountId.
{"firstPage":"http://192.168.30.98/XX/v3.0/accounts?pageno=1","lastPage":"http://192.168.30.98/XX/v3.0/accounts?pageno=36","nextPage":"http://192.168.30.98/XX/v3.0/accounts?pageno=2","previousPage":null,"results":[{"accountId":220,"name":"abc2","url":"http://192.168.30.98/XX/v3.0/accounts/220"},{"accountId":1,"name":"ZZ1","url":"http://192.168.30.98/XX/v3.0/accounts/1"},{"accountId":7,"name":"ZZ2018-03-28T22:18:55.393Z","url":"http://192.168.30.98/XX/v3.0/accounts/7"},{"accountId":8,"name":"ZZ2018-03-28T22:23:11.081Z","url":"http://192.168.30.98/XX/v3.0/accounts/8"},{"accountId":9,"name":"ZZ2018-03-28T22:27:54.129Z","url":"http://192.168.30.98/XX/v3.0/accounts/9"},{"accountId":10,"name":"ZZ2018-03-....................}
I see that JSON Extractor can help me so I added it after my HTTP req. tree:
Names of created variables: = accoutnId
JSON Path expression = $..accountId
Match No: -1
compute .. = checked
When I run the test in View Result Tree I still see the list like above, and I do not see any, accountId_1 or accountId_2.
So I thought maybe because I don't have the JSON Plugins, I went to, Options --> Plugin Manager --> Available Plugins then I found JSON plugins (deprecated) I installed it anyway
Restarted Jmeter
Re-ran the test
but I still do not see the JSON extracted accountIds?
Here
Names of created variables: = accoutnId
There might be some spelling mistake becasue You are asking for "accountId_1 .. or accountId_2 ". There is spelling mistake in "accoutnId" and "accountId_1 ".
Refer Below Images