1

I have some trouble with a regex in JMeter. I have this form in HTML

<form class="UIForm" id="UIComposer" action="/portal/intranet/?portal:componentId=b5914710-6c12-4fa9-9a18-2707d97111b7&interactionstate=JBPNS_rO0ABXcmAAt1aWNvbXBvbmVudAAAAAEAClVJQ29tcG9zZXIAB19fRU9GX18*&portal:type=action" onsubmit="return false;" method="post">

and I need to get the values of componentId and interactionstate in JMeter, as variables.

jscs
  • 63,694
  • 13
  • 151
  • 195
Roman Iuvshin
  • 1,872
  • 10
  • 24
  • 40
  • @DaveNewton You mean BlackGaff? Is he the JMeter guy around here? His avatar seems to be a generated one right now. EDIT: wait, never mind. Confusing him with skaffman. – G_H Oct 25 '11 at 20:02
  • @G_H Was quoting the seminal [no regex for html](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) post. – Dave Newton Oct 25 '11 at 20:11
  • @DaveNewton And just when I've used all my upvotes for the day... Man, that thread is a beauty. Thanks for the link! – G_H Oct 25 '11 at 20:14
  • @G_H That it is; pure artistry. And true, as good art is. – Dave Newton Oct 25 '11 at 20:16

3 Answers3

1

Use an XPath Extractor instead.

If you must use a regex, just search for regex tag parsing.

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • He actually needs some stuff that's inside an attribute value, so extracting with XPath would only be the first step. – G_H Oct 25 '11 at 20:04
  • 1
    @G_H Extractors are used for just that, getting stuff from XML/HTML and putting them into JMeter variables for later use. – Dave Newton Oct 25 '11 at 20:09
  • Whoa, thought you were merely talking about XPath. That looks real useful! I've used my upvotes for the day, will try to remember to upvote tomorrow. That, and actually clicking a link before commenting. – G_H Oct 25 '11 at 21:23
  • @G_H That would take all the adventure out of it. Yeah, JMeter can actually do some pretty twisted stuff. For fun, write a DSL that generates the XML test plans, including defining input data and specifying form/page elements. Re-use that info in easyb tests. Zing! BDD and load testing with big code re-use; it's fun. – Dave Newton Oct 25 '11 at 21:29
  • @G_H Enjoy the lovely user interface (which is why I did the DSL in the first place, although basically as easy to just use a builder). – Dave Newton Oct 25 '11 at 21:31
1

Jmeter uses PERL regular expressions to extract and store values into variables.

Here is a great resource for learning how to write them: http://www.regular-expressions.info/

Here's the link for the Jmeter user manual: http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor

In Jmeter, make sure you put parentheses () around the items you want to store to the variable. Given you're new to JMeter, I would recommend having TWO regular expressions - one for each item. This will make it easier for you to track and debug. You'll end up with expressions like: componentId=(.+?);

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
BlackGaff
  • 7,579
  • 1
  • 38
  • 45
0

Please don't use regular expressions for getting attribute values. There's so many corner cases in terms of character escaping and such that it's likely to break sometime. Look into XML processing APIs, like SAX, StAX, DOM or XSLT. Do mind that this requires the HTML to be XML compliant (if it's XHTML that's covered).

Once you get the value of your action attribute via a suitable API, you can then unleash regular expressions on it.

Alternatively, find out if you can somehow harness what already exists for handling HTTP posts/gets via the Servlet API or something similar. They place URL parameters in a map for retrieval.

G_H
  • 11,739
  • 3
  • 38
  • 82
  • Sorry, I'm not familiar with JMeter. Hope someone with more experience can help. – G_H Oct 25 '11 at 15:16