watirfirewatirwatir-webdriver

Does Watir-webdriver resolve the difference in indexing bases between Watir and Firewatir?


One of the barriers (that as far as I know was never removed, but perhaps I'm mistaken and this was resolved a while ago?) to being able to have truly cross browser compatible tests with Watir and Firewatir is that Watir was originally designed to use One based indexing, while whoever created firewatir broke with that and made it Zero based.

While I'm sure there are good historical reasons for each decision, and I don't want to debate which is right, it's been a pain for testers trying to create scripts that run under each without any alteration since at the very least this affects identifying elements by :index, which is sometimes something you've no choice but to do.

I'm wondering if moving to Watir-Webdriver could create a more uniform platform?

Also do we have any reference to the differences between the latest Watir, and Watir-Webdriver? For example in a recent question here it came up that .value= is not implemented as a 'direct set without events' alternative to .set, and basically acts just the same as .set does.


Solution

  • The best solution to this problem would be for Watir 1.X to gain configurable indexing. I believe the majority of that work has already been done on Bret's zero-index branch, so it's just a question of someone picking that up and getting it out there.

    When we were migrating to watir-webdriver, we added this monkey patch to help with this problem:

    class Fixnum
      def as_index
        Config.webdriver? ? self - 1 : self
      end
    end
    

    and then in our scripts:

    browser.div(:index => 1.as_index)
    

    Then when we were off Watir completely, it was a simple matter of grepping for as_index throughout the code base and decrement the indexes by one.

    I've tried to document the major differences between Watir and watir-webdriver on this wiki page. I'm sure it's lacking, and if someone wants to improve it, that's very welcome of course :)