One other thing about getting stuff in post-processors using regex...

You want to try to make your expression as generic as possible - while still 
being specific enough to get what you want.

This is so your test case won't break if there are slight variations in the 
response data being returned - to the point that the
variations are not actually a functional change in the code.

For example, in our systems, we have a generic "Test Fragment" for logging into 
the web site we're testing. We include this test
fragment in dozens of other tests - that need the user logged in before we can 
step through the test procedure. We get a few
variables that can be used by subsequent tests through Regular Expression Post 
Processors. But if we code our regex patterns too
specifically in that login system - slight changes in the login system will 
break all of our test cases (until we modify the login
test and retest everything). So we've learned to setup our regex patterns to 
get what we need in the most 'flexible' way possible.
Take a look at the following returned string, and see the patterns we used:

Returned string:

<a href="/some/path/to/a/link" id="my_id" name="my name" style="color: 
red;">This is the link text</a>

If I setup my regex to be very specific for this pattern:

        pattern=<a href="([^"]*)" id="my_id" name="my name" style="color: red;">

It will surely match when I first setup my tests. But if a future code update 
changes anything in that link, I will break the
regex... On the other hand, if I _know_ that the link I need is the one with 
the 'id="my_id"' in the anchor tag, I can make my
expression a little less picky, and still match so long as the changes made to 
the code don't swap the order of the 'href' and 'id'
parameters in the anchor tag:

        pattern=<a[^>]*href="([^"]*)"[^>]*id="my_id"

This pattern will match any anchor tag that has an 'href="..."' in it, and is 
followed by an 'id="my_id"' somewhere after the href
in the same anchor tag. (The '[^>]*' pattern matches anything up to the closing 
">" character in the anchor tag - so it can never
jump out of this same anchor tag.) Based on this pattern, if the developers 
change the "name" or the "style" - my regex will still
get the variable I need. Likewise, if they do something incredibly subtle - 
like change the SPACE between the parameters to TABS (or
add extra spaces or tabs), it will still work. (Of course, if they swap the 
order of the parameters - so that 'id' comes before
'href', I still break - but at least I've limited the ways in which I will 
break...)

Just a suggestion when building out your test cases.

--
Robin D. Wilson
Sr. Director of Web Development
KingsIsle Entertainment, Inc.
VOICE: 512-777-1861
http://www.kingsisle.com


-----Original Message-----
From: Deepak Shetty [mailto:shet...@gmail.com] 
Sent: Wednesday, November 13, 2013 1:01 PM
To: JMeter Users List
Subject: Re: Jmeter Regex advice - qualifier string after regex

Hi
I guess your expression is too greedy (Im assuming you are getting a lot more 
than 12354

a href=([^>]*)><span>Foo2
Note that your snippet is invalid html and people tend to put in quotes or 
apostrophes or add spaces or more attributes and if you
want to write an expression that doesnt break easily youll have to change the 
regex.
the other way would be to modify your expression to have .*? - that would work 
but it would be inefficient


On Wed, Nov 13, 2013 at 9:11 AM, Gavin Maselino
<gavinmasel...@hotmail.com>wrote:

> Hi
> So here is an example of the JMeter response I am struggling with:
> <div><a href=12354><span>Foo1<a href=12357><span>Foo2</div> The text I 
> need to use regex on is the ahref next to Foo2 (12357).When I do this 
> regex on RegexTester.com (a href=(.*)><span>Foo2), it returns the href 
> value for Foo1.
> Can anyone advise how I can get the ahref for Foo2?
>  I cannot use XPath extraction as the real response I am using has 
> hexademical in it so a '<' is actually encoded as '\u003C'.
> Thanks
>


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

Reply via email to