Sha256: 7592a1c8b8ed20a9542290867f0415fc664a2ae69651220cd50ba993ffa87118

Contents?: true

Size: 1.36 KB

Versions: 22

Compression:

Stored size: 1.36 KB

Contents

require 'active_support/ordered_hash'

module LocatorSpecHelper
  def browser
    @browser ||= double(Watir::Browser, wd: driver)
  end

  def driver
    @driver ||= double(Selenium::WebDriver::Driver)
  end

  def locator(selector, attrs)
    attrs ||= Watir::HTMLElement.attributes
    element_validator = Watir::Locators::Element::Validator.new
    selector_builder = Watir::Locators::Element::SelectorBuilder.new(driver, selector, attrs)
    Watir::Locators::Element::Locator.new(browser, selector, selector_builder, element_validator)
  end

  def expect_one(*args)
    expect(driver).to receive(:find_element).with(*args)
  end

  def expect_all(*args)
    expect(driver).to 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 = double(Watir::Element, opts)

    attrs.each do |key, value|
      allow(el).to receive(: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

22 entries across 22 versions & 2 rubygems

Version Path
watir-6.4.3 spec/locator_spec_helper.rb
watir-6.4.2 spec/locator_spec_helper.rb
watir-6.4.1 spec/locator_spec_helper.rb
watir-6.4.0 spec/locator_spec_helper.rb
watir-6.4.0.rc2 spec/locator_spec_helper.rb
watir-6.4.0.rc1 spec/locator_spec_helper.rb
watir-6.3.0 spec/locator_spec_helper.rb
watir-6.2.1 spec/locator_spec_helper.rb
watir-6.2.0 spec/locator_spec_helper.rb
watir-6.1.0 spec/locator_spec_helper.rb
watir-6.0.3 spec/locator_spec_helper.rb
watir-6.0.2 spec/locator_spec_helper.rb
watir-6.0.1 spec/locator_spec_helper.rb
watir-webdriver-0.9.9 spec/locator_spec_helper.rb
watir-6.0.0 spec/locator_spec_helper.rb
watir-6.0.0.beta5 spec/locator_spec_helper.rb
watir-6.0.0.beta4 spec/locator_spec_helper.rb
watir-6.0.0.beta3 spec/locator_spec_helper.rb
watir-6.0.0.beta2 spec/locator_spec_helper.rb
watir-6.0.0.beta1 spec/locator_spec_helper.rb