Sha256: 91f5888f29c021faecf6e2180b90273f36536fc22b1aa8454617a4826071b50d

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

$htmlRoot =  "file:///#{$myDir}/html/" 

module Watir::UnitTest
  # navigate the browser to the specified page in unittests/html
  def goto_page page
    new_url = self.class.html_root + page
    browser.goto new_url
  end
  # navigate the browser to the specified page in unittests/html IF the browser is not already on that page.
  def uses_page page # only works with IE
    new_url = self.class.html_root + page
    browser.goto new_url unless browser.url == new_url
  end
  def browser
    return $browser if $browser && $browser.exists?
    $browser = Watir::Browser.new
  end
  def close_browser
    $browser.close if $browser.exists?
  end

  def assert_class element, klass
    assert_match(Regexp.new(klass, Regexp::IGNORECASE), element.class.to_s, "element class should be #{klass}; got #{element.class}")
  end

  @@filter = []
  class << self
    def filter
      @@filter
    end
    def filter= proc
      @@filter = proc
    end
    # Add a filter that excludes tests matching the provided block
    def filter_out &block
      @@filter << Proc.new do |test| 
        block.call(test) ? false : nil
      end
    end
    def filter_out_tests_tagged tag
      filter_out do |test|
        test.tagged? tag
      end
    end
  end
end

class Test::Unit::TestCase
  include Watir::UnitTest
  include Watir::Exception

  class << self
    def tags *names
      @tags ||= []
      @tags += names
    end
    def tag_method method_name, *tags
      self.method_tags[method_name.to_s] = tags    
    end
    def method_tags
      @method_tags ||= Hash.new []
    end
    def html_root
      return "file:///#{File.expand_path @html_dir}/" if @html_dir
      $htmlRoot
    end
    def location path
      @html_dir = File.join File.dirname(path), 'html'    
    end
  end
  
  def tagged? tag
    self.class.tags.include?(tag) ||
    self.class.method_tags[@method_name].include?(tag)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
commonwatir-3.0.0.rc3 unittests/setup/watir-unittest.rb
commonwatir-3.0.0.rc2 unittests/setup/watir-unittest.rb
commonwatir-3.0.0.rc1 unittests/setup/watir-unittest.rb
commonwatir-2.0.4 unittests/setup/watir-unittest.rb
commonwatir-2.0.3 unittests/setup/watir-unittest.rb