The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP / Mercury LoadRunner

Pages: 1
thorwath
Veteran


Reged: 07/22/99
Posts: 3840
Loc: Grand Rapids, MI
web_reg_save_param_regexp() questions
      #707194 - 05/16/12 01:09 PM

Just when I am foolish enough to think I understand regular expressions something comes along to put me in my place. I have two questions for those who know how to boss around regular expressions in vuGen 11. The BODY text being returned for both of my questions is:

var data = "App.XD._scbs.f593bfb3ce8ce7\\x2D\\x7B\\x0A\\x20\\x20\\x22 status\\x22\\x20\\x3A\\x20200,\\x0A\\x20\\x20\\x22callid\\x22\\x20\\x3A\\x20100410100,\\x0A\\x20\\x20\\x22userid\\x22\\x20\\x3A\\x20\\x226cf0225c\\x2Dd80f\\x2D48a0\\x2D939c\\x2Dd2540702136e\\x22,\\x0A\\x20\\x20\\x22 state\\x22\\x20\\x3A\\x20\\x22 SUCCESS\\x22\\x0A\\x7D";\n

1. Extracting the status value. This is the only regEx expression that I can get to extract the status number 200:

"RegExp=status.*x20([0-9]+),.*call"

I initially thought I could use: "RegExp=status.*x20([0-9]+),"

But when I used that regEx pattern it returns the 100410100 value. Now that also qualifies for this regEx pattern but I am surprized that LR returns the last match rather than the first (which is how the older functions worked). I tried to use the Perl interval construct, but it has no positive effect (but using it did not throw a runtime error):

"RegExp=status.*x20([0-9]+),{1}" and "RegExp=status.*x20([0-9]+){1},"

So is there a way to construct a regEx pattern to select a specific occurance of the match, when there is more than one match in the Body?

2. Extracting the state value. All of the following regEx expressions extract the state string SUCCESS:

a. "RegExp=state.*x22([a-zA-Z_]+)"
b. "RegExp=state.*x22([a-zA-Z_]+)\\.*"
c. "RegExp=state.*x22([a-zA-Z_]+)\x5C.*"
d. "RegExp=state.*x22([a-zA-Z_]+)\134.*"

