How can I add/import/include 'IncludeController' in JSR223/Groovy and use it in current TestPlan? - performance

How can I access/use the specific test fragment file (jmx file) in the project use JSR223/Groovy code and use a specific Sampler?
For example, I have test fragments files [patientApi.jmx, doctorApi.jmx], each of these include fragment contains bunch of HTTP Requests (endpoint) with assertions and etc.:
patientApi.jmx:
{uri}/patientApi/getFirstName
{uri}/patientApi/getLastName
{uri}/patientApi/getDoctors
{uri}/patientApi/blaBla
doctorApi.jmx:
{uri}/doctorApi/getFirstName
{uri}/doctorApi/getLastName
{uri}/doctorApi/getPatients
{uri}/doctorApi/blaBla
So, I would like to know can I import/add/include in my new TestPlan these test fragments and disabled/enabled specific HTTP requests. It will give me the ability to create different test suites.

The only option I can think of is using an Include Controller per API endpoint and naming them according to the endpoint URL.
Once done you can put them under the Switch Controller and choose which one you want to execute by providing the relevant "Switch Value"
The "Switch value" doesn't have to be hard-coded, you can use a JMeter Variable there originating from i.e. CSV Data Set Config

Related

In JMeter how do I set multiple dynamic variables in User Parameters or CSV Data Set Config

Very new to JMeter (and a long time Stack Overflow listener but first time caller so take it easy on me) so any help would be appreciated.
I am trying to set up a JMeter test that uses multiple dynamically generated access tokens to run across scenarios. I currently have a set of data using the CSV Data Set Config containing login credentials of a user's email and password for example:
email1#email.com,password1
email2#email.com,password2
Next I send a HTTP POST request to the Login service which generates an accessToken. Then, I am using the JSON Extractor to grab the generated accessToken. After that I am using the BeanShell Assertion to store the accessToken property/variable.
My issue seems to lie here in this last step since it will only store the last generated variable instead of each of the generated accessTokens. I want to be able to store/overwrite the grabbed accessToken for each email password combination. I would like it to modify/populate the CSV file like this:
email1#email.com,password1,accessToken1
email2#email.com,password2,accessToken2
I have also tried using the Pre Processor > User Parameters
Screen shot of User Parameters
I would like to have the "userBearerToken" variable update/overwrite along with the tests, but I cannot find a way to do so or if this can even currently be done.
I'm finding it difficult to word what I am trying to ask, but basically I want to store multiple dynamically generated variables (accessTokens that change and time out) and use them in other tests. I don't care which component can handle this (either the CSV or User Parameter), but I need to be able to store these variables with their corresponding email password credentials.
If you want to store the accessToken value into a JMeter property for using in other Thread Group(s) be aware that properties are global for the whole JVM and remain until JMeter is restarted so if you define a single accessToken property - each JMeter Thread (or iteration) will overwrite the value.
The solution is to use current thread (or iteration) number as prefix or postfix, this can be done using either __${__threadNum} function or relevant JMeter Variable depending on how iteration is defined or both.
Example setup:
In first thread group: ${__setProperty(access_token_${__threadNum},bar,)}
In second thread group: ${__P(access_token_${__threadNum},)}
Demo:
If you want to save the values into a file writing into the current one is not the best idea as you can (and most probably will) get malformed file due to a form of a race condition. So I would recommend using Sample Variables property instead.
If you add the next line to user.properties file:
sample_variables=email,password,accessToken
JMeter will store the variables named ${email}, ${password}, and ${accessToken} along with their values in the .jtl results file which is basically CSV file which can be re-used anywhere else.
However if you have a requirement to store only the credentials and the token you can go for the Flexible File Writer plugin and configure it to save the aforementioned variables values into a separate file, the relevant configuration would be as simple as:
variable#0,variable#1,variable#2
You can install Flexible File Writer plugin using JMeter Plugins Manager

HTTP Request path needs to be parameterized with UUID and a random URL

URL format is
www.something.com/something/api/{uuid}?code=gomundw0gjq2kbvc3g63whfr9usap5rurjaq5vui5vm6xbt9hhqa8hbcpto4yatwpn26v42t9
I need to make several calls to this GET Url and check performance of the feature.
uuid here is not just the UUID , but is specific to my application
UUID= accountid+identifierid+uuid, which will look like 1234+1234+123e4567e89b12d3a456426655440000
How should I arrange my Jmeter Test Plan.
My Plan would be:
write UUID generated to a file
Using any preprocessor call the file from file and write program to append to a different value in the csv which is account/identifierid.
Please help on this, can some one explain how I should logically arrange my test plan and code to get data to parameterize my path in HTTP Request sampler.
Thanks in Advance
You need to get accountid+identifierid information stored into CSV file. This is something you need to do on your own.
You can use CSV Data Set Config in order to get the information from that file while your test is running, example configuration would be:
UUID can be generated using __UUID() function
So your HTTP Request sampler configuration would be something like:

JMeter http choose different url variable

I want to test a resource that gets a token in the URL.
for example: localhost:8080/api/{TOKEN}/function
I want JMeter to choose from a list of 4 different tokens. is it possible?
Everything is possible given JMeter is open source.
If you have i.e. 4 User Defined Variables containing tokens like:
You can get a random one for the each request using __V() and __Random() functions combination like:
${__V(TOKEN_${__Random(1,4,)})}
So you can change "Path" of the HTTP Request Sampler to look like:
/api/${__V(TOKEN_${__Random(1,4,)})}/function
and that should be it. See Here’s What to Do to Combine Multiple JMeter Variables article for more details.

How to use JMeter to create a resource with POST, extract Location, and then subsequently update it with PUT

I would like to profile a REST API using JMeter. I would like to write the test plan such that each user thread performs the following actions:
creates a new resource using HTTP POST
If HTTP 201 Created is received, then extract the new resource URL from the Location header of the HTTP response.
Subsequently update the resource using HTTP PUT
Loop in 3 and measure the response time
It's unclear to me how to use JMeter's conditional logic to break up the tests into these discrete parts. I would appreciate any insight anyone can provide on how to implement this.
You need to use If Controller to express this logic.
You can use Regular Expression Extractor to extract Response code (In field to check, check it and extract response code in a Variable)
Use the previously extracted variable in the If Controller condition

JMeter : how to use the timestamp of the parent

I'm testing a group of urls for performance tests. We have an SLA that states that a certain group of URLS must have an average of 80% success within a certain timerange.
The logic of the sla is done in a separate application. The data is fed from JMeter output into a database.
I need a way to identify the 5 tests of these urls, so that the application knows they belong to the same test. I use a Transaction Controller to group all the URL tests, but I still don't see how I can put an identifier in the generated output file (done by View Results Tree Listener). If I could reuse the timestamp of the parent, i.e. the Transaction Controller for the individual HTTP Requests, that would make my day. I tried adding User Defined Variables under the Transaction Controller, but I don't see how I can output the value of my variable into the output file.
Is anything similar possible?
Best regards,
Wim
Store your value in jmeter context using a Beanshell sampler then in jeter.properties uncomment sample_variables ans add the name under which you stored your value:
Optional list of JMeter variable names whose values are to be saved in the result data files.
Use commas to separate the names. For example:
sample_variables=SESSION_ID,REFERENCE
Regards
Philippe M.

Resources