Paul Rogers
7/23/2007 6:14:00 PM
On Jul 23, 12:11 pm, Paul Rogers <pmr16...@gmail.com> wrote:
> On Jul 23, 11:20 am, "Kyle Schmitt" <kyleaschm...@gmail.com> wrote:
>
>
>
> > Hey all.
> > Short version: the Proc I pass to Watir's add_checker is run twice on
> > each page load
>
> > Long version:
> > I'm trying to get decent logging out of my watir scripts, without an
> > insane amount of extra code.
>
> > I settled on using the add_checker method, which takes a Proc, to
> > handle things like assertions.
>
> > Every class in my script inherits from SuperPage (shown below, heavily
> > heavily chopped down for ease of reading).
> > Aside from running the Proc twice, this seems to work well.
>
> > The throw is commented out, because well, sometimes you want the error
> > in your page, but you want the thing to continue. Obviously if it's
> > not commented out, the proc only runs once. And yes I know having the
> > page seems like overkill, but I want to be able to retrieve it from an
> > xml log file later (after I replace my log method)
>
> > Thanks --Kyle
>
> > require 'win32ole'
> > require 'zlib'
> > require 'base64'
> > require 'watir'
>
> > class SuperPage
>
> > def initialize(baseURL,pageURL,pageName,phrases=["Server Error"])
> > @pageURL = pageURL
> > @pageName = pageName
> > @baseURL = baseURL
> > @phrases = phrases
> > setupIE()
> > end
>
> > def logError(message)
> > log(:Error,message)
> > #commented out, so log the error but try and continue
> > #throw :assertion_error
> > end
>
> > def log(type,message)
> > puts("#{type.to_s}: #{message.to_s}")
> > end
>
> > def buildAssertionChecker()
> > Proc.new do
> > |ie|
> > @phrases.each do
> > |phrase|
> > if ie.text.include?phrase
> > z=Zlib::Deflate.new(9)
> > logError("Found #{phrase}, compressed b64 encoded page is
> > #{Base64.encode64(z.deflate(ie.html,Zlib::FINISH))}")
> > end
> > end
> > end
> > end
>
> > def setupIE()
> > begin
> > @ie=Watir::IE.attach(:url,/localhost/)
> > rescue
> > @ie=Watir::IE.new()
> > @ie.goto(@baseURL)
> > end
> > @ie.waitForIE
> > #add the checking facility
> > @ie.add_checker(buildAssertionChecker)
> > end
>
> > end
>
> You'd do better to post to the watir list.
> This might be due to a number of reasons - if you can post some html I
> might be better able to help you.
> Which version of watir are you using?
>
> Paul
actually looking at it again, if you always use the same phrases, then
you are basically asking watir to run a new error_checker, but which
is checking for exactly the same thing.
If the phrases are different for each page, then maybe delete the
checker when youve finished with it
Paul