Jmeter - Auth token over time, troubles with evaluation of __time() function - authentication

I have two Threads running in parallel, one responsible for the load testing, the other for generating Authentication token.
The problems I have are in this section:
enter image description here
Two if controllers checking basically the current time with the jmeter function ${__time(/1000,)}.
If the time + {delay time for next request} < current time = > time =current time and make request for the auth token.
The other controller's purpose is making the thread "sleep" for 30 seconds.
My problem is that it seems the if statement is executed only once and can not enter this if() and update my time property, hence only 1 token is requested and after time it will expire.
Do you have any idea why this if() statement is executed only once /Thread is infinite/ and how can I check for the current time ?

It is not very possible to come up with the comprehensive solution without seeing your If Controllers conditions, so far I can only suggest checking all the variables and expressions using Debug Sampler and View Results Tree listener combination (including the functions used in the If Controllers)
Also be aware that
starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
it is NOT recommended to reference JMeter Functions and/or Variables like ${__time(/1000,)} in Beanshell/Groovy scripts

Related

Running login operation 1/50 or 1/100 ratio of the total request in jmeter

I am running some tests on JMeter. I am testing a web application and its functionality for example login, homepage, product catalogue. So I have a test script and I am using the ultimate thread group for the users. But I would like to run the login request only once or twice on every 100 requests. I know I can use if controller for that and I tried few solutions but did not work. So I would like to know how I can run requests properly?
You're supposed to share your "few solutions", otherwise it sounds like you're asking us to solve your problem.
If you want to run a Sampler 1 time per 100 iterations you can use the following __jexl3() function as the If Controller's condition:
${__jexl3(${__jm__jp#gc - Ultimate Thread Group__idx} % 100 == 0,)}
If you changed the Ultimate Thread Group label from default jp#gc - Ultimate Thread Group - you will need to change it in the function as well.
More information: 6 Tips for JMeter If Controller Usage
P.S. In majority if cases Throughput Controller is much easier to use
You can use Once Only Controller to run a request only once per thread/user
You can use Throughput Controller to run requests by the percentage of total execution or count
You can use Random Controller to randomly pick one item from the child requests
You can use If Controller with execution count check
${__groovy(vars.get("loginCount").toInteger() <=4 && (new Random()).nextBoolean() )}
You will have to set the loginCount variable for successful logins
int loginCount = vars.get("loginCount").toInteger().next()
vars.put("loginCount", loginCount.toString())
You need to ensure the login request is executed in the first iteration/loop. For the following iterations, you can randomly pick the login request using other appropriate logic controllers.
Also you can combine them to simulate complex combinations.

Is there a way to clear graphql-rate-limit default in-memory stored contexts?

I am writing a GraphQL API using apollo-server-express.
I implemented a rate limit for a login query using graphql-rate-limit directive approach. I use client IP to identify the context, using default InMemoryStore provided by package. window value is 60s and max value is 10. The rate limit implementation is working as expected.
But I wrote security e2e tests using Mocha, Chai, and graphql-request, and rate limit (as expected) always make it go wrong. It happens because I need to execute login queries to get token before every set of tests. But even if I just set a valid token without request to API, it probably will return an error.
In other tests, I just disable rate-limit. But in the case of security it does not makes sense.
Is there a way to clear stored contexts, in order to avoid the issue? For example, create a mutation for this purpose, or pass a value in headers (both just enabled in development/test environment).

Jmeter - How to use the variable set in first request for all the threads in one thread group

I would like to run one request only once, and get an authorization token from its response using Json extractor and then use that token as header in another request that runs under the same thread group.
I tried to use "setup Thread Group", but the variable value was not available to the main thread group.
So, I used "If Controller" under the same thread group, with below condition:
${__groovy(ctx.getThreadNum() == 0 && vars.getIteration() == 1,)}
This is making the specific request to be executed only once.
However, variable value is available only for one thread for the subsequent requests, but not for all the threads. Below is the picture of results tree:
May I know how to access the variable value set in first request for all the threads instead of just one thread?
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
So if you want to use a single token for all threads (virtual users) you need to convert it into a JMeter Property first like:
Under the If Controller use __setProperty() function to convert your variable into a property
In your GET request use __P() function to read the property value
Another way of sharing data between threads (even if they're in different thread groups) is using Inter-Thread Communication Plugin
You are not allowed to use the variable created in one thread in other threads this is how JMeter scoping for variables extracted works.
You already near to solution, providing steps so any one can approach problem like this:-
Use If Controller to make sure only once request being made to get Authorization token
Extract the token using post-processor
Save token in the property using post-processor so that same token can get used in multiple threads
Use newly created property instead of a variable in subsequent requests by referring property function instead of variable
You can use one JSR223 post-processor like below to create a property from the variable:
Please note that if you are mimicking multiple users using thread group, ideally you should create different auth token for different users.
P.S.: Balzemeter have an article which uses the BeanShell to demonstrate how to solve this problem

Page Factory - how does it work

I've tried to implement one of our app modules by using PageFactory (for iOS)
Most of the elements are located by name and others by classname
In general everything works (more or less) but the thing is that the appium server has tons of logs , it seems that each time I'm trying to use some page control , and all the declared controls within that page are being update (?) which cause to longer time execution.
In case and I'm trying to debug my test , it takes a lot of time to move step by step (the appium server works extra hours ...)
I do use "CacheLookup" whenever it possible ...
Where my mistake is, or it's just should be like that ?
Thanks
Updated
Not enough info provided to say for sure. If you have a bunch of cucumber steps and each step is creating a new page instance then yes, you could create a class variable to communicate between cucumber steps
Class variables get thrown out at the end of each scenario so no cross scenario contamination. However, if a single scenario leaves a page and comes back you would need to explicitly set the class page handle to nil/null so that it is reinitialized upon reentry to that page. You want to avoid stale element errors.

JMeter Tests and Non-Static GET/POST Parameters

What's the best strategy to use when writing JMeters tests against a web application where the values of certain query-string and post variables are going to change for each run.
Quick, common, example
You go to a Web Page
Enter some information into a form
Click Save
Behind the scenes, a new record is entered in the database
You want to edit the record you just entered, so you go to another web page. Behind the scenes it's passing the page a parameter with the Database ID of the row you just created
When you're running step 5 of the above test, the page parameter/Database ID is going to change each time.
The workflow/strategy I'm currently using is
Record a test using the above actions
Make a note of each place where a query string variable may change from run to run
Use a XPath or Regular Expression Extractor to pull the value out of a response and into a JMeter variable
Replace all appropriate instances of the hard-coded parameter with the above variable.
This works and can be automated to an extent. However, it can get tedious, is error prone, and fragile. Is there a better/commonly accepted way of handling this situation? (Or is this why most people just use JMeter to play back logs? (-;)
Sounds to me like your on the right track. The best that can be achieved by JMeter is to extract page variables with a regular expression or xpath post processor. However your absolutely correct in that this is not a scalable solution and becomes increasingly tricky to maintain or grow.
If you've reached is point then you may want to consider a tool which is more specialised for this sort of problem. Have a look web testing tool such as Watir, it will automatically handle changing post parameters; but you would still need to extract parameters if you need to do a database update but using Watir allows for better code reuse making the problem less painful.
We have had great success in testing similar scenarios with JMeter by storing parameters in JMeter Variables within a JDBC assertion. We then do our http get/post and use a BSF Assertion and javascript do complex validation of the response. Hope it helps