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


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

Question:

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?

Thanks!


Answer:

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:

TEST_JSON:

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

TEST_RESULT_SUCCESS

if(obj.status != "success")
{
    setFailed();
}`

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

eval(vars.get("TEST_JSON"));
eval(vars.get("TEST_RESULT_SUCCESS"));

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

eval(vars.get("TEST_UTIL"));

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


Related:


Expressive assertion failure messages in C++


c++,unit-testing,assertions,verbosity
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...

Apache httpd connection refused during stress test using jmeter


apache,jmeter,connection-refused
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...

importing VHDL packages to SV from libraries other than WORK


vhdl,system-verilog,assertions
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...

Jmeter BeanShell - compare between int to counter


jmeter,beanshell
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...

Token Parsing Error: Lexical error


jmeter,beanshell
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 java.io.FileOutputStream; import java.util.Map; import java.u . . . '' Token Parsing Error: Lexical error...

JMeter variable scope in threads


jmeter
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...

Not able to record HP Webtour app using Jmeter


jmeter,record
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...

JMeter - Graphite Backend listener rootmetricsPrefix taking previously generated value


jmeter,graphite
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...

.NET assert assertions are enabled


c#,.net,assertions
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...

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


jmeter
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...

How to use multiple checkboxes in jmeter?


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?

Why jMeter show transaction controller data in its summary report?


jmeter,performance-testing,load-testing,jmeter-plugins
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...

Can anyone explain me following RandomString


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

How to get value from property in BeanShell (jmeter)


variables,jmeter,beanshell
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...

How to Print variable in aggregate report jmeter?


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

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


json,string,groovy,soapui,assertions
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...

run sh script in jmeter


bash,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...

Calculating Age by custom Program


jmeter,parameterization
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...

Using Jmeter OS Process Sampler to collect script data


python,command,jmeter
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 use throughout operator in systemverilog assertions


system-verilog,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 http://www.testbench.in/AS_06_SEQUENCES.html) and the way I understood it, above mentioned spec can be written...

Jmeter - BeanShell assertion is not running


jmeter,beanshell
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 write pulse width systemverilog assertion when width is configurable


system-verilog,assertions
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...

Is it possible to remotely check a JMeter slave machine?


jmeter
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)...

Dollar Object intricacies


c#,tdd,assertions
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()...

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


java,jmeter,netty
I've implemented an HTTP service based on the HTTP server example as provided by the netty.io 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...

Running Java class with JMeter (Bean Shell)


java,jmeter,beanshell
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...

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


regex,jmeter,load-testing
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...

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


jmeter,performance-testing,jmeter-plugins,threadgroup
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


jmeter
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="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:SaveDocument xmlns:ns2="http://oword.muhc.ca/"> <DocumentID>0</DocumentID> <StatusCode>DRA</StatusCode> <TemplateID>17839</TemplateID> <Document>Testing save document.</Document>...

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


load,jmeter,performance-testing,loadrunner,grinder
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...

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


web-applications,jmeter,performance-testing,load-testing,loadrunner
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


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

static_assert fails check on templated object pointer


c++,templates,c++11,assertions,static-assert
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...

Custom FEST Assertions : Displaying readable message with


java,junit,testng,assertions,fest
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); } }...

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


jmeter
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?

Ignoring the Http Request Defaults in jMeter


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 Requests are concurrent requests or sequential requests?


jmeter,load-testing
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...

using JMeter proxy recorder behind company proxy with SSL manager


jmeter
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...

Is this possible to automate the JMeter scripts running schedule?


jmeter
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?

Jmeter- How to extract token id from Response Data


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

How to handle multi language website in jmeter script


jmeter
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.

Deleting unnecessary symbols from variable in Jmeter


variables,jmeter,trim,symbols,beanshell
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 2.10 Random Variable that gets data from string


variables,random,jmeter
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...

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


regex,json,xpath,jmeter
[ { "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 + Chrome driver config: empty page while processing


performance,google-chrome,jmeter,selenium-chromedriver
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


jmeter,jmeter-plugins
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...

Empty Response In BSF Post Processor


jmeter
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',...

Will jmeter function FileToString(path) takes dynamic values


jmeter
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 JDBC Call returns the value as parameter name if the value received from DB is null


jmeter
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?


jmeter
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...