Postman - Selective run of API Requests within the same Iteration - postman

I have a set of the API Requests (which are saved under the same folder). I need to execute those multiple times, based on the iterations # specified in the Runner.
But there is one (the very first) request which needs to be executed only once for the whole run. This request is the authentication request that collects auth-token.
I.e. I have Req1, Req2, Req3, Req4, saved under the same collection/folder. I will need to run this set 100 iterations. But the Req1 should be run only once, while Req2, Req3 and Req4 should be executed all 100 times.
Is there a way to tell Postman (or set it some other way) to execute Req1 only once at the beginning of the whole run?

Postman has building workflow feature where you can specify which request you want to call next.
After you reach the Req4, call the Req2, which is after Req1 based on a counter.
This can be achieved in the Tests tab of the postman request window.
Pseudo code -
set 2 global/environment variables , iteration = <some number you need>, iteration_ref = 0
<In Req1 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req2')
<In Req2 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req3')
<In Req3 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req4')
<In Req4 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
{
postman.setGlobalVariable("iteration_ref",
Number(postman.getGlobalVariable("iteration_ref"))+1);
postman.setNextRequest('Req2')
}
Or only in the last request, if you are pretty confident about the order of the requests set in the collection.
<In Req4 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
{
postman.setGlobalVariable("iteration_ref",
Number(postman.getGlobalVariable("iteration_ref"))+1);
postman.setNextRequest('Req2')
}
Make sure, you have the Req1(Post Request) at first in the collection and only 1 iteration in the collection runner. We are using a global/env variable for iterations.
PS: I highly recommend having a simple python or js script using request library to call the APIs, the above flow is a witty hack.
Reference - https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/

Related

How to run a request only once with many iterations in Postman

I tried to look everywhere, but no luck so far. I have a collection with 6 requests that run automatically, but I need the last request to run only once at the end of the last iteration.
I tried to use this code in Pre-request Script of Request 5
if (pm.info.iteration === 0) {
postman.setNextRequest("Request 6")
} else {
postman.setNextRequest("Request 1")
}
and expected that the Request 6 would run only once after there is no more iteration to run, but I am doing something wrong since it is still not working.
you kind of mixed up pm.info.iterationCount and pm.info.iteration:
pm.info.iteration The value of the current iteration
pm.info.iterationCount The total number of iterations that are scheduled to run
See the documentation: Scripting with request info
You want to execute "Request 6" at the very end, this means, when iteration and iterationCount are equal.
Note that iteration start at 0, so you need to add + 1 when comparing it to iterationCount.
Also, if this condition does not match, you need to set the nextRequest to null.
"Request 1" will be executed automatically by the Collection Runner. If you set the nextRequest to "Request 1", you will end up in an endless loop.
The following will do you what you want, you can put it as pre-request script or test of "Request 5".
if (pm.info.iterationCount == pm.info.iteration + 1) {
postman.setNextRequest("Request 6")
} else {
postman.setNextRequest(null)
}

My request won't repeat itself after executing

So I have a request in Postman that will create a User for me. I want to run it automatically for a certain amount of time to save time preparing datas. I try using setNextRequest but it doesn't work. I have tried to put it in Pre-request Script, Tests tab of the request itself as well as the Collection but it just won't run. I have certainly sure that all of my item is saved, none of them has orange dots.
var count = 0;
while(count < 5){
postman.setNextRequest("CreatePersonWithUser");
console.log("This is the " + count + " time");
count++;
}

Jmeter - how to pass cookie captured in one thread to another thread

I am trying to use same cookie(i.e. capturing cookies in main thread and trying to pass it in support threads) in different threads in Jmeter. I have already read the article give at
https://blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell
but its not working in my case. Can someone please help in recognizing what mistake I am doing while implementing the logic given in above link.
please find below steps I am following
Test Plan
- HTTP Cache Manager
- HTTP Header Manager
- HTTP Cookie Manager
- Main Thread(login page under main thread)
- Login (BeanShell PostProcessor under login)
- BeanShell PostProcessor
import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
props.put("cookiecount", String.valueOf(manager.getCookieCount()));
for (int i = 0; i < manager.getCookieCount(); i++)
{
props.put("cookie_name" + i, manager.get(i).getName());
props.put("cookie_value" + i, manager.get(i).getValue());
props.put("cookie_domain" + i, manager.get(i).getDomain());
props.put("cookie_path" + i, manager.get(i).getPath());
props.put("cookie_expires" + i, String.valueOf(manager.get(i).getExpires()));
props.put("cookie_secure" + i, String.valueOf(manager.get(i).getSecure()));
}
- Support Thread 1
- BeanShell PreProcessor
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
import org.apache.jmeter.testelement.property.JMeterProperty;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
int count = Integer.parseInt(props.getProperty("cookiecount"));
for (int i = 0; i < count; i++) {
Cookie cookie = new Cookie(props.getProperty("cookie_name" + i),
props.getProperty("cookie_value" + i),
props.getProperty("cookie_domain" + i),
props.getProperty("cookie_path" + i),
Boolean.parseBoolean(props.getProperty("cookie_secure" + i)),
Long.parseLong(props.getProperty("cookie_expires" + i)));
manager.add(cookie);
}
JMeterProperty cookieprop = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager");
cookieprop.setObjectValue(manager);
ctx.getCurrentSampler().setProperty(cookieprop);
- HTTP Request
After running it for 1 thread - 1 loop getting different cookies for both threads something like below
- Main Thread
Cookie Data:
JSESSIONID=PvRSWmBXNp9y65njGkRWbLlxLM1pvxLzpnyjThQDny3pMy6Gkcjv!486373045
- Support Thread
Cookie Data:
JSESSIONID=YVGsWmQSXdGt1xqfDDvlkgkHLpqJ3WRD2sDyqXp62rChfTDbM0Vj!486373045
I have set CookieManager.save.cookies=true.
Just use 2 different HTTP Cookie Manager test elements for different thread groups.
P.S. If you already have CookieManager.save.cookies=true property set and you know cookie names - you can use __setProperty() function to pass variables which hold cookie values between thread groups like:
In 1st Thread Group convert variable to property like ${__setProperty(JSESSIONID,COOKIE_JSESSIONID,)}
In 2nd Thread Group refer the property as ${__P(JSESSIONID,)}
The approach is described in details in the How to Use Variables in Different Thread Groups article.

