<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: watir code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 18:31:10 GMT</pubDate>
    <description>DZone Snippets: watir code</description>
    <item>
      <title>watir element examine all attributes</title>
      <link>http://snippets.dzone.com/posts/show/5772</link>
      <description>// description of your code here&lt;br /&gt;patch to watir for examining all attributes of an element&lt;br /&gt;&lt;code&gt;&lt;br /&gt;module Watir&lt;br /&gt;  class Element&lt;br /&gt;    # for watir element returns array of arrays where each element is a [name, value] as long as value is other than null or blank&lt;br /&gt;    def get_attributes&lt;br /&gt;      attrs = []&lt;br /&gt;      self.document.attributes.each do |atr|&lt;br /&gt;        k= []&lt;br /&gt;        next if (atr.value == 'null') || (atr.value == '')&lt;br /&gt;        k &lt;&lt; atr.name &lt;&lt; atr.value&lt;br /&gt;        attrs &lt;&lt; k&lt;br /&gt;      end&lt;br /&gt;      return attrs.sort&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 15 Jul 2008 17:08:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5772</guid>
      <author>marekj (marekj)</author>
    </item>
    <item>
      <title>Separate Test Models and add Behaviours at runtime in Watir Tests</title>
      <link>http://snippets.dzone.com/posts/show/5381</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;module DefaultBehavior&lt;br /&gt;  def wag&lt;br /&gt;    puts 'default wag left to right'&lt;br /&gt;  end&lt;br /&gt;  def bark&lt;br /&gt;    puts 'woof woof default bark'&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;module SpecialBehavior&lt;br /&gt;  include DefaultBehavior&lt;br /&gt;  def bark&lt;br /&gt;    puts 'raah raah special bark'&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class DogAsTestModel&lt;br /&gt;  include DefaultBehavior&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;DogAsTestModel.new.wag &lt;br /&gt;DogAsTestModel.new.bark&lt;br /&gt;&lt;br /&gt;class DogAsTestModel&lt;br /&gt;  include SpecialBehavior&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;DogAsTestModel.new.wag &lt;br /&gt;DogAsTestModel.new.bark&lt;br /&gt;&lt;br /&gt;class DogAsTestModel&lt;br /&gt;  include SpecialBehavior&lt;br /&gt;  def bark&lt;br /&gt;    puts 'overwrite bark. Woooooof Woooooof'&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DogAsTestModel.new.wag &lt;br /&gt;DogAsTestModel.new.bark&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 Apr 2008 21:07:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5381</guid>
      <author>marekj (marekj)</author>
    </item>
    <item>
      <title>Watir Logging</title>
      <link>http://snippets.dzone.com/posts/show/5218</link>
      <description>// setup logging infrastructure for Watir tests using ruby Logger class&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#Logging infrastructure&lt;br /&gt;require 'logger'&lt;br /&gt;# hack ruby logger to format and output only the minimum needed for testing scripts&lt;br /&gt;# Logger is configured to write &lt;br /&gt;class Logger&lt;br /&gt;  # hack format of logger&lt;br /&gt;  class Formatter&lt;br /&gt;    #original: Format = "%s, [%s#%d] %5s -- %s: %s\n"&lt;br /&gt;    #Change the name of constant to avoid redefining the super which raises exception and bugs us.&lt;br /&gt;    Formato = "[%s] [%5s] : %s\n" &lt;br /&gt;    &lt;br /&gt;    #keep the original signature but alter implementation to change formatting&lt;br /&gt;    def call(severity, time, progname, msg)&lt;br /&gt;      #add logging to stdout&lt;br /&gt;      puts output_message = msg2str(msg)&lt;br /&gt;      STDOUT.flush&lt;br /&gt;      #original: Format % [severity[0..0], format_datetime(time), $$, severity, progname, msg2str(msg)]&lt;br /&gt;      Formato % [format_datetime(time),severity, output_message]&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;logfile = File.join(File.dirname(__FILE__),'..','log', 'logger.log')&lt;br /&gt;$log = Logger.new(logfile,'daily')&lt;br /&gt;$log.level = Logger::DEBUG&lt;br /&gt;$log.datetime_format = "%H:%M:%S"&lt;br /&gt;$log.info("Watir Execution Starts")&lt;br /&gt;$log.debug("Halllow Worled!")&lt;br /&gt;$log.info("Achtung Achtung. The Train will leave from platform 9")&lt;br /&gt;$log.warn("no no no no no. you can't do this")&lt;br /&gt;$log.error("error error Danger Danger")&lt;br /&gt;$log.fatal("game over game over game over")&lt;br /&gt;# example of output&lt;br /&gt;#[13:02:00] [DEBUG] : Watir Execution Starts&lt;br /&gt;#[13:02:00] [DEBUG] : Halllow Worled!&lt;br /&gt;#[13:02:00] [ INFO] : Achtung Achtung. The Train will leave from platform 9&lt;br /&gt;#[13:02:00] [ WARN] : no no no no no. you can't do this&lt;br /&gt;#[13:02:00] [ERROR] : error error Danger Danger&lt;br /&gt;#[13:02:00] [FATAL] : game over game over game over&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Mar 2008 18:05:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5218</guid>
      <author>marekj (marekj)</author>
    </item>
    <item>
      <title>Empty a Gmail label with FireWatir</title>
      <link>http://snippets.dzone.com/posts/show/3961</link>
      <description>When you have a huge label with thousands of messages, Gmail can't handle deleting all of them at a time (it says it can, but for me it's never worked). This solves the problem.&lt;br /&gt;&lt;br /&gt;I wrote it more as a practice to get familiar with FireWatir, so it's not very pretty or anything and it's a bit slow. If you have doubts on how to use or suggestions on how to improve it please feel free to contact me.&lt;br /&gt;&lt;br /&gt;By the way, it assumes Gmail is in German. Replace that string with the one that comes up for your language.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def empty_label(label)&lt;br /&gt;  # you need a Firefox instance already running with JSSh installed and listening&lt;br /&gt;  ff = Firefox.new&lt;br /&gt;  # Goes to Gmail in HTML&lt;br /&gt;  ff.goto('http://mail.google.com/mail/h/x4odcwnm5f5v/?s=l&amp;l=#{label}')&lt;br /&gt;  a = []&lt;br /&gt;  # doing 'c.set' didn't work for me here so I had to do this hack of getting the value&lt;br /&gt;  # and then acquiring the element thorugh ff.checkbox(:value,value)&lt;br /&gt;  ff.checkboxes.each {|c| a &lt;&lt; c.value}&lt;br /&gt;&lt;br /&gt;  while a.length &gt; 0 do&lt;br /&gt;    c = []&lt;br /&gt;    a.each {|v| c &lt;&lt; ff.checkbox(:value,v)}&lt;br /&gt;    # checks all checkboxes&lt;br /&gt;    c.each {|e| e.set}&lt;br /&gt;    # clicks the drop-down entry for deleting&lt;br /&gt;    ff.select_list(:name,'tact').select('In den Papierkorb verschieben')&lt;br /&gt;    ff.button(:name,'nvp_tbu_go').click&lt;br /&gt;    a = []&lt;br /&gt;    ff.checkboxes.each {|c| a &lt;&lt; c.value}&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 07 May 2007 21:54:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3961</guid>
      <author>helder (Helder Ribeiro)</author>
    </item>
  </channel>
</rss>
