I would like to test a few of the websites on JMeter where they belong to the same websites but with different GUID.
Examples of the mentioned website would be:
www.example.com/api/example/example/{guid}
{guid} - A series of randomly generated strings in UNIX timestamp format.
There is __time() function which returns current time in form of a Unix Timestamp so all you need to do is to replace {guid} with ${__time(,)}
Demo:
Check out Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept.
Related
I've been working with timeshift, but it seems that timeshift does not do what I expect it should do. When I input a DateTime into TimeShift to work with it always uses the Current DateTime, but when I only input the Date it works?
long timeStamp = ${__timeShift(,,P2D,,)};
${__timeShift(yyyy-MM-dd'T'hh:mm:ss'Z',,P2D,,timeStampFrom)};
log.info("timeStamp: " + timeStamp);
log.info("timeStampFrom: " + ${timeStampFrom});
long timeStampTo = ${__timeShift(,${timeStampFrom},P2H,,)};
log.info("timeStamp: " + timeStampTo);
The function is called timeShift, but why doesn't let it me work with the datetime I input in?
Thanks
UPDATE:
I've been playing around with it... and yes when you are using it in the header of the JSR223 Sampler it works great. The moment you use the same code inside Sampler it doesn't... It always goes wrong with the following message:
Another update:
So when using this in the User Defined Variables:
This works without any issues, but using it in Groovy itself it doesn't work at all... getting errors. Using it in the name of a sampler works also outstanding. From my point of view it is an issue in the way how jMeter works.
Don't inline JMeter Functions or Variables into Groovy scripts, either use "Parameters" section for this.
There is one more thing connected with using functions and variables in Groovy scripts: they're being compiled and cached hence if you run your test with 2 or more iterations only first value will be used everywhere.
Correct expression for adding 2 hours is PT2H
And last but not the least, your code is not a valid Groovy code so it won't compile, you can check jmeter.log file yourself and you will see the error.
Assuming all above I don't think you need any Groovy scripting at all, you can do everything using JMeter's built-in test elements as functions can be used anywhere in the script:
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
I have externalized my input with the help of CSV Data Set Config.
I'm trying to modify the value read from CSV before sending it to my sampler in jmeter
Sample example
For simple understanding, my CSV file has following information
${Today},Test Information
${Tomorrow}, Test Information 2
In bean shell preprocessor I'm saving the today(02/sep/2021) and tomorrow(03/Sep/2021) date in the variable today and tomorrow but when the sampler gets executed, it's still having ${Today} and ${Tomorrow} rather than having 02/Sep/2021 and 03/Sep/2021
I'm trying to pass dynamic values for the variable available in csv
JMeter Variables are case sensitive so Today and today are different entities and you need to mind the case
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider migrating to Groovy
You can get today and tomorrow dates in various formats using __time() and __timeShift() functions, there is no need to use any CSV files or go for scripting
Currently I am working on moving some API DDT (data from CSV) tests from RobotFramework to Jmeter and what troubles me is the lack of proper JSONs assertion which is able to ignore some keys during comparison. I am totally new to jmeter so I am not sure if there's no such option available.
I am pretty sure we are using the wrong tool for this job, especially because functional testers would take the job of writing new tests. However, my approach (to make it as easy as possible for functionals) is to create jmeter plugin which takes response and compare it to baseline (excluding ignored keys defined in its GUI). What do you think? Is there any builtin I can use instead? Or do you know anything about some existing plugin?
Thanks in advance
The "proper" assertion is JSON Assertion available since JMeter 4.0
You can use arbitrary JSON Path queries to filter response according to your expected result
Example:
If it is not enough - you can always go for JSR223 Assertion, Groovy language has built-in JSON support so it will be way more flexible than any existing or future plugin.
Please find below the approach that I can think of:-
Take the response/HTML/json source code dump for the base line using "save response to a file".
Take the response dump for the AUT that needs to be compare or simply 2nd run dump.
Use 2 FTP sampler's to make calls for the locally saved response dump's.
Use compare assertion to compare the 2 FTP call response's. In the compare assertion, you can use RegEx String and Substitution to mask the timestamps or userID to something common for both so that it will be ignored in comparison.
Below I have shown just an image for my thought's for help.
You need to take care on how to save and fetch the response's.
Hope this help.
I need to load test a service I've developed but I need the data that I post to the web service to have some variance.
I've set up Thread with an Http Request and I've the parameter I need to set but I can't see how I'd go about changing the contents of the HTTP parameter from request to request.
Ideally I'd like to feed in a list of data Items and have JMeter iterate through them.
Prepare kind of csv-file with list of your test-params and use it to parametrize your test-samplers, using at least the following:
CSV Data Set Config
Explained example here, simple example here.
Jmeter functions: __CSVRead, __StringFromFile.
Variables From CSV sampler from jmeter-plugins.
One way would be to prepare a CSV file with all the values that you will need. There are a multitude of different ways to use it afterwards. Alies Belik's answer listed most of them. The drawback of the CSV approach, however, is that you need to generate the list of values, and in some tests you can't simply reuse it without cleaning up/reinitializing the back-end database.
Another option are the functions for generating random values, usually paired with "User Defined Variables" controller.
__Random for generating numbers in a given range.
__RandomString for generating random strings of a given length and containing a set of characters.
This is a powerful mechanism, but I find it somewhat cumbersome and clunky.
For simple variables, like generating username/password/e-mail combinations, I prefer and find it easier to use the Random Variable config element. It's available since Jmeter 2.3.3. You add it to your thread group and specify a variable to store the random value for each thread. You can later reference this variable in your HTTP sampler, in the GET/POST parameters of the request, by specifying the Value of the parameter to be testuser-${rnd} for username, testpass-${rnd} for password. Each thread will get a different value of ${rnd} so there is a small chance (but there is still a chance) that you will get duplicate values (users).
Besides the functions mentioned in #zorlem answer, You can also use:
__UUID for generating a pseudo random type 4 Universally Unique IDentifier, if you need to generate random & unique strings.
I am using JMeter for a real estate application when I am selecting a plot it is generating a dynamic value like this 1305003402565. It is incrementing like this 1305003280751 per request to request I need to capture this value and I am not able to find it in the source code.
You may be able to force your application to show the dynamic value in the source code by requesting the page as a GET (instead of POST). Then, using Tree View, copy the source into your favorite regular expression extractor to write your regex to extract the value.