am new to JMeter. I hit the multiple "post" calls with the different data sets. Every post call results in unique id as the response. I want to again pass the each unique id to "get" call with 5 mins interval. I have extracted the unique id by regex extractor. The problem is, I can only pass the last unique id to "get" call instead of every unique id. Is there a way we can create dynamic regex-key and downstream the value for further use?enter image description here
There are certainly multiple ways in which you could solve for this. To name a couple:
Capture each of the different POST response ID's as unique variables, which could then be used in future GET calls, each requesting with one of the unique ID's.
Example: ID1, ID2, ID3, etc...
Create separate thread groups for each of these POST/GET scenarios. The JMeter variable will only be local to the thread group, so they will be isolated from one another. This would also provide the possibility of running them concurrently if so desired.
Using a variable (a count of sorts) to increment on each POST, and appending it to a common variable name.
Example: ID${count} . You would have to add a Beanshell Preprocessor to increment the count variable within each HTTP Request Sampler.
int count = Integer.parseInt(vars.get("count"));
count = count + 1;
vars.put("count", count.toString());
You could then iterate until reaching the value of count in a While Controller when making the GET requests, or you could decrement count. Both would serve the same function, provided the condition in the While statement is satisfied. Additionally you could use a Loop controller with count as the # of iterations, and simply have another count that increments for the life of the loop.
Probably the easiest way will be using an incrementing postfix like:
Add __counter() function as a postfix for your "Reference Name" like
Each time the Regular Expression Extractor will be called, a new batchid_N variable will be created where N is an incrementing number produced by the __counter() function
You will be able to access these variables values as ${batchid_1}, ${batchid_2}, etc. where required. There is also a possibility to use another JMeter Function or Variable as the postfix value via __V() function like:
${__V(batchid_${yourVar})} - combine "batchid_" prefix with ${yourVar} variable
${__V(batchid_${__counter(,)})} - combine "batchid_" prefix with __counter() function
See How to Use JMeter Functions article series for more information on above and others JMeter functions.
Related
I have a get request from where I am taking all the id values , using json extractor I have extracted and named it id and used match number as -1
Now I want to pass this id variable into a post url paths
And this post requests are set inside a for each controller to run for required no of iterations
I have given for each controller values as
Input variable : id
Start index : 0
End index : ${id_matchNr}
Output var name : outid
Paths arelike
Post Path 1: https://demo.qwe.com/blue${outid}
Post Path 2:
https://demo.qwe.com/blue${outid}
I want to pass only even id numbers to path 1 and odd id numbers to path two
So I have used if controller and gave expression as
${outid}%2==0 to first path
And ${outid}%2!=0 to other if controller and placed the path 2 request
And checked the interpret condition
These two rqsts are in for each controller.
When I run the script I am getting a blank output for the post rqsts.
Can you please help me out
The function or variable you put in the If Controller must evaluate to true, only this way the If Controller will run its children. In your case you're providing just a string.
You need to wrap it into i.e. __jexl3() function like:
${__jexl3(${outid}%2==0,)}
this way it should work as expected.
More information: 6 Tips for JMeter If Controller Usage
I'm attempting to pass the ID from one storage routine into another copy task, which requires a for each to recursively process each ID. I've setup the Lookup ID task, which is working. It's passing these objects into my for each, in which the settings are "sequential" with items set to the following: #activity('LookupUID').output.value
foreach
In my for each, I have 1 activity to copy data from another API call to an Azure SQL Database. I have a linked service, with a parameter that is being passed. I'm attempting to use a dynamic content operator to pass the current item from the for each into this parameter, which then gets sent to the API call for the ID parameter. When I manually plug in a value here, it works fine. However, trying to pass the value from the for each into this copy task parameter doesn't produce a data row when running the task.
copy task
output
You must mention the column name along with the current item in copy activity like #item().ID
Example:
I have a lookup activity to get the IDs from a source. Below is the output of the Lookup activity with a list of IDs.
Lookup Output:
I am looping these IDs in the ForEach activity and passing the current item to a variable.
ForEach activity setting: Items- #activity('Lookup1').output.value
I have a string variable in which I am passing the current item as below using Set Variable activity.
#string(item().ID)
Output:
Use this code and replace with your column name
#activity('lookup1').output.firstrow.columnname
I'm trying to filter my users list by comparing two parameters
query="EmployeeData.EmployeeID=externalId"
EmployeeData.EmployeeID is a custom schema that is populated, with a cron job, with the same value as externalId.
Of course I let the cron do the field copy only if necessary, this is the reason I'm trying to filtering the users list.
In the way i wrote seems that the query trying to looking for a value "externalId" into the EmployeeData.EmployeeID ignoring that "externalId" is a even a field
any suggestion?
The way your code is written, the query sent to Google's servers is as you correctly guessed the following:
EmployeeData.EmployeeID=externalId where your actual externalId is not sent but rather the string "externalId".
To replace this string for the actual value of your variable, you can use what is called "string concatenation" 1. To do it, you just need to modify your code as shown below:
query="EmployeeData.EmployeeID=" + externalId;
This way, the query will be sent as you need to Google's servers.
I have a text field with data, something like:
[{"id":10001,"timeStarted":1355729600733,"projectId":10002,"issueId":"29732,","userName":"tester","assignee":"test","status":"STARTED","shared":True,"name":"Session 4","projectName":"IDS","assigneeDisplayName":"First1 Last1"},
{"id":10002,"timeStarted":1358354188010,"projectId":10002,"issueId":"","userName":"tester","assignee":"test","status":"CREATED","shared":True,"name":"asdf98798","projectName":"IDS","assigneeDisplayName":"First Last"}]
but with much more rows, it may be 30-40, and may be 2 more different statuses (total 4).
Is it possible to extract some data from here having read-only access to DB and only using MySQL query?
For example to count number of items with status "Stated" and with status "created".
Additional conditions may apply, e.g. where id is in definite interval.
Assuming you're using PHP, first you're better off with correcting those unrecognized booleans. You have True where it should have been true (alternatively TRUE for PHP) for it to evaluate the data right.
$jsStr = preg_replace_callback(
'~(?<=[,{[])(".+?"\s*:\s*)(true|false)(?=\s*[,}\]])~i',
create_function('$m','return $m[1].strtolower($m[2]);'),
$jsStr);
Then to be able to process it you want to use the json_decode() function.
$parsed = json_decode($jsStr);
// see the result if you like:
// print_r($parsed);
Ultimately if you want to extract some specific information on the client side (using Javascript) you can use the Array filter() function or a loop if you're not using jQuery. Otherwise you can use the jQuery filter() function with necessary conditions.
If you want to do this in PHP, after the string is parsed into JSON you can use the solutions that apply to Javascript.
I want something like this:
link
GET and 2x POST in hyperlink. How can I do that? Nothing wants to work
I have a GET array in PHP and I want to generate a link which leads to the correct url to give me those GET variables.
You can't have 2 GET variables with the same name. You can arrange them into an array as follows:
link
Just for clarification, this is still a GET request, links cannot normally produce a POST request, nor you should try to achieve that not-normally.
EDIT: To answer OP's calrification.
If you have a $_GET array, and you want to generate a link to get you there, you can use http_build_query()
I don't think you understand what GET and POST means in the HTTP world. Any items you put on a query string of a URL are GET parameters, you can't have 2 with the same name. POST parameters are sent as a part of the request, not as a query string on the URL.
GET and POST are http operations.
Sending values by using the ? as a separator in the url is different but related. eg:
foo.com/page.php?val1=1&val2=2
The values are called Query String values.
For GET operations, values are sent as a query string values. For POST operations, the values are sent in the body of the POST request. This is why POST must be used when a lot of data is being sent to the server. (Query strings have a maximum length, HTTP requests do not.)
You can do a POST operation to a url that includes query string values. This is more common with Ajax requests but can be done in a form as well. Just set the action url to something like index.php?val1=1&val2=2 the form's (additional) values will be sent as the http body. Remember to set method="post" in the form.
Note that you will need to create the query string yourself in this example, including escaping it properly.
Repeating value names in the query string values
Usually this causes both values to be sent, but the server overwrites the variable and ends up only presenting the last one to the client software.
So if you use a url such as
<a href="http://localhost/index.php?get=abc&post=cde&post=efg">
// It will be decoded by php and most server-side frameworks as
set get to abc
set post to cde
set post to efg
Result: 2 variables, get and post
There is nothing in the HTTP standard that says you can't send two query string params with the same name. However, you won't be able to use $_GET to retrieve these values; $_GET will pick up the last one. Instead, you'll have to manually parse $_SERVER['QUERY_STRING']. It's not that hard and I've done it a number of times when PHP has to handle a URL pattern generated by a third-party tool. If you're feeling really fancy you can have your query-string parse routine generate a $_GET member as an array if more than one instance of that member is encountered.