web_reg_save_param_regexp in Vugen
This is a crosspost, as I initially posted in the incorrect forum...
I'm having an issue using web_reg_save_param_regexp in Vugen. I need to grab the "href" parameter from the following HTML code:
<a href="/some/url/here/"> <img src="/some/other/url/here.gif" border="0" align="absmiddle"/> Foo</a>
I have found this href parameter to be anywhere from the second to the fourteenth on the page, so using "ORDINAL=" to find the position doesn't work. As a result, I elected to use web_reg_save_param_regexp.
According to the web_reg_save_param_regexp reference in Vugen, a valid Perl regex will work in this function. I've built and tested the following regex, which correctly extracts the URL I'm looking for:
However, when I insert the following code into Vugen, it complains that the specified parameter can't be found:
web_reg_save_param_regexp("ParamName=Correlation1", "RegExp=<a href=\"(.+)\".+Foo<\/a>", LAST);
I assume that this is because the source HTML in the page spans multiple lines, but there does not appear to be an equivalent to Perl's "s" flag, which allows the regex to span multiple lines.
Unfortunately, the href is dynamicly generated each time the application runs, so I can't just hardcode it, and I am not the author of the webpage, so glomming all this together into one line in the page source is not an option.
Help? Am I missing flags for this function? Is there a better way to do this with a different web_reg_save_param_* function?
P.S. This thread has been moved from Application Perf Mgmt (BAC / BSM) Support and News Forum to LoadRunner Support Forum. -HP Forum Moderator
Also, FWIW, in trying to use web_reg_save_param_xpath I can't even extract a single parameter based on XPath!
When I test the code code ...
web_reg_save_param_xpath("ParamName=Correlation1", "QueryString=//a/@href", SEARCH_FILTERS, "Scope=Body", LAST);
...it should extract the href of the first <a> tag on the page, but it doesn't. The code:
web_reg_save_param_xpath("ParamName=Correlation1", "QueryString=//a[contains(.,'Foo')]/@href", SEARCH_FILTERS, "Scope=Body", LAST);
...should extract the href of the 'Foo' link from above, but again it doesn't.
What am I doing wrong?
For correllating my current HTTP script for an SAP Web application I ran into a ton of trouble with the traditional LB/RB approach of web_reg_save_param_ex, and decided to dive in to regexp as a whole. After beating my head against a wall for a bit, I noticed in the documentation's examples the authors are actually double-escaping anything that is a literal or is an escape char that needs to stay there.
Here's an exampl e. I had retreive the mangled string in the center of the below url from the server's response body.
web_reg_save_param_regexp( "ParamName=corSapShortUrl", "RegExp=application_list\\\\.exit_url=/sap\\((.*)\\)/bc/bsp/sap/crm_ic", "Ordinal=1", SEARCH_FILTERS, "Scope=Body", "IgnoreRedirections=No", LAST);
In order for the escaped literals to remain escaped according to compiler, you have to escape the escape marks. It can get a bit silly in some cases. Here is another example below.
/* 8_V27_admini_table.unit\\" class=\\"sapDdlWhl\\"><option value=\\"CON\\" selected>?alsotry~ "RegExp=table\\[[0-9]+?\\]\\.unit\\\\\" .+?\\<option value=\\\\\"([A-Za-z]+?)\\\\\" selected\\>", */
"RegExp=admini_table\\[1\\]\\.unit\\\\\" .+?><option value=\\\\\"([A-Za-z]+?)\\\\\" selected>",
I admit that these regular expression strings look like they could be overkill for what I'm trying to capture. They work though!
Hope this helps!
To correlate multi-line dynamic parameters, after several hours of trials, the following worked for me. It uses nested paranthesis to capture each line that could end with newline. It grabs the value that could be up to 200 lines, which you can adjust.