jmeter,assertions , JMeter assertion modularity (can I re-use assertions?)

JMeter assertion modularity (can I re-use assertions?)


Tag: jmeter,assertions

I am working on a test plan for our REST web application and we have several common test types which have common criteria we want to test for. For example, when creating entities through the API we have a common set of expectations for the JSON response; id should be set, created date should be set, etc.

Now, I would like to model my plans like this:

Now, I understand how the scoping works and that if I placed assertions where the BOLDed module controllers are they would be invoked for each sampler. However, I'd rather not have to copy-paste-maintain numerous copies of the same assertions in each of these locations. Hence, why I want a way to define assertions once, and invoke where appropriate.

However, with this approach, the ACCENTed assertions placed in the common simple controllers are never invoked (confirmed by using a BSF assertion with logging messages). If I place an additional sampler in the common assertions simple controller it is invoked. But only a single time.

I'm using JMeter 2.12 but have confirmed that JMeter 2.8 behaves the same way.

So, how can I use JMeter to define assertions once, and re-use them anywhere?



I ended up getting creative. Using JSR223 assertions in Javascript I've accomplished what I wanted. This is a natural fit because all the response data I want to test is in JSON, YMMV.

In User Defined Variables I define the tests I want to perform using Javascript.

Tests like:


    eval('var obj = ' + prev.getResponseDataAsString());
} catch(e)


if(obj.status != "success")

Then in the assertion(s) I can do something like:


And I don't have to re-write tests over and over and over.

I even have some a some utility functions that I can add to my assertion by doing


which allows me to print additional logging from my assertions if I desire.


Deleting unnecessary symbols from variable in Jmeter

I have variable as string in this view: ["564546","56454654","3123123","868987"] I need the script that deletes unnecessary symbols [ ] " and put it to another variable . (something like trim method) I assume it should be made in BeanShell pre-processor....

JMeter: Is it possible to assign a UI value to a JMeter variable

I want to login in to an email server and read the value '5' from inbox(5) in a variable to use it further.Is this possible?

Calculating Age by custom Program

There is one POST request which submits both Date of Birth & Age. I found the Date of Birth from previous request, extracted it through Regular Expression Extractor, and passing the Variable in the POST request. But I did not found the Age from the previous request. Tried figuring out...

Will jmeter function FileToString(path) takes dynamic values

Will jmeter function FileToString(path) takes dynamic values. I need to use around 400 json files as a input. so planning to use FileToString($fileName}) in body data. By providing the filename column in csv. But it seems Jmeter is checking filename as file instead of getting value from csv....

Jmeter + Chrome driver config: empty page while processing

I configured jmeter to run tests using Chrome Driver Config. Test run with no errors: 2015/06/01 20:14:14 INFO - jmeter.engine.StandardJMeterEngine: Running the test! 2015/06/01 20:14:14 INFO - jmeter.samplers.SampleEvent: List of sample_variables: [] 2015/06/01 20:14:14 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 2015/06/01 20:14:14 INFO - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 2015/06/01...

if-else block in JMeter

I expect two possible cases in my application: Search was successful and search was failed. In both cases I have two different sets of HTTP requests, which JMeter should execute. How can I implement if-else block in JMeter scenario? I've tried to use if controller with Regular Expression Extractor, but...

How to extract All of reg expression matches from html page via JMeter

I have a html page containing userIds of students. I need to extract all the userId values from this html page and use them in a parameter of JMeter HTTP request.. For example i have following data on htm page. <input type="checkbox" StudentID="1503" <input type="checkbox" StudentID="1504" <input type="checkbox" StudentID="1505" so...

Not able to record HP Webtour app using Jmeter

I am new to Jmeter and I took HP Loadrunner Webtour application for testing. I am not able to record the Webtour app using Jmeter. I have already changed my settings for firefox browser to its proxy port where it will record the Jmeter scripts. I tried other web application...

static_assert fails check on templated object pointer