Meteor regex find() far slower than in MongoDB console

I've been researching A LOT for past 2 weeks and can't pinpoint the exact reason of my Meteor app returning results too slow.
Currently I have only a single collection in my Mongo database with around 2,00,000 documents. And to search I am using Meteor subscriptions on the basis of a given keyword. Here is my query:
db.collection.find({$or:[
{title:{$regex:".*java.*", $options:"i"}},
{company:{$regex:".*java.*", $options:"i"}}
]})
When I run above query in mongo shell, the results are returned instantly. But when I use it in Meteor client, the results take almost 40 seconds to return from server. Here is my meteor client code:
Template.testing.onCreated(function () {
var instance = this;
// initialize the reactive variables
instance.loaded = new ReactiveVar(0);
instance.limit = new ReactiveVar(20);
instance.autorun(function () {
// get the limit
var limit = instance.limit.get();
var keyword = Router.current().params.query.k;
var searchByLocation = Router.current().params.query.l;
var startDate = Session.get("startDate");
var endDate = Session.get("endDate");
// subscribe to the posts publication
var subscription = instance.subscribe('sub_testing', limit,keyword,searchByLocation,startDate,endDate);
// if subscription is ready, set limit to newLimit
$('#searchbutton').val('Searching');
if (subscription.ready()) {
$('#searchbutton').val('Search');
instance.loaded.set(limit);
} else {
console.log("> Subscription is not ready yet. \n\n");
}
});
instance.testing = function() {
return Collection.find({}, {sort:{id:-1},limit: instance.loaded.get()});
}
And here is my meteor server code:
Meteor.publish('sub_testing', function(limit,keyword,searchByLocation,startDate,endDate) {
Meteor._sleepForMs(200);
var pat = ".*" + keyword + ".*";
var pat2 = ".*" + searchByLocation + ".*";
return Jobstesting.find({$or:[{title:{$regex: pat, $options:"i"}}, { company:{$regex:pat,$options:"i"}},{ description:{$regex:pat,$options:"i"}},{location:{$regex:pat2,$options:"i"}},{country:{$regex:pat2,$options:"i"}}],$and:[{date_posted: { $gte : endDate, $lt: startDate }},{sort:{date_posted:-1},limit: limit,skip: limit});
});
One point I'd also like to mention here that I use "Load More" pagination and by default the limit parameter gets 20 records. On each "Load More" click, I increment the limit parameter by 20 so on first click it is 20, on second click 40 and so on...
Any help where I'm going wrong would be appreciated.
But when I use it in Meteor client, the results take almost 40 seconds to return from server.
You may be misunderstanding how Meteor is accessing your data.
Queries run on the client are processed on the client.
Meteor.publish - Makes data available on the server
Meteor.subscribe - Downloads that data from the server to the client.
Collection.find - Looks through the data on the client.
If you think the Meteor side is slow, you should time it server side (print time before/after) and file a bug.
If you're implementing a pager, you might try a meteor method instead, or
a pager package.

jmeter - counting cookie values

I'm playing around with jmeter to validate a bug fix.
Server logic sets the cookie "mygroup" it can be either "groupa" or "groupb". I want to be able fire a series of requests and be able to see there is a proper balanced distribution between the values of this cookie. Ie make 100 requests and 50 times the cookie will be set to "groupa" and "groupb".
I'm a bit stuck on this. I currently have the following. I can see the cookies being set in the results tree but I'd like to be able to display the a table with the version and the number of requests of each.
Thread Group
HTTP Cookie Manager
HTTP Request
View Results Tree
Within the results tree I can see Set-Cookie: mygroup="groupa" and also sometimes mygroup="groupb" how do I tabulize this ??
You can have cookies values exported as JMeter variables by setting:
CookieManager.save.cookies=true
in user.properties.
Add a Cookie Manager to your Test Plan.
In this case you will have the var COOKIE_mygroup set by JMeter.
You can then count it like this using a JSR223 Sampler + Groovy (add groovy-all-version.jar in jmeter/lib folder:
String value = vars.get("COOKIE_mygroup");
Integer counterB = vars.getObject("counterB");
Integer counterA = vars.getObject("counterA");
if(counterA == null) {
counterA = new Integer(0);
vars.putObject("counterA", counterA);
}
if(counterB == null) {
counterB = new Integer(0);
vars.putObject("counterB", counterB);
}
if(value.equals("groupa")) {
counterA = counterA+1;
vars.putObject("counterA", counterA);
} else {
counterB = counterB+1;
vars.putObject("counterB", counterB);
}
Asyou have only one thread, at end of loop you can then compare the 2 values or just display the value:
add a debug sampler
add a view tree result
Run test plan, in view result tree click on debug sampler , select response tab and you should have your values