[Wtr-development] A solution for JavaScript dialogs in Watir

Jarmo jarmo.p at gmail.com
Fri Oct 29 12:34:44 EDT 2010


Why not add those working methods to that wikipage also?

I'd vote to clean up that wikipage since it has a lot of complex and
ugly code there.

Also, i'm in favor of using the solutions provided by Jari, since
javascript dialogs are usually pointless and if you really need to
test the existence of them then you could it one time - at some
specific test, which tests that the dialog appears. All the other time
you could just ignore them and this solution would be the way to do
it.

Jarmo

On Fri, Oct 29, 2010 at 6:35 PM, Bret Pettichord <bret at pettichord.com> wrote:
> Yes, this is what Selenium has done from day one (which is why
> ThoughtWorkers know about it). It, in fact, is the only way that Selenium
> can handle these.
>
> There are pros and cons to using this technique. But no reason not to share
> with people. Some testers will be disturbed when they learn it eliminates
> the dialogs entirely. I don't use it personally, because I have other
> methods that work.
>
> Bret
>
> On Thu, Oct 28, 2010 at 9:16 PM, Alister Scott <alister.scott at gmail.com>
> wrote:
>>
>> Hi,
>>
>> One of the guys I am working with setting up Cucumber and Watir on a
>> ThoughtWorks project told me about a way to get rid of the pesky JavaScript
>> dialogs that cause Watir scripts to be unstable. It involves overriding the
>> JavaScript function to always return true, so the dialogs never appear.
>>
>> I wrote an example for Watir:
>>
>> require 'rubygems'
>> require 'watir'
>> b = Watir::Browser.start
>> "http://www.sislands.com/coin70/week1/dialogbox.htm"
>> b.execute_script "window.confirm = function() { return true; }"
>> b.execute_script "window.alert = function() { return true; }"
>> b.execute_script "window.prompt = function() { return true; }"
>> b.button(:value => 'confirm').click
>>
>>
>> What do you think of this? Is it worthwhile putting this out for Watir
>> users to see and use?
>>
>> Cheers,
>>
>> Alister Scott
>> Brisbane, Australia
>> Watir Web Master: http://watir.com
>> Blog: http://watirmelon.com
>> LinkedIn: http://www.linkedin.com/in/alisterscott
>>
>> "There are two ways to get enough: One is to continue to accumulate more
>> and more. The other is to desire less." ~ G. K. Chesterton
>>
>> _______________________________________________
>> Wtr-development mailing list
>> Wtr-development at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/wtr-development
>
>
>
> --
> Bret Pettichord
> Lead Developer, Watir, www.watir.com
>
> Blog, www.io.com/~wazmo/blog
> Twitter, www.twitter.com/bpettichord
>
>
> _______________________________________________
> Wtr-development mailing list
> Wtr-development at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-development
>


More information about the Wtr-development mailing list