Sha256: 471fc1a2d341003e6c9b54609540aa190f7e7ba038baf6a7c24319574d184770

Contents?: true

Size: 1.07 KB

Versions: 49

Compression:

Stored size: 1.07 KB

Contents

require 'active_support/ordered_hash'

module LocatorSpecHelper
  def driver
    @driver ||= mock(Selenium::WebDriver::Driver)
  end

  def locator(selector, attrs)
    attrs ||= Watir::HTMLElement.attributes
    Watir::ElementLocator.new(driver, selector, attrs)
  end

  def expect_one(*args)
    driver.should_receive(:find_element).with(*args)
  end

  def expect_all(*args)
    driver.should_receive(:find_elements).with(*args)
  end

  def locate_one(selector, attrs = nil)
    locator(ordered_hash(selector), attrs).locate
  end

  def locate_all(selector, attrs = nil)
    locator(ordered_hash(selector), attrs).locate_all
  end

  def element(opts = {})
    attrs = opts.delete(:attributes)
    el = mock(Watir::Element, opts)

    attrs.each do |key, value|
      el.stub!(:attribute).with(key).and_return(value)
    end if attrs

    el
  end

  def ordered_hash(selector)
    case selector
    when Hash
      selector
    when Array
      ActiveSupport::OrderedHash[*selector]
    else
      raise ArgumentError, "couldn't create hash for #{selector.inspect}"
    end
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
watir-webdriver-0.6.4 spec/locator_spec_helper.rb
watir-webdriver-0.6.3 spec/locator_spec_helper.rb
watir-webdriver-0.6.2 spec/locator_spec_helper.rb
watir-webdriver-0.6.1 spec/locator_spec_helper.rb
watir-webdriver-0.6.0 spec/locator_spec_helper.rb
watir-webdriver-0.5.8 spec/locator_spec_helper.rb
watir-webdriver-0.5.7 spec/locator_spec_helper.rb
watir-webdriver-0.5.6 spec/locator_spec_helper.rb
watir-webdriver-0.5.5 spec/locator_spec_helper.rb
watir-webdriver-0.5.4 spec/locator_spec_helper.rb
watir-webdriver-0.5.3 spec/locator_spec_helper.rb
watir-webdriver-0.5.2 spec/locator_spec_helper.rb
watir-webdriver-0.5.1 spec/locator_spec_helper.rb
watir-webdriver-0.5.0 spec/locator_spec_helper.rb
watir-webdriver-0.4.1 spec/locator_spec_helper.rb
watir-webdriver-0.4.0 spec/locator_spec_helper.rb
watir-webdriver-0.3.9 spec/locator_spec_helper.rb
watir-webdriver-0.3.8 spec/locator_spec_helper.rb
watir-webdriver-0.3.7 spec/locator_spec_helper.rb
watir-webdriver-0.3.6 spec/locator_spec_helper.rb