class Object

Public Instance Methods

bases() click to toggle source
# File lib/capybara/spec/session/current_url_spec.rb, line 13
def bases
  @servers.map { |s| "http://#{s.host}:#{s.port}" }
end
cell_position(cell) click to toggle source
# File lib/capybara/selector/definition/table.rb, line 71
def cell_position(cell)
  cell.preceding_sibling(:td).count.plus(1)
end
combine_locators(locator, config:) click to toggle source
# File lib/capybara/selector/definition/button.rb, line 53
def combine_locators(locator, config:)
  [
    XPath.attr(:id).equals(locator),
    XPath.attr(:name).equals(locator),
    XPath.attr(:value).is(locator),
    XPath.attr(:title).is(locator),
    (XPath.attr(:id) == XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for)),
    (XPath.attr(:'aria-label').is(locator) if config.enable_aria_label),
    (XPath.attr(config.test_id) == locator if config.test_id)
  ].compact.inject(&:|)
end
labelable_elements() click to toggle source
# File lib/capybara/selector/definition/label.rb, line 59
def labelable_elements
  %i[button input keygen meter output progress select textarea]
end
labellable_elements() click to toggle source
# File lib/capybara/selector/definition/button.rb, line 65
def labellable_elements
  (XPath.self(:input) & XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')) | XPath.self(:button)
end
match_row(row, match_size: false) click to toggle source
# File lib/capybara/selector/definition/table.rb, line 75
def match_row(row, match_size: false)
  xp = XPath.descendant(:tr)[
    if row.is_a? Hash
      row_match_cells_to_headers(row)
    else
      XPath.descendant(:td)[row_match_ordered_cells(row)]
    end
  ]
  xp = xp[XPath.descendant(:td).count.equals(row.size)] if match_size
  xp
end
match_row_count(size) click to toggle source
# File lib/capybara/selector/definition/table.rb, line 87
def match_row_count(size)
  XPath.descendant(:tbody).descendant(:tr).count.equals(size) |
    (XPath.descendant(:tr).count.equals(size) & ~XPath.descendant(:tbody))
end
options_text(node, **opts, &filter_block) click to toggle source
# File lib/capybara/selector/definition/select.rb, line 74
def options_text(node, **opts, &filter_block)
  opts[:wait] = false
  opts[:visible] = false unless node.visible?
  node.all(:xpath, './/option', **opts, &filter_block).map do |o|
    o.text((:all if opts[:visible] == false))
  end
end
prev_col_position?(cell) click to toggle source
# File lib/capybara/selector/definition/table.rb, line 67
def prev_col_position?(cell)
  XPath.position.equals(cell_position(cell))
end
row_match_cells_to_headers(row) click to toggle source
# File lib/capybara/selector/definition/table.rb, line 92
def row_match_cells_to_headers(row)
  row.map do |header, cell|
    header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[XPath.string.n.is(header)]
    XPath.descendant(:td)[
      XPath.string.n.is(cell) & XPath.position.equals(header_xp.preceding_sibling.count.plus(1))
    ]
  end.reduce(:&)
end
row_match_ordered_cells(row) click to toggle source
# File lib/capybara/selector/definition/table.rb, line 101
def row_match_ordered_cells(row)
  row_conditions = row.map do |cell|
    XPath.self(:td)[XPath.string.n.is(cell)]
  end
  row_conditions.reverse.reduce do |cond, cell|
    cell[XPath.following_sibling[cond]]
  end
end
should_be_on(server_index, path = '/host', scheme = 'http') click to toggle source
# File lib/capybara/spec/session/current_url_spec.rb, line 17
def should_be_on(server_index, path = '/host', scheme = 'http')
  # Check that we are on /host on the given server
  s = @servers[server_index]

  expect(@session).to have_current_path("#{scheme}://#{s.host}:#{s.port}#{path}", url: true)

  expect(@session.current_url.chomp('?')).to eq("#{scheme}://#{s.host}:#{s.port}#{path}")
  expect(@session.current_host).to eq("#{scheme}://#{s.host}") # no port
  expect(@session.current_path).to eq(path.split('#')[0])
  # Server should agree with us
  expect(@session).to have_content("Current host is #{scheme}://#{s.host}:#{s.port}") if path == '/host'
end
to_hash() click to toggle source
# File lib/capybara/spec/session/has_text_spec.rb, line 118
def to_hash; { value: 'Other hash' } end
to_s() click to toggle source
# File lib/capybara/spec/session/has_text_spec.rb, line 117
def to_s; '42' end
win_size() click to toggle source
# File lib/capybara/spec/session/window/window_spec.rb, line 93
def win_size
  @session.evaluate_script('[window.outerWidth || window.innerWidth, window.outerHeight || window.innerHeight]')
end