TwinTechs

Dream, Create, Deliver…

More SafariWatir additions: linkhandledbyjs

May 1st, 2009 · No Comments · Mobile Devices, RIA, iPhone/iPod Touch

In our app, we use the jQuery tabs plugin to provide a JavaScript-driven tabs interface. The tabs themselves are a elements, and clicking on them hooks into the jQuery tab click handler to switch different content areas to be visible. Unfortunately, when trying to automate tests with SafariWatir, the test was not working when trying to click the tabs, because SafariWatir assumes a elements to always be traditional links with HREFs.

I was able to patch SafariWatir with a HtmlElement::linkhandledbyjs method for a elements like the jQuery tabs that aren’t traditional links, but are instead handled by JavaScript. Here’s the code:

# Add our linkhandledbyjs method to HtmlElement.  This is to be used
# for "a" elements that have their click event handled by JavaScript,
# as opposed to traditional "a" elements that follow their href attr.
module Watir
  module Container
    class LinkHandledByJS < Link
      def click
        @scripter.highlight(self) do
          click_element
        end
      end
    end

    def linkhandledbyjs(how, what)
      LinkHandledByJS.new(scripter, how, what)
    end

    class HtmlElement
      OPERATIONS = {
        :id => "by_id",
        :index => "by_index",
        :class => "by_class",
        :name => "by_name",
        :text => { "Link" => "on_link", "Label" => "by_text",
           "LinkHandledByJS" => "on_link" }, # add our class here
        :url => "on_link",
        :value => "by_input_value",
        :caption => "by_input_value",
        :src => "by_src",
      }
    end
  end
end

Tags:

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.