I’m using Postman 8.12.1. I’m creating a mock server and trying to set up my mock response for a certain request so that the response returns a random 10 digit number. However, the only pre-built function I can find is “randomInt”
That seems to have a very limited range. Is there a way I can configure my response to return a random integer that has 10 digits? It is fine if the leading digits are zeroes.
You can use $timestamp which will return 10 digits number:
The current UNIX timestamp in seconds (as 1562757107)
You have similar options as $randomBankAccount
A random 8-digit bank account number
Or $randomPhoneNumber
A random 10-digit phone number (as 700-008-5275)
https://documenter.getpostman.com/view/8296678/UUy65Pz5
Postman doesn't allow to update mock server dynamically , but due to its sweet API first design , we can use Postman API to update the environment variables and this will reflect in the mock server response
Please see the attached public collection to know how to do this .
Here i am getting the environment and the correseponding variable , and then updating it before calling the mock server
So when we call the mock server , it always gets the updated value.
you can store the update variable request in a variable as
pm.variable.set("request",pm.request)
and then use it in pre-prequest as
pm.sendRequest(pm.variables.get("request"))
Related
We have one URL parameter as "code_challenge" which gets generated at run time, this value we need to extract so that from next runs it can be handled. However since this code value is not captured in any previous requests/responses and need to extract at run time, unable to understand how to achieve.
Tried Regular Extractor choosing URL radio button, but it captures the value from recorded script.
Steps followed:
Record script using Blazmeter (Browse URL xx.com>Click Login)
Redirected to URL(s) in which one of the url has "code_Challenge" parameter with run time value)
First URL is: accounts-xx.com/oauth2/oidcdiscovery/.well-known/openid-configuration> The response doesn't have any parameter values
Second URL is:
https://accounts-xx.com/oauth2/authorize?response_type=code&client_id=zzzz&scope=ituytutut&redirect_uri=xx.com/callBack&code_challenge_method=ooo&**code_challenge=dsfsdlfhl**
In above 3rd point url, Code_challenge value is generated at run time when executed steps from browser.
However If replayed the recorded script which would have already generated code value hence other requests would fail. Due to this, need to get the code value fetched.
The code_challenge is generated from WS02 service.
Jmeter version: 5.3
Please suggest, or should we need to use Selenium webdriver integration.
Regular expression which would extract the value from recorded script:
As per Mitigating Authorization Code Interception Attacks article:
code_challenge The client creates and records a secret cryptographically random string (the code_verifier), which is then encoded using URL safe base64 encoding to transform it into the code_challenge.
As per PKCE in WSO2 IS server article:
1.Plain:
If a code_challenge method is mention as plain or not mention at all it will take this plain value. Then code_challenge will like:
code_challenge = code_verifier
2. SHA256:
To have the code_challenge as SHA256, we should mention this in request otherwise plain value will be assumed.For SHA256 code challenge will be like
code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
Here base64url is same as base64encoding(used so that all machine can identify as same value) but trailing “=” will be removed and “+” & “/” are placed by “-” & “_” to avoid unnecessary length in URL.(otherwise ‘+’ becomes ‘%2B’, ‘/’ becomes ‘%2F’ and ‘=’ becomes ‘%3D in URL)
As much as possible, it is better to select the code challenge method as SHA256 then the flow will become more secure and hard to guess(if someone try to brute force it)
So I think you need to add JSR223 PreProcessor and calculate/generate the code_challenge using the algorithm used by your server in Groovy language, store the value into a JMeter Variable and use it in the request.
You can leave the field value empty and then its value gets updated once the request is sent. But you won't see the value in the request.
I had a similar issue, it worked in my case.
New to Jmeter, I want to pass a variable of say "1234 567 8910" from a CSV file as a Param value to a HTTP GET request and I just can't seem to get it to work, tried a number of ways, any ideas ?
Complains with "java.net.URISyntaxException: Illegal character in query at index 71" which is the first space in the param.
Fixed by changing the csv file.....
If you need to pass this phone number as a GET request parameter just tick URL Encode? box in the HTTP Request sampler:
If you need to pass this phone number as a part of a GET request URL path - you can use __urlencode() function to wrap your variable from the CSV file:
${__urlencode(${variableFromCSV})}
Check out Apache JMeter Functions - An Introduction article to get familiarized with JMeter Functions concept.
I am trying to apply load sample request is like
http://54.174.110.64:8080/adserver/html5/inwapads/?adFormat=preappvideo&ak=O4DCX2&version=1.0&adu=5&cb=1494853894218&output=vast&priority=1&size=[vdo_adSize]&pageURL=http://qa.vdopia.com/qa/Ruchi/ssp_preroll1.html?0.7888977&domain=vdopia.com&refURL=&category=[CATEGORY]&siteName=vdopia&displayManager=Vdopia-SPP-Web&di=[COOKIE_ID]&dif=fpcm&sex=[GENDER]&age=[AGE];ipAddress=203.122.9.130;di=abcdefghijklmn
I have single request, what I want is that same request should have unique di (last key in query param). Nothing else I want to change.
My test is based on unique di in request keeping other parameters constant.
You can use Random function.
Hint:
I would suggest using __UUID() function which will generate a GUID structure which is unique according to the underlying algorithm each time being called.
If you don't like dashes you can remove them via __groovy() function like
${__groovy("${__UUID}".replaceAll("-"\, ""),)}
Demo:
See Apache JMeter Functions - An Introduction to get started with JMeter Functions.
I have used below approach :
ad di=${di_random}in path of HTTP request
I am using the jmeter for load testing a web application.I am using csv Data Set Config to pass email to test login scenario.While i am running with 100 concurrent users,it is picking same email from csv file.How can i make sure that it will use one email only once.
I was facing the same issue during concurrency testing using CSV data config. By enabling Sharing Mode=All Threads in CSV data config solved my problem and i was able to send unique data per request
Use Random String Function for generation of different email ids,
RandomString function returns a random String of length using characters in chars to use.
It has three parameters,
1. Length of the desired random string
2. Source characters
3. If you need to store generated string into a JMeter variable you can provide variable name as 3rd argument.
${__RandomString(6,a12zeczclk, MYVAR)}
Example as,
${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}#MyMail.com
[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12} this is how my UUID looks like
I don't know where your generated random UUID comes from but supposing you have put it (through CSV Reader or some extractor) in variable randomUUID and that it's accessible through:
${__P(randomUUID)}
use a Response Assertion in the following configuration:
Check Matches
Check JMeter Variable and enter randomUUID
Fill in the correct regexp for your UUID (you will have to create it)
If your regular expression does not work, I would try to add capital letters, and make it more generic:
[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}
I am getting a UUID in Response when I call a 'GET' Rest Service. And I need to validate it for every iteration.
Here is what I have tried with Reg Exp and
Response Assertion
For [0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
It kind of works but the problem here is the if i change this [0-9a-f]{8} to [0-9a-f]{7} or any other number <8 its still works fine
Even If i change this [0-9a-f]{12} to [0-9a-f]{10} or any other number <12 its still works fine