Now 2(a) is the cleanest, but I like an explicit RB anchor. But I get the following error for b, c, and d when the pattern does not end with (what seems to me unnecessary as per my O'Riely book on RegEx) the .* character combination:

Error -35055: Invalid regular expression [MsgId: MERR-35055]

So why is "RegExp=state.*x22([a-zA-Z_]+)\\.*" a valid regEx pattern while "RegExp=state.*x22([a-zA-Z_]+)\\" " is not?

-Thanks, Terry Horwath


Post Extras: Print Post   Remind Me!   Notify Moderator  
LoadRunner421
Member


Reged: 05/06/11
Posts: 142
Re: web_reg_save_param_regexp() questions [Re: thorwath]
      #707199 - 05/16/12 01:52 PM

I'm no expert but I've been using LR regex for a little while.

This one worked for me to get the 200:
Regex: status.{1,25}([0-9][0-9][0-9])

I believe the key is the '{1,25}', assuming there is a pattern/format for how far away the '200' is from 'status'.


Post Extras: Print Post   Remind Me!   Notify Moderator  
TeeJay0469
Member


Reged: 11/03/10
Posts: 43
Loc: MN, USA
Re: web_reg_save_param_regexp() questions [Re: thorwath]
      #707201 - 05/16/12 01:57 PM

Hi Terry,

The simple asnwer is that it is most likely the escaping of the "\" character and it is very very fussy. Play around with how many you use in order to get it to work. I had one RE that invovled the "\" character (for a file path name) and needed FOUR in a row..... I acually ran the RE through that wonderfully helpful Rubular website and it worked cleanly there. After reading and rereading and rereading the document over several times, I determined that the only thing it could have been was the escaping. After lining up 4 in a row, it suddenly worked so sweetly.

Tom


Post Extras: Print Post   Remind Me!   Notify Moderator  
LoadRunner421
Member


Reged: 05/06/11
Posts: 142
Re: web_reg_save_param_regexp() questions [Re: TeeJay0469]
      #707316 - 05/17/12 08:50 AM

I actually realized you could also just do:

status.{1,25}([0-9]{3})


Post Extras: Print Post   Remind Me!   Notify Moderator  
thorwath
Veteran


Reged: 07/22/99
Posts: 3840
Loc: Grand Rapids, MI
Re: web_reg_save_param_regexp() questions [Re: LoadRunner421]
      #707338 - 05/17/12 12:23 PM

421,

Thanks for this feedback. I was pondering your "status.{1,25}..." syntax (why 1?) and found that while LR says the BODY response is:

t=24432ms: 842-byte chunked response body for "https://ptest-[redacted]/controller/api/widget/validatepu...
<html>\n
<head>\n
</head>\n
<body>\n
<div id="root"></div>\n
<script type="text/javascript">\n
var data = "App.XD._scbs.f593bfb3ce8ce7\\x2D\\x7B\\x0A\\x20\\x20\\x22status\\x22\\x20\\x3A
\\x20
200,\\x0A\\x20\\x20\\x22callid\\x22\\x20\\x3A\\x20100410111,\\x0A\\x20\\x20\\x22useri
d\\x22\\x20\\x3A\\x20\\x226cf0225c\\x2Dd80f\\x2D48a0\\x2D939c\\x2Dd2540702136e\\x22,\\x0A\\
x20\\x20\\x22state\\x22\\x20\\x3A\\x20\\x22SUCCESS\\x22\\x0A\\x7D";\n
var xdUrl = "https\\x3A\\x2F\\x2Fptest\\x2Dstatic.v.me\\x2Fxdr.html";\n
if (typeof window.postMessage != 'undefined') {\n
parent.postMessage(data, xdUrl.split('/', 3).join('/'));\n
} else if (xdUrl.indexOf(window.location.protocol) != 0) {\n
window.name = encodeURIComponent(data); window.location.href = xdUrl;\n
} else {\n
document.getElementById("root").innerHTML = '<iframe src="'+encodeURI(xdUrl)+'" name="'+en
codeURIComponent(data)+'"></iframe>';\n
}\n
</script>\n
</body>\n
</html>\n

In reality this relevant string within the BODY is actually being returned:

<html>\n<head>\n</head>\n<body>\n<div id="root"></div>\n<script type="text/javascript">\nvar data = "App.XD._scbs.f593bfb3ce8ce7\x2D\x7B\x0A\x20\x20\x22 status\x22\x20\x3A\x20200,\x0A\x20\x20\x22callid\x22\x20\x3A\x20100410111,\x0A\x20\x20\x22userid\x22\x20\x3A\x20\x226cf0225c\x2Dd80f\x2D48a0\x2D939c\x2Dd2540702136e\x22,\x0A\x20\x20\x22state\x22\x20\x3A\x20\x22SUCCESS\x22\x0A\x7D";\nvar xdUrl = "https\x3A\x2F\x2Fptest\x2Dstatic.v.me\x2Fxdr.html";\nif (typeof window.postMessage != 'undefined') {\nparent.postMessage(data, xdUrl.split('/', 3).join('/'));\n} else if (xdUrl.indexOf(window.location.protocol) != 0) {\nwindow.name = encodeURIComponent(data); window.location.href = xdUrl;\n} else {\ndocument.getElementById("root").innerHTML = '<iframe src="'+encodeURI(xdUrl)+'" name="'+encodeURIComponent(data)+'"></iframe>';\n}\n</script>\n</body>\n</html>\n

The difference being that the Replay Log LR display is escaping the backslash characters, as in \\x22, etc.

So once I figured that out I could then use the exact interval count of any char matches using this regEx statement: "RegExp=status.{16}([0-9]{3})". But my original regEx statement is a bit more flexible and does not depend on char counts. I would still like to construct a statment that logically says: get the FIRST pattern match of this: "RegExp=status.*x20([0-9]+)," but its proper regEx contruction still aludes me.


Post Extras: Print Post   Remind Me!   Notify Moderator  
LoadRunner421
Member


Reged: 05/06/11
Posts: 142
Re: web_reg_save_param_regexp() questions [Re: thorwath]
      #707340 - 05/17/12 01:17 PM

Yes the 1 in the {1,25} is probably not necessary, I was just using a range that worked.

I can see that you somehow know that "x20" is always in the string, so can't you find out how long the string is? Even if it's a range you can still use the curly braces to your advantage, unless the range is too big, then the second match will be picked up sometimes...

I know what you're saying though about finding the first match, that would be a useful regex function, I wonder if it's out there...


Post Extras: Print Post   Remind Me!   Notify Moderator  
ptrussell_ncModerator
Super Member


Reged: 01/17/06
Posts: 1636
Loc: Charlotte, NC
Re: web_reg_save_param_regexp() questions [Re: LoadRunner421]
      #707346 - 05/17/12 03:57 PM

And now for something completely different...

Why are you trying to do what you are trying to do?


When I look at your input, the last thing I think is Regular Expression. I would step back and figure out what I really wanted to do and approach it completely differently.

Yes, the above is my personal opinion, and yes, I DID NOT read this thread in detail.

--------------------
Unless you are writing a compiler, strtok is NOT the answer.
See: http://www.sqaforums.com/showflat.php?Cat=0&Number=541641&Main=541641#542222

QAF is still an exercise in self-sufficiency! (Thank JB!)


Post Extras: Print Post   Remind Me!   Notify Moderator  
thorwath
Veteran


Reged: 07/22/99
Posts: 3840
Loc: Grand Rapids, MI
Re: web_reg_save_param_regexp() questions [Re: ptrussell_nc]
      #707420 - 05/18/12 06:59 AM

Russell,

Well of course you can always be counted on to read a thread before diving in!

So you would go after correlation of ...status\x22\x20\x3A\x20num,... using web_reg_save_param()? I did not mentioned that I have received 2 builds that return different BODY syntax (the first sent "...status : num..., while the latest build is returning URL compliant syntax).

Now that I figured out that the LR Replay Log was escaping the \ chars I could go back and use web_reg_save_param() but web_reg_save_param_regex() seems more flexible in this situation.

So I would like it if you would expand on your opinion here, as I can always use another experienced point of view when it comes to correlating values.

-Thanks, Terry


Post Extras: Print Post   Remind Me!   Notify Moderator  
ptrussell_ncModerator
Super Member


Reged: 01/17/06
Posts: 1636
Loc: Charlotte, NC
Re: web_reg_save_param_regexp() questions [Re: thorwath]
      #707428 - 05/18/12 08:05 AM

The escaping and levels of escaping are exactly why when I looked at your post I thought "YUCK!"

In a case like this I want to get what I get and then work with a knife to cut it down. That way I can look at each cut I make and if it's not working back it out.

-------------

If different builds are changing what is returned then you need to recode. Everyone needs to understand that!

--------------------
Unless you are writing a compiler, strtok is NOT the answer.
See: http://www.sqaforums.com/showflat.php?Cat=0&Number=541641&Main=541641#542222

QAF is still an exercise in self-sufficiency! (Thank JB!)


Post Extras: Print Post   Remind Me!   Notify Moderator  
sharathreddybode
Newbie


Reged: 02/18/08
Posts: 23
Re: web_reg_save_param_regexp() questions [Re: ptrussell_nc]
      #719148 - 11/01/12 11:43 AM

All,

How to capture Sharath2Bode using LR9.5?
ID=\x22Sharath2Bode\x22>

Can pls anyone suggest?


Post Extras: Print Post   Remind Me!   Notify Moderator  
LoadRunner421
Member


Reged: 05/06/11
Posts: 142
Re: web_reg_save_param_regexp() questions [Re: sharathreddybode]
      #719151 - 11/01/12 12:20 PM

Quote:

All,

How to capture Sharath2Bode using LR9.5?
ID=\x22Sharath2Bode\x22>

Can pls anyone suggest?




What have you tried? Seems pretty simple to me using web_reg_save_param with left boundary="x22" and right boundary="x22"

You must not be explaining the whole problem.

Also from reading your past few posts it doesn't seem like you've been formally trained. Have you been formally trained on how to use Loadrunner?



Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 36 anonymous users are browsing this forum.

Moderator:  AJ, James Pulley, ptrussell_nc, JimHowell1970 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 10423

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5