You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Jakob van Bethlehem <ja...@jet-stream.nl> on 2013/03/05 11:24:20 UTC

Inserting a user-defined variable in a Response Assertion pattern

Dear users,

This week I started looking into JMeter for testing some components of our software. I'm still in the process of digesting the huge amount of possibilities within JMeter, so maybe my (current) question (and near-future questions) are of the RTFM kind, but at least maybe someone can then send me to the right part of the manual ;)

So while creating an extremely test script based on the example in ch5 of the manual, I suddenly came to the realization that I wanted to add the value of a user-defined variable inside a Response Assertion pattern. To be more exact: the tests can be run on different hosts, so I created a HOST variable, but on certain pages that host is displayed, which I would like to add again to the response pattern.

Is this possible?

Sincerely,
Jakob van Bethlehem
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Inserting a user-defined variable in a Response Assertion pattern

Posted by Jakob van Bethlehem <ja...@jet-stream.nl>.
Hello Flavio,

Thanks a lot for the detailed explanation. You helped me get a bit further, but not quite to the point I was hoping to get. Let my try to clarify a bit more on what I'm trying to achieve:
- our software accepts an 'about' parameter, and when passed and equal to 1, it will display a nice 'about'-page, with company logo, etc, -and- the hostname of the server
- in a typical installation of the software, there is a whole bunch of servers that run that accept that parameter, displaying the 'about'-page
- I created the following simple Test Plan:
Test Plan
+ Thread Group
++ HTTP Request Defaults
++ HTTP Request
+++ Response Assertion
+++ View Results Tree

I have now idea whether I'm trying to achieve something really useful, but the idea is to be able to repeat the same Test Plan for different hosts. Using Test Plan variables using the techniques you described works beautifully for achieving this, except that I would like to include the selected hostname in the Test Pattern configured in the Response Assertion. In the Response Assertion I basically put the 'about'-page that should be send by the server, but that server is variable, hence the pattern should change when the host is different. I tried simply writing ${myHost1} inside the pattern, with and without the '$' escaped, but that didn't do the trick.

Is there a trick to achieve this? Or is it nonsense anyway (a viable possibility, me being a complete newby when it comes to this kind of testing)

Sincerely,
Jakob van Bethlehem

On 5 mrt. 2013, at 13:15, Flavio Cysne <fl...@gmail.com> wrote:

> Welcome, Jakob.
> 
> As a starting point I suggest you reading the Best Practices advice (
> http://jmeter.apache.org/usermanual/best-practices.html ).
> 
> At first, before capturing the script, add an HTTP Request Defaults
> configuration component and fill in the fields host, port, HTTP
> implementation, protocol and content encoding.
> Before capturing, add as many Test Plan variables as the hosts you are
> testing against (I suppose you are already doing this).
> 
> The first will ensure that any HTTP request captured by JMeter proxy, that
> have the same parameters, will follow the defaults (fields inside HTTP
> Request sampler will be left blank).
> The second will help you to parameterize some of the Request Headers
> parameters. Ex.: Host and Referer parameters.
> 
> After capturing you could change Host field in HTTP Request defaults with a
> Test Plan variable.
> 
> Test Plan variables that are subject to change should have their values
> defined like this: ${__P(myHost1,my.host1.com)}
> myHost1 = parameter passed on command line: jmeter -n -t myTestPlan.jmx
> -JmyHost1=my.alternative.host
> my.host1.com = default variable value if myHost1 parameter is not passed


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Inserting a user-defined variable in a Response Assertion pattern

Posted by Flavio Cysne <fl...@gmail.com>.
Welcome, Jakob.

As a starting point I suggest you reading the Best Practices advice (
http://jmeter.apache.org/usermanual/best-practices.html ).

At first, before capturing the script, add an HTTP Request Defaults
configuration component and fill in the fields host, port, HTTP
implementation, protocol and content encoding.
Before capturing, add as many Test Plan variables as the hosts you are
testing against (I suppose you are already doing this).

The first will ensure that any HTTP request captured by JMeter proxy, that
have the same parameters, will follow the defaults (fields inside HTTP
Request sampler will be left blank).
The second will help you to parameterize some of the Request Headers
parameters. Ex.: Host and Referer parameters.

After capturing you could change Host field in HTTP Request defaults with a
Test Plan variable.

Test Plan variables that are subject to change should have their values
defined like this: ${__P(myHost1,my.host1.com)}
myHost1 = parameter passed on command line: jmeter -n -t myTestPlan.jmx
-JmyHost1=my.alternative.host
my.host1.com = default variable value if myHost1 parameter is not passed