jmeter to issue http request based on response - json

I'm using Jmeter for my API testing using various http requests and various samplers to validate them. Now, I'm writing test for another http request. In this test,the steps are:
Issue a http request. Handle response.
using xpath xtractor, I'm extracting the response and storing URL in another variable(store_url).
If variable has a URL, repeat step-1.
This loops has to be repeated until no value is stored in (store_URL).
There is not definite number, how many time the loop has to be repeated. It is based on store_url is empty or not.
How can I achieve this in jmeter? I know step-1 and step-2. But I'm looking how to repeat step-1 and step-2. Please help me.

set a jmeter variable loopCount to 1 for init value,
move your step 1 and 2 into a loop controller,
set to loop count to ${loopCount}
in your step 2,
increase loopCount if store_url is found after you finish xpath xtractor

Put your points 1 and 2 under While Controller
Use ${__javaScript(vars.get("store_URL") != null)} as While Controller's Condition
In condition __javaScript() function is used to check store_URL variable value.
if store_URL variable is set (has any value) - everything under the While Controller will start over
if store_URL variable becomes null - the look will break
vars - is a shorthand to JMeterVariables class instance, it provides read/write access to all JMeter Variables
See Using JMeter Functions article for more detailed information on __javaScript and other useful functions

Related

JMeter- user defined variable not changing its value

I have a Test Plan containing one Thread Group whith one HttpRequest sampler, JRS223PreProcessor and one csv data set config. I need to read from csv, at run time,the current value of column 2 and use it in my JSR223 PreProcessor. In order to do this, I defined a variable on Test Plan:
name ${__CSVRead(C:/Users/marial/Desktop/csvs/csv_hotelCodeReq.txt,2)
In JSR223 PreProcessor I am taking it like this:
String name= new String(vars.get("name"));
I would expect this value to change on each line readed, but it didn't, it always take the first value encountered. Does anyone know why?
To be more specific, if I have the csv file :
1,2,firstName1:lastName1
3,2,firstName2:lastName2
and loop count = 2, users=1 than the values of name are:
loop1: firstName1:lastName1
loop2: firstName1:lastName1
The other values are correctly handled, so it goes to the next line.
According to User Defined Variables documentation:
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
So your __CSVRead() function is evaluated only during test startup and only once
The solution would be moving the function into "Parameters" section of the JSR223 PreProcessor and you will be able to access the function output as Parameters in your Groovy script like:
String name = Parameters
Demo:
This way the __CSVRead() function will be executed each time the JSR223 PreProcessor is called. Check out Apache Groovy - Why and How You Should Use It article to learn more about Groovy scripting in JMeter

Execution requests n times with Postman

I need to execute a requests n times which in his body has an id value. Collection runner lets executing complete collection n times but I have not found anything for concrete requests.
Request body:
{
"idEncargo":XXXXXXXX
}
From previous request I get an array with several idEncargo.
Somebody knows about this?
In your first request, if you get an array with all your idEncargo, you shall save it in a global variable
Then in your second request, you shall loop over this array.
Either inside your second request, if it is possible or if you want to perform the http request for each idEncargo, you could try to use setNextRequest feature (refer to http://blog.getpostman.com/2016/03/23/conditional-workflows-in-postman/)
like doing the following (sorry I'm a beginner in javascript, I just suggest the algorithm):
request 1 - get my idEncargo array and set it in global // to bypass if array exists
set global my_index = 0
setNextRequest("request 2")
request 2 on idEncargo[my_index]
in request 2 tests part do:
my_index ++
if my_index == max value
setNextRequest("null") // breaks the loop
else
setNextRequest("request 2") // processes the next idEncargo
Something like that could work ...
hope that helps
Alexandre

JMeter uses only first line of CSV settings

I have JMeter project:
- HTTP Request Defaults
- HTTP Header Manager
- CSV Data Set Config
(filename = my.tsv, variable names = myVar,..., delimiter = \t, others default)
- Thread group
--- Loop Controller
----- HTTP Request (uses ${myVar})
----- Timer
----- View Results Tree
The issue is that only first line of my.tsv is used by JMeter to generate requests. How to fix it?
If you define multiple threads, It should pick the values from the tsv file. each thread picks different value until all the rows consumed and will repeat the records for next threads/iterations.
If you are looking for Loop Controller, in multiple loops and single thread, then JMeter uses the same value picked in first iteration for remaining iterations.

Reading RawRequest JSON parameter value in SoapUI changes its value

I'm trying to transfer parameter from RawRequest using SoapUI but when reading it, value changes.
The parameter is request ID (which is unique for every test), it is requested by every test case from Custom Properties, where it is stored as follows:
${=((System.currentTimeMillis().toString()).subSequence(4, (System.currentTimeMillis().toString()).length())).replaceFirst("0", "")}
Above generates number like this for example:17879164.
The problem starts, when I'm trying to transfer it using either in build in feature or Groovy script. Both read parameter incorrectly:
Following is how the parameter presents in RawRequest window:
This is how it is read in Transfer window in SoapUI:
And finally, how it is read by Groovy script:
Can any one explain, why this value despite being shown in SoapUI RawRequest window as 17879164 is then read as 17879178 using two different methods?
I think the clue might be, that when I'm using "flat number" as reqId and not the generated one, both methods work fine and return correct number. But in this case when it is RawRequest, I understand that it is set once and for all, so what is show in the window and what is being read, should be the same.
What you are seeing is a "feature" in SoapUI. Your transfer step will transfer the code, which will then get evaluated again, resulting in a different value.
What you need to do is:
Create a test case property.
Set the property from test case setup script to a value. So in your case, something like testCase.setPropertyValue("your_property", ((System.currentTimeMillis().toString()).subSequence(4, (System.currentTimeMillis().toString()).length())).replaceFirst("0", ""))
Anywhere in your test refer to the test case property ${#TestCase#your_property}... which is a fixed value at this point, so will be always the same.

Jmeter CSV issue

Please help me with following issue:
I have a simple Jmeter test with where variables are stored in CSV file. There is only one request in the test:
Get .../api/${page} , where ${page} is a variable from CSV
Everything goes well with thread properties for ex. 10 threads x30 loop count
If i increase any parameter, for ex. in 10x40 or 15x30, i receive at least one error and looks like this is jmeter issue:
one request (random) isn't able to take variable from CSV and i got an error:
-.../api/page returns 404 error
So the question is - is there any limit in jmeter's connection to CSV file?
Thanks in advance.
A key point to focus on is the way your application manage the case when 2 different users require the same page.
There are few checks that I would recommend:
be sure that the "Recycle on EOF" property is true
be sure that you have more lines on CSV than the number of threads you are firing
use a "View result tree" controller to investigate the kind of error you are getting
Let us know