Sha256: 77eafb96a673af6af652ba88213d15a0f78869f5d028d33a3e37e1e3e11fc6d6

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

class Capybara::Grid::Node < Capybara::Driver::Node
  def text
    native.text
  end

  def [](name)
    if name == :value
      value
    else
      native.attribute(name.to_s)
    end
  rescue Selenium::WebDriver::Error::WebDriverError
    nil
  end

  def value
    if tag_name == "select" and self[:multiple] and not self[:multiple] == "false"
      native.find_elements(:xpath, ".//option").select { |n| n.selected? }.map { |n| n.value || n.text }
    else
      native.value
    end
  end

  def set(value)
    if tag_name == 'input' and type == 'radio'
      click
    elsif tag_name == 'input' and type == 'checkbox'
      click if value ^ native.attribute('checked').to_s.eql?("true")
    elsif tag_name == 'textarea' or tag_name == 'input'
      resynchronize do
        native.clear
        native.send_keys(value.to_s)
      end
    end
  end

  def select_option
    resynchronize { native.select }
  end

  def unselect_option
    if select_node['multiple'] != 'multiple' and select_node['multiple'] != 'true'
      raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
    end
    resynchronize { native.toggle } if selected?
  end

  def click
    resynchronize { native.click }
  end

  def drag_to(element)
    resynchronize { native.drag_and_drop_on(element.native) }
  end

  def tag_name
    native.tag_name
  end

  def visible?
    displayed = native.displayed?
    displayed and displayed != "false"
  end

  def selected?
    selected = native.selected?
    selected and selected != "false"
  end

  alias :checked? :selected?

  def find(locator)
    native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
  end

private

  def resynchronize
    driver.resynchronize { yield }
  end

  # a reference to the select node if this is an option node
  def select_node
    find('./ancestor::select').first
  end

  def type
    self[:type]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grid-0.4.3 lib/grid/extensions/capybara/node.rb
grid-0.4.2 lib/grid/extensions/capybara/node.rb