The xpath is surely the best way in your case.
Ideally you should convince the developers to place an explicit id on
the node containing the booking reference: this makes your xpath even
simpler and it won't break if the design of the page is totally changed
in the next release of your app.

Concerning regex, you can toggle flags in your regex for instance with
(?-s) for DOTALL.

See:
http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

Marc.

John and Pip wrote:
> Hi Ralf,
> 
> Thanks heaps for that. It works perfectly and I even kind of understand it!
> 
> In the mean time I had got xPath working as well using
> //div[div='BOOKING REFERENCE']/div[2]/div. I had a string() around it
> which seemed to mess it up (although had been working OK I think in the
> past?).  I also found that DOTALL flag in QuickREx so have turned it off
> so I don't confuse myself in future.
> 
> So wins on all counts - much appreciated!
> 
> regards,
>       John
> 
> On 3/15/07, *Ralf Müller* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
>     Hi!
> 
>     I guess it is because the webtest regular expressions are greedy which
>     means that an expression like .+ tries to match as many characters as
>     possible and not just the next characters until the next \r\n as
>     intended.
>     So if you change your expression to
>     <storeRegEx
>       description="Extract confirmation number i.e. PNR Ref"
>       text="BOOKING REFERENCE[^\r]+((\r\n)[^\r]+){2}\r\n[^&gt;]*.([^&lt;]+)"
>       group="3"
>       property="PNR_Ref" />
>     <echo message="PNR Ref of #{PNR_Ref}" />
> 
>     it works fine.
> 
>     I just checked QuickRex: I guess the main difference is the flag
>     "DOTALL":
>     In dotall mode, the expression . matches any character, including a line
>     terminator.
> 
>     So if you are not in dotall mode, your expression works fine, but
>     webtest "is in" dotall mode.
> 
>     BTW: you should really try to use xpath :-)
> 
>     Cheers,
>     Ralf
> 
>     John and Pip wrote:
>     > Hi,
>     >
>     > I am using this regex:
>     >
>     > BOOKING REFERENCE.+((\r\n).+){2}\r\n[^>]*.([^<]+)
>     >
>     > to extract the booking reference (EAMPXH) out of this page
>     (simplified):
>     >
>     > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>     > " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>     > <html xmlns=" http://www.w3.org/1999/xhtml"; xml:lang="en"
>     > lang="en"><head>
>     > <title>Air New Zealand Bookings - Booking
>     Confirmation</title></head><body>
>     > <div id="main" style="display: block;">
>     > <div class="i20">
>     >     <div class="panel">
>     >         <div class="paneltext">BOOKING REFERENCE</div>
>     >     </div>
>     >     <div class="indentcell">
>     >         <div class="errorstyle" style="font-family:
>     > Arial,Verdana,Helvetica,sans-serif; font-style: normal; font-variant:
>     > normal; font-weight: bold; font-size: 14px; line-height: normal;
>     > font-size-adjust: none; font-stretch: normal;">EAMPXH</div>
>     >     </div>
>     > </body></html>
>     >
>     > When I put the regex into QuickREx in eclipse, it highlight up to the
>     > end of the reference, and when I click through the groups at the
>     bottom
>     > it gives me this as the 3rd group.
>     >
>     > However, when I do this in my WebTest script:
>     >
>     >                 <storeRegEx
>     >                     description="Extract confirmation number i.e.
>     PNR Ref"
>     >                     text="BOOKING
>     > REFERENCE.+((\r\n).+){2}\r\n[^&gt;]*.([^&lt;]+)"
>     >                     group="3"
>     >                     property="PNR_Ref" />
>     >                 <echo message="PNR Ref of #{PNR_Ref}" />
>     >
>     >
>     > The result I get is just the ">" character.
>     >
>     > The results.xml shows:
>     >
>     >             <step>
>     >                 <parameter name="description" value="Extract
>     > confirmation number i.e. PNR Ref"/>
>     >                 <parameter name="group" value="3"/>
>     >                 <parameter name="property" value="PNR_Ref"/>
>     >                 <parameter name="taskName" value="storeRegEx"/>
>     >                 <parameter name="text" value="BOOKING
>     > REFERENCE.+((\r\n).+){2}\r\n[^>]*.([^&lt;]+)"/>
>     >                 <result>
>     >                     <completed duration="16"/>
>     >                 </result>
>     >             </step>
>     >             <step>
>     >                 <parameter name="message" value="PNR Ref of >"/>
>     >                 <parameter name="taskName" value="echo"/>
>     >                 <result>
>     >                     <completed duration="0"/>
>     >                 </result>
>     >             </step>
>     >
>     > I turned logs to debug and the relevant output is:
>     >
>     > [storeRegEx] DEBUG
>     (com.canoo.webtest.reporting.StepExecutionListener) -
>     > isToIgnore: [EMAIL PROTECTED], main
>     > [storeRegEx] DEBUG (com.canoo.webtest.reporting.StepResult ) - In
>     > retrieveNestedText
>     > [storeRegEx] INFO (com.canoo.webtest.steps.Step) - >>>> Start Step:
>     > storeRegEx "Extract confirmation number i.e. PNR Ref" (8/10)
>     > [storeRegEx] DEBUG ( com.canoo.webtest.steps.Step) - Executing
>     storeRegEx
>     > "Extract confirmation number i.e. PNR Ref" (8/10)
>     > [storeRegEx] DEBUG (com.gargoylesoftware.htmlunit.WebResponseImpl)
>     - No
>     > charset specified in header, trying to guess it from content
>     > [storeRegEx] DEBUG (com.gargoylesoftware.htmlunit.WebResponseImpl) -
>     > Nothing guessed, supposing that it is ISO-8859-1
>     > [storeRegEx] DEBUG (com.canoo.webtest.steps.Step) -
>     setWebtestProperty:
>     > PNR_Ref=> [null]
>     > [storeRegEx] DEBUG ( com.canoo.webtest.steps.Step) - Finished
>     storeRegEx
>     > "Extract confirmation number i.e. PNR Ref" (8/10)
>     > [storeRegEx] DEBUG (com.canoo.webtest.steps.Step) - Completed Step:
>     > storeRegEx "Extract confirmation number i.e. PNR Ref" (8/10)
>     > [storeRegEx] DEBUG (com.canoo.webtest.steps.Step) - Step didn't
>     produce
>     > results, no need to notifying listeners
>     > [storeRegEx] DEBUG ( com.canoo.webtest.steps.Step) - <<<< Successful
>     > Step: storeRegEx "Extract confirmation number i.e. PNR Ref" (8/10)
>     >
>     > I've spent a good few hours trying things with no success so I'd be
>     > grateful if anyone could advise me on what to do as I'm starting
>     to look
>     > pretty stupid here at work!
>     >
>     > Incidentally, the response from the invoke saved during the test is
>     > identical to the input file.
>     >
>     > Please don't suggest using storeXPath as an alternative as the
>     reason I
>     > turned to storeRegEx was because of problems with storeXPath -
>     I'll post
>     > that separately!
>     >
>     > I am using version R_1498
>     >
>     > regards,
>     >          John
> 
>     _______________________________________________
>     WebTest mailing list
>     [email protected] <mailto:[email protected]>
>     http://lists.canoo.com/mailman/listinfo/webtest
> 
> 

_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest

Reply via email to