Use todays date as a variable in Jmeter - jmeter

I need to create a load test script using Jmeter for the some apis including this one:
https://myserver01.net/alert/bydate/${Today}
Now I use the date value manually , e.g everyday I manually change the date value in the request , e.g today I sent a request to https://myserver01.net/alert/bydate/2018-02-09. I want to make it automated so that whenever I run the test it will take todays date by default. I have seen this answers in the link http://www.jmeter-archive.org/way-to-get-current-date-into-a-variable-td512937.html but did not understand the methods. Like the first method says to define today in command line, which means I have to do it annually every time I initiate Jmeter. I want to avoid it and make it automated inside the script.

Add User Defined Variables configuration element somewhere to your Test Plan
Add the following entry there:
Name: Today
Value: ${__groovy(new Date().format('yyyy-MM-dd'),)}
Once done you will be able to refer today's date as ${Today} where required
More information:
__groovy() function
SimpleDateFormat documentation (explanation of yyyy-MM-dd pattern)

It is as simple as using JMeter __time function:
https://myserver01.net/alert/bydate/${__time(yyyy-MM-dd,)}
To test functions, you can use Function Helper Dialog which allows you to test:

Related

How can i generate a coulmn value as a random value in a csv file while doing load test with Jmeter

I am using Jmeter for load testing. I am passing parameters of the body from a csv file for an api. But our application will not receive the duplicate value. So when i load test by multiple users, the request get failed.because i am passing same parameter value for all users.So i need to make some of the columns with an instant value(random). so that different users will get different values.
{
"clinic_name":"clicnic",
"first_name":"provider1",
"initial":"v",
"last_name":"doc",
"salutation":"salu",
"address_1":"testttadd1",
"address_2":"testtttadd2",
"city":"ckdy",
"state":"Arizona",
"zip":"12365",
"fax":"",
"email":[{"email_id":"dfdf#dzcz.in","type":"Work","note":null}],
"phone":[{"number":"1235974444","note":"","type":"Mobile","extension":""}]
}
here i have given the request body and i need different email for different users. How can i do this?Can anyone help me..Thanks in advance.
you can use __RandomString function for the value of email_id:
"${__RandomString(15, abcdefghijklmnopqrstuvwxyz)}#${__RandomString(10, abcdefghijklmnopqrstuvwxyz)}.in"
The easiest is using Faker library like:
Download Java Faker jar and drop it to JMeter Classpath
Restart JMeter to pick the .jar up
You can use the following __groovy() function directly in the HTTP Request sampler body:
${__groovy(new com.github.javafaker.Faker().internet().emailAddress())}
Alternatively you can put the above expression into your CSV file, however make sure to wrap the variable reference into __eval() function, for example if you had ${email} you will need to change it to ${__eval(${email})}

Jmeter can get parameters?

My question is - if I run a test via Jmeter, for example , if it's a site which enables you to book a flight, and you choose your source and destination when you record it.
Is it possible to pass different values to the destination field? I mean, maybe a txt file with some destinations and pass it to the Jmeter test and then, you will have some tests which each of them is running with a different destination?
If yes, how can I do it?
It's not necessary that it will be a txt file. Just a way to pass different values to one parameter.
Important: I'm using blazemeter plugin for chrome.
Thanks a lot,
appreciated.
You can use CSV Data Set Config. It is very easy to use for parameterizing variables in the test plan.
Check this article on blazemeter to understand the CSV Data Set Config quickly.
Depending on what you're trying to achieve you can go for:
HTML Link Parser. See Poll Example which shows how you can use it for selecting random values from inputs
You can extract all the possible values from the previous response using a Post-Processor, most probably CSS Selector Extractor and configure each thread to use its own (or random) value from the input
And last, but not the least, you can use an external data source like .txt or .csv file and utilize __StringFromFile() function or CSV Data Set Config so each thread (virtual user) would read the next value from file instead of using recorded hard-coded values.

what container we can use for global and environment variables in Jmeter for API testing

I am trying to use Jmeter for API automation testing.
But Jmeter hasn't provided any separate containers for global and environment variables similarly like SOAP-UI and Postman.
I tried to use property file which also shared among all the JSR223 throughout the project but property having many others keys too and I haven't got any option by which I can delete key which been initiated once. Moreover, I can update the value too which seems most preferable to use
Below code I am using to set and get the values
props.put("shubhamKey", "shubhamValue")
props.get("shubhamKey")
I can also update it using same key
props.put("shubhamKey", "shubhamNewValue")
But as I said we can't delete key once initiated and it seems dangerous to delete from properties as it has many other keys too which may be required by Jmeter internally
After seeing too many things I have seen "User Defined Variables" where I can specify my key-value pairs. I am able to get the value using below code:
vars.get("shubhamLocalVariable")
But I am not able to set the value using below code:
vars.put("shubhamUserKeyagain","shubhamUservalue")
neither I got any option by which I further update it or delete it.
so Is there any feasible thing to store variables in Jmeter which can be easily created/deleted/updated using the code and can even call by other containers like HTTP Request.
Moreover I also want a container which preserve the values so the next iteration and next time (any time like other day) it will start with latest values
User Parameters
Jsr223
Any workaround will be helpful and appreciated in advance
As for me, I'm using a JSR223 Sampler at the begining of every Thread.
And for me it works:
vars.put("checksums_1","")
vars.put("checksums_2","")
vars.put("checksums_3","")
Firstly you can delete properties by using:
props.remove("shubhamKey");
And if you use specific prefix/suffix it shouldn't effect JMeter internally.
User Defined Variables isn't the best way to handle dynamic values, it's used for static variables
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
But you can set variable by string or variable or function, e.g:
For defining variables during a test run, see User Parameters which use similar assignments.

How do I generate a timestamp and put it in a variable in jmeter?

How do I generate a timestamp and put it in a variable in jmeter?
So that the variable can be passed in the URL.
Add the following function wheerever you want to send the Unix based timestamp:
${__time(,curTime)}
you can refer the value using ${curTime} in later requests.
Example:
HTTP Sampler
in View Results Tree
You can use Function Helper Dialog (in Options), to generate the code:
Note: you can also save the value using name of the variable (second row), so later you can refer the same value.
Note: you can also format the time, based on your needs (first row).
Reference:
http://jmeter.apache.org/usermanual/functions.html#__time

Runtime Test Data for Testscript in TestComplete

I started using Test Complete to automate Desktop application.
The issue is scripts holds the value which i entered while recording and the value is hard-coded.
i want the pass the value during run time. how can i achieve it?
This depends on how you want to do this. If you want to put it to your test as a parameter from another test or using a project's test item, you can define a keyword test parameter (see Keyword Test Parameters).
If you want to make a human user specify a value on runtime (although this is not very "automated"), you can create a user form that will request this value (see User Forms - Overview).
And if you want to pass a parameter to your test using command line, you can use script to read parameters from the TestComplete command-line, assign a project variable with this value and then use this variable instead of a hard coded value. See ParamStr Method, ParamCount Method and Project And Project Suite Variables.
And if you want to feed your test with some data from an external source, you can do this using the data-driven testing feature of TestComplete. See Data-Driven Testing.

Resources