template <size_t N> class Foo { static_assert(N > 0, "WRONG"); //void Something() = 0; //my original implementation }; int main() { Foo<0> *p2 = nullptr; //no error Foo<0> p; //gives an error return 0; } I've tested both the lines separately. static_assert is not called when p2 is initialized but...

using JMeter proxy recorder behind company proxy with SSL manager

Hi I am facing following issue when try to use JMeter proxy recorder behind company proxy There are two environments one is not using company proxy(QA env) other is using company proxy(UAT env) Also both sites are using client side certificate to identify user(saml2). When recording in the QA environment...

Apache httpd connection refused during stress test using jmeter

Now, I do stress test using jemter in windows(jmeter.bat). Number of Threads = 100 Ramp-up period = 0 Loop count = 1000 But raise connection refused error in jmeter, after 20~30 seconds. I can not find connection refused error in /usr/local/apache/logs/error.log or /usr/local/apache/logs/access.log. Test is HTTP GET, index.html("It's works") Apache...

JMeter variable scope in threads

I have a JMeter tests which does the following: It makes a GET request. The request returns some ID which is extracted by a Regular Expression Extractor and is set to a variable myId. Another GET request is made using this ID stored in myId. It is important that the...

Which is the best performance testing tool when i dont know the client application behaviour. As i am going to have number of web based clients

My organization is looking to perform a performance testing externally. The performance testing is going to be only for web based applications. Can you guide me which tool is best to choose as performance testing tool. Right now there is no idea about the client web application behaviour. Beacuse there...

Where is HTML renderer of View Results Tree hidden in Jmeter 2.13

Where is hidden HTML response renderer option? This happened to me after update jMeter to 2.13 r1665067. ...

Expressive assertion failure messages in C++

Unit test frameworks generally provide very nice assertion failure messages (I'm using gtest) describing expected and actual values to a particular test. Furthermore, you know the origin of the function call because you're testing the interface of the class. In contrast, assert, when used as a sanity check in the...

Why incremental load and ramping up the threads is considered a best practice?

I was looking into performance testing and wanted to ask why ramping up slowly and then running under max load and then slowly ramping down is considered a better paradigm .And test team spends a lot of time achieving a perfect graph for the same. Though its completly subjective but...

SoapUi Assertions - Use a string as a json path with groovy

I am using groovy to automate some tests on SoapUI, and I wanted to also automate assertions in a way I would get a field's name and value from a *.txt file and check if the wanted field does exist with the wanted value in the SOapUI response. Suppose I...

importing VHDL packages to SV from libraries other than WORK

I have a VHDL module that is compiled to a library, say, LIB_A. The module has ports that are records, the corresponding type is defined in a package that is also compiled into LIB_A. I would like to write some assertions for the module and check them using OneSpin. At...

How to handle multi language website in jmeter script

I have website which supports English and French.I have already created script for website in English but now they want me to test against french website.So how can i extended my script that asssertions does not fail i test script any of those languages.

JMeter 2.10 Random Variable that gets data from string

I have 1st thread group that GETs some id's and writes it to the variable. This var has view like that "654564546,564564,56454,56456454,21231321,8972341,65423187". I need to pick up randomly one of the id and put it to the another variable. In jmeter 2.07 I used this code: import java.util.Random; String[] erroridcox...

Why jMeter show transaction controller data in its summary report?

Here i have A recording controller and test script recorder. I recorded the user activities using template. This automatically creates a Recording controller and then transaction controller. Each transaction controller has child HTTP request wrapped inside it. Now when I run the test after creating a test script, I see...

How to use throughout operator in systemverilog assertions

Here is a spec: If signal a is asserted then it must be asserted till signal b is asserted and then it should de-assert on next clock edge. I'm reading through 16.9.9 of LRM (as well as and the way I understood it, above mentioned spec can be written...

JMeter - Graphite Backend listener rootmetricsPrefix taking previously generated value

Background: I am using graphite to store the data generated during the performance test and ideally, we would like to look at the historical graphs as well. Hence, I am creating a rootMetricsPrefix folder name dynamically in a setup thread group and assigning it to a property. The backend listener...

Is this possible to automate the JMeter scripts running schedule?

Is this possible to schedule the JMeter scripts.for example I want to run the same script every hour and want to automate this process.Is this possible?

Using Jmeter OS Process Sampler to collect script data

Is it possible to collect the output of a python script using the "OS Process Sampler"? My python script does a database query and returns "r1=123 r2=456 r3=789" Is there a way to collect the r1, r2, r3 values and graph them?...

How to write pulse width systemverilog assertion when width is configurable

The scenario is: Signal active can be either 1 cycle, 2 cycle, 3 cycle or 4 cycle wide depending on config[1:0] input to the module Easiest way to write property for this is: property p_PropA; @(posedge clk) $rose active ##config ~active; endproperty But it is syntactically wrong. What is correct...

Empty Response In BSF Post Processor

I'm trying to use the BSF Post Processor with an HTTP request sampler. The body of the response is JSON, however it appears that I'm not seeing the body in my script. Test script below: var response = prev.getResponseDataAsString(); if (response.length > 0) { vars.put('foo', 'success'); } else { vars.put('foo',...

How to get value from property in BeanShell (jmeter)

I have got several thread groups. I want to use variable from the first group. In second group this var should be used in BeanShell. So: in first thread group I created BeanShell Assertion with this code: ${__setProperty(erroriden, ${erroriden1})}; In second thread group I have BeanShell pre-processor. If has line...

Dollar Object intricacies

I am reading Kent Beck's book "Test Driven Development: By Example." In his book, there is a coding example: public class Dollar { public int _amount; public Dollar(int amount) { _amount = amount; } public Dollar Times(int multiplier) { return new Dollar(_amount *= multiplier); } } [TestMethod] public void TestMethod2()...

How to extract all the Id's value from the Json given below using Regular expression extractor or any other Extractor(Xpath, Beanshell etc)

[ { "id": 1, "name": "MetaOperationN1", "type": "Operation" }, { "id": 2, "name": "GreenOper2", "type": "Operation" }, { "id": 3, "name": "GreenOper4", "type": "Operation" }, { "id": 4, "name": "GreenOper5", "type": "Operation" }, { "id": 5, "name": "GreenOper6", "type": "Operation" }, { "id": 6, "name": "GreenOper7", "type": "Operation" }, {...

Jmeter - BeanShell assertion is not running

When running the thread, it goes through the whole flow except for the last BeanShell assertion. My BeanShell code is: report = vars.get("status_1"); if (report=="active") { Failure = true; FailureMessage = "failed to report"; } else { Failure = false; } What could go wrong?...

How to use multiple checkboxes in jmeter?

In my script i have multiple checkboxes,upon selecting which it populate values(like in first group -- Phone,tablets and in other group it --mac,android).I know that jmeter does not support javascript.If i want to automate it in my script that it selects random checkbox during execution.How can i do that?

run sh script in jmeter

For load testing I want to randomize my testvalues before I run the test in jmeter. To do so, I want to use this bash script: #! /bin/bash cat data.dsv | shuf > randomdata.dsv This should be executed in jmeter. I tried using a BeanShell Sampler with this command (I...

How to Print variable in aggregate report jmeter?

I want to pass variable to aggregate report to distinguish request .How to print/pass a variable in aggregate report jmeter?

Custom FEST Assertions : Displaying readable message with

I have created a custom FEST Condition to verify that my actual string either matches or is equal to an expected String public class StringMatchesOrIsEqualTo extends Condition<String>{ private String expectedStringOrExpression; public StringMatchesOrIsEqualTo(final String expectedStringorExpression){ this.expectedStringOrExpression = expectedStringorExpression; } @Override public boolean matches(String value) { return value.matches(expectedStringOrExpression) || value.equals(expectedStringOrExpression); } }...

Token Parsing Error: Lexical error

I am getting the following error when I use a BeanshellPostProcessor to regex some data and write to file: 2015/06/11 12:11:19 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: `` import; import java.util.Map; import java.u . . . '' Token Parsing Error: Lexical error...

JMeter test on Netty-based impl produces error for every second request

I've implemented an HTTP service based on the HTTP server example as provided by the project. When I execute a GET request on the service URL from command-line (wget) or from a browser, I receive a result as expected. When I perform a load test using ApacheBench (ab -n...

JMeter Requests are concurrent requests or sequential requests?

I am new to JMeter, I want to do load testing on a particular web site. I have to do load test for the following requests on my web site -->Visiting login page -->Login to website -->visiting to products page -->Visiting to product details page for this I made script...

Is it possible to remotely check a JMeter slave machine?

We are setting up a load testing platform and developping some tools in go. We'd like to remotely check a JMeter load generator and (if possible) get some statistics or infos from a JMeter daemon. This will be from a utility developed in go (the language isn't the concern here)...

Jmeter BeanShell - compare between int to counter

I'm trying to compare int (parse from string) to counter in BeanShell assertion. my code: int i = Integer.parseInt(vars.get("count_2")); counter = vars.get("counter"); if (i != counter) { Failure = true; FailureMessage = "failed"; } else { Failure = false; } On debug sampler I can see that both "count_2" and...

Jmeter- How to extract token id from Response Data

This is the response data from which i need to extract token value { "token":...

How to decide the ideal hold time in Ultimate Thread Group in Jmeter

How can we decide the ideal hold time in Ultimate Thrad Group in Jmeter

Need help testing a web service method with a char parameter

I'm trying to use JMeter 2.13 to test my web service. One of the methods that I need to call has a parameter that is defined as char. The parameter is sex. Here is my HTTP request body data. <S:Envelope xmlns:S=""> <S:Body> <ns2:SaveDocument xmlns:ns2=""> <DocumentID>0</DocumentID> <StatusCode>DRA</StatusCode> <TemplateID>17839</TemplateID> <Document>Testing save document.</Document>...

JMeter: How to use the RESTful API key for authorization of the next set of API

I am creating a jmeter load test plan for RESTful API request. I need to use the dynamic API key generated in my first sampler SignIn API in the next set of API requests I am going to create. Can someone help out with how to pass the selected data...

Ignoring the Http Request Defaults in jMeter

Is there a way to tell an HTTP Request in jMeter to ignore the HTTP Request Defaults element? I've got a string of about 100 HTTP Requests that need the defaults but the last few I need to keep them from posting what's in the defaults.

JMeter JDBC Call returns the value as parameter name if the value received from DB is null

I am using a JDBC PreProcessor in JMeter to fetch a value from the DB before firing a SOAP call which needs to be enriched with that information. I have assigned a variable XYZ to fetch the value returned from DB. If there is a value returned from DB, i...

Why does HTTP Authorization Manager only work if HTTP Request implementation is HTTPClient3.1?

I have configured the HTTP Authorization Manager, but for some reason it only logs in if HTTPClient3.1 is selected as the implementation of my HTTP Request. Furthermore it does not seem like JMeter sends the information at all if Java or HTTPClient4 is selected. I'd like to know why that...

.NET assert assertions are enabled

How does one assert that assertions are enabled in C#? Here's a link to a related answer for Java, that does not work in C#. The purpose of this would be to prevent the use of release-type assemblies because where efficiency is of no concern I might as well be...

Running Java class with JMeter (Bean Shell)

I have written a Java Class for use in JMeter, packaged the project as a .jar file and moved that file into the lib/ext folder in the jmeter directory. I have seen documentation on how to proceed but they give contradictory answers. The first way is to use the BeanShell...

Can anyone explain me following RandomString

Can anyone explain me following syntax which is used to create randomstring ${__time(ddHHMMmmss)}${__javaScript(Math.floor((Math.random() * 10) + 1))} ...