is it possible to wait for XPath or CSS selector to display in Jmeter?
I am using HTTP request to send API call and I have assertion as CSS selector path but due to API slowness , I would like to implement a waitfor method for the specific element in UI.
JMeter doesn't execute any Post-Processors or Assertions or Listeners until it gets response from the server therefore you don't need to do anything. See Execution order user manual chapter for more details.
However if I misunderstood your requirement and you want to repeat a HTTP request until XPath or CSS extractor return the value you're looking for you can put the request under the While Controller and put the condition of your choice there:
In the above case:
On iteration 0 of the While Controller ${myVariable} doesn't have any value (CSS Selector Extractor hasn't been executed yet)
Iterations from 1 to 5 - ${myVariable} has value of foo which doesn't match While Controller's condition so it loops over
Iteration 6 - ${myVariable} value becomes bar and the While Controller exits the loop.
Just in case, textual representation of the jexl3() function used to compare variable with some value:
${__jexl3("${myVariable}" != "bar",)}
Related
Below code is in While controller
${__jexl3(${__jm__While Controller__idx} < 3 && "${responseCode}" != "200",)}
enter image description here
enter image description here
Above is in Regular Expression extractor
Result: It is looping 3 times for successful requests also but I want to loop only for failed requests and for success requests it should execute once
Thanks for in advance
Your regular expression extractor configuration is not correct, you need to apply it to Response Code, not to the Body
With your current configuration it extracts first numeric value from the response body and HTTP status code is not there, it's a special response header
Following another solution with a While Controller, If Controllers, and Flow Control Action (FCA) controllers.
Add the following into the While controller
${__groovy(${__jm__WC__idx}.toInteger() < 5)}
Add the request and two If controllers below them with Flow Control Action elements as shown in the figure
Add the following into the first If Controller
${JMeterThread.last_sample_ok}
Select Break Current Loop in the FCA element
Add the following to the second If Controller
${__jexl3(!${JMeterThread.last_sample_ok})}
Set the FCA to Go to the next iteration of the next loop
If you want to do something else, in addition, to retry, Set pause in the FCA element, add a JSR 223 element inside the FCA and include the actions. For example, I wanted to log the user name of the failing requests and retry.
String username = vars.get("username")
int current_loop_count = vars.get("__jm__WC__idx").toInteger()
log.warn("Attempt# ${current_loop_count.next()} $username ")
current_loop_count.next()<5?:ctx.getThreadGroup().getOnErrorStartNextLoop()
When i use a loop controller to go through my results from regex extractor, it stops working when i include a http request inside the loop controller.
Regex extractor format (will output multiple results with multiple groups each)
name of created variable - pageDetails
Template: blank
Match no -1
After that i initialized a loop controller (with a counter) to go through all the results of this regex
The counter is as follows
Starting value =1
Increment =1
Maximum value =${pageDetails_matchNr}
Reference Name =pageDetailsIndex
I have a debug sampler in the loop thats using the counter
${__evalVar(pageDetails_${pageDetailsIndex}_g1)} ${__evalVar(pageDetails_${pageDetailsIndex}_g2)}
Also have http request in the loop thats using the counter
If i disable the httprequest in the loop controller, the debug sampler works, and prints out all the values
However, if i enable the http request, BOTH the debug sampler and http request only work in the first iteration works i.e. when ${pageDetailsIndex} = 1. When its above 1 then ${__evalVar(pageDetails_${pageDetailsIndex}_g1)} etc. all return blanks...
Most probably your Regular Expression Extractor scope is not correct, if you want to apply it to one Sampler only - you need to make it a child of that particular sampler
From your explanation it seems that the HTTP Request sampler which is under the Loop Controller is overwriting the previous values which should not be the case.
Also be aware that your Counter is not necessary, there is ${__jm__Loop Controller__idx} special JMeter Variable which holds the value of the current iteration of the Loop Controller.
I want to manipulate the request body of HTTP thread based on the data extracted (using 'Regular Expression Extractor') from the previous HTTP response.
Here is the scenario:-
I have extracted the statusFlag and statusId from 'HTTP request 1' as:
Ref name: status
Reg. Exp: "statusFlag":"(\w+)","statusId":"(\w+)"
So, first I want to check that the value of statusFlag is 'New' or not.
If it is New then I have to proceed and feed statusId in next HTTP request or else display statusFlag mismatch.
Need help. Got stuck badly.
I believe Response Assertion is what you're looking for. Add it after the Regular Expression Extractor and configure it as follows:
Apply to: JMeter Variable -> statusFlag (or your reference name)
Pattern Matching Rules: Equals
Add New as a "Pattern to Test"
The assertion will check whether "statusFlag" is "New" and if not - it will fail the sampler and report the expected and the actual value.
Optionally you can add If Controller after the Response Assertion, use ${JMeterThread.last_sample_ok} as a condition and place 2nd request as a child of the If Controller - it will be executed only if "statusFlag" is new.
See How to Use JMeter Assertions in Three Easy Steps guide for more information on conditionally setting pass or fail criteria to requests in your JMeter test.
That's how your Jmeter project should look like.
Regular Expression Extractor stores extracted value in ct variable that can be accessed in If Controller as "${ct}" == "yourvalue" and, if true, can be also sent as a part of Request 2 body using the same ${ct} reference.
Jmeter project structure
I am new to JMeter. I am using the Regular Extraction extractor as i want to check when the text "Completed" appears on the webpage.
On the page I click a run button.
The page will process some data & show a progress bar.
I have used the recorder to capture all the steps from login to the processing page.
The processing takes time to complete and I want to check when the complete message appears.
This way I know the processing has completed as i am testing how long the processing takes with x number of users for this page.
I have put the regular expression extractor in a While loop controller.
The Regular expression extractor i have set the following values:
Reference Name: Completed
Regular Expression: div class=""gwt-Label absoluteleft padding">[Completed]
Template: $1$
DefaultValue: None
I have inspected the web page and the html content shown is:
<tdbody>
<tr>
<td>
<div class=""gwt-Label absoluteleft padding">Completed.</div>
</td>
</tr>
</tdbody>
Have i done my regular expression correctly to check for the completed message appears?
I think i am doing the test the wrong as it looks like the while controller is stuck in an infinite loop.
My set up is like this:
Thread Group
- HTTP Request Defaults
- HTTP Cookie Manager
-Recording controller
- http requests (login, select project, go to processing page, run process)
- While controller
- http request (the page which does the processing)
- regular expression extractor
- Constant timer
In the While controller i have tried setting the Condition field to the value Completed.
I run it, it never exits the loop.
I think maybe i need an assertion to check when the completed message appears then it will exit.
I understand the While loop will keep running while true. When the condition is false then it will exit.
Can you post the condition in your while controller? The while controller can be very difficult when it comes to the condition. You can try:
${__javaScript("${Completed}" == "Completed")}
or
${__javaScript("${Completed}" != "Completed")}
depending on whether you want the While controller to execute when the action has been completed or while it has not.
I have to write load tests for web application using JMeter. The application has items available for booking, each item has a 'Book' button. If some user clicks this button for item, it becomes unavailable for other users. My question is:
Is it possible to make JMeter threads to book different items (to make different requests) and how to implement it?
You should be able to determine what parameter is being posted by different "Book" buttons and modify nested requests as needed. Test plan structure should be something like:
Open Booking Page - HTTP Request
Get all Booking IDs - Post Processor
Book - HTTP Request
Where "Post Processor" can be
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
In case of multiple matches Post Processor will return multiple variables like
BookindID_1=some value
BookindID_2=some other value
BookindID_3=some other value 2
....
BookindID_matchNr=10
There are at least 2 options on how to proceed with these values:
Iterate all the values using ForEach Controller
Stick to current virtual thread number via __threadNum function so thread #1 will take BookindID_1 variable, thread #2 - BookingID_2 variable value, etc.
It is also possible to take random value using __Random function but it may result in request failure if item is not available.
The correct way of 2 variables combination looks like:
${__V(VAR1${VAR2})}
So combining BookingID_N and __threadNum will look like
${__V(BookingID_${__threadNum})}
See How to use JMeter Functions post series for more on what can be done via functions.
yes, If every item has static(predefined) unique id,descriptor,identifier then that can be parameterized using a csv config file or random no. generator and selector
Random no generator and selector will work only for integers but csv config is better/standard practice. If you need more help please paste your test plan here with explaination of your need.