02.19.08

Would My Watir Tests Run With Firewatir?

Posted in Watir at 5:00 pm by Željko Filipin

I saw this question at watir-general.

Short story is, there is no simple solution at the moment. I am just porting my tests from Watir to Firewatir and I have noticed two major differences:

  1. Firewatir does not see page text the same way as Watir does:

    • Watir would see “logged in as name”.
    • Firewatir would see “logged in as\n\nname”.
  2. Firefox sees relative urls in links, while Internet Explorer sees apsolute paths:

    • Watir would see “page.htm”.
    • Firewatir would see “domain.com/page.htm”.

I created a separate branch of my tests for Firewatir, until I see what should be changed in original tests to make them compatible with both Watir and Firewatir. If I can not make them work at both, I do not think that maintaining two branches will be much work.

If you are using id’s for identifying page elements, I think most of your test should work.

7 Comments »

  1. Jared said,

    February 21, 2008 at 2:35 pm

    Hi Zelko,

    If the problem is only /n’s in text, can you just test for the string with the /n’s removed? eg. test_string.gsub(/\n/,”")==string_to_check

    Alternatively, could you override String’s ‘==’ method at startup. eg.

    In your main file:

    @firewatir=true
    test_string=”fasdf\n\nasdfasd”
    puts test_string==”fasdfasdfasd”
    require ‘extension.rb’ if @firewatir
    puts test_string==”fasdfasdfasd”

    In extension.rb:
    class String
    alias_method :original_equals, :’==’
    def ==(string_to_check)
    return self.gsub(/\n/,”").original_equals(string_to_check)
    end
    end

    It’s not perfect if the newlines are actually important, but beats modifying all of your code.

    I’m assuming the URLs are a problem because you want to check the page you are on? Or is it when navigating?

    Either way, something like -

    @baseUrl=” if @internet_explorer
    @baseUrl=’http://www.baseurl.com’ if @firefox

    Then do all of your checks as:

    if url = @baseurl + @page ….

    Ideally, put this behaviour into your own URL object.

    Does this sound like it would work?

  2. Željko Filipin said,

    February 21, 2008 at 2:52 pm

    Jared,

    you are right, if text that Firewatir sees has only additional \n’s (and similar), that would be trivial to fix. We will see.

    URLs are bugging me both when navigating to page and when checking the page, and your suggestion how to solve the problem looks great!

    Anyway, I have just started to port my tests (and there are lots of them), so I am not sure what will happen. I thought I would make a separate branch to play with so I would not complicate existing code. Your solution looks so simple, I will just have to try it. I will write about it here, soon I hope.

  3. Jared said,

    February 21, 2008 at 10:59 pm

    Good luck…I can see a few different approaches for the Url aspect. You might even try modifying the return methods of Watir itself to get consistency. Another idea might be putting the above url logic into String in a ‘to_url’ method, or creating some kind of ‘compare_url’ method. But you’ll need to get trickier if you have multiple base urls.

    It’s something I thought about a while back, and we’re rarely in a situation where we need to, but when I worked on an automation project for a long time (over 12 months) I learned that it often pays to hide everything behind your own abstractions as soon as you see some benefit. Some of that abstraction is going to be done by the Watir team itself as they merge all the different flavours, but some of it is stuff we should probably be doing ourselves as good programming practice.

    Perhaps we need a wiki space for examples of these kind of things. Much of it is really ‘programming for testers’, and I’m just as much in need of that kind of help as anyone else :)

    Another side note is that the FireWatir/Watir url problem actually exists in ‘regular’ watir if you start trying to access IE.ie.Document, I’m pretty sure. I know I encountered the issue when I was trying to build a ’save_complete_html_page’ method. I might check that code and see if there’s something there that can help.

  4. Željko Filipin said,

    February 22, 2008 at 11:16 am

    I have been writing Watir tests for the project I am working on at the moment for almost three years now. I guess that counts as long lasting project. :)

    Everything is abstracted by now. My tests look like:

    user.log_in
    event.add
    user.log_out

    Actually, you can put examples at Watir wiki. Even more, I (and I am sure I am not alone) would really like to see more examples. Let me know if you need help with Watir wiki.

    Please let me know what you found about (Fire)Watir url’s.

  5. coral said,

    March 14, 2008 at 5:06 am

    Hi Zelko,

    I have a quesiton about the Firewatir how to catch the pop up windows.

    My htm script as follows:

    testing

    function showAlert() { alert(”Alert showing!”); }

    testing
    Handler can deal with the link:
    Click this link

    Handler can’t deal with the form submit button:

    I want to catch the button pop up, so i write the script as follows:
    require ‘rubygems’
    require ‘firewatir’

    include FireWatir

    ff=Firefox.new
    ff.goto(”file://C:/test.html”)
    puts “Working with popup from links:”
    ff.startClicker(”OK”, 1, ”, “Click this button”)
    ff.button(:name, “submit”).click
    #assert_equal(”Alert showing!”, ff.get_popup_text)
    ff.startClicker(”OK”, 1, ”, “Alter”)
    ff.button(:name, “OK”).click
    ff.close()

    the Javascript pop up windows was opened, but i can’t catch the ok button, could you help me to correct this script error?
    Thank you very much

  6. Željko Filipin said,

    March 14, 2008 at 10:53 am

    Coral,

    I did not have to deal with pop ups, so I really do not know the answer. You should post it at Firewatir Google group.

    http://groups.google.com/group/firewatir

  7. coral said,

    March 17, 2008 at 8:27 am

    ok, Thank you all the same

Leave a Comment