2016-03-08 00:52:19 +00:00
|
|
|
# frozen_string_literal: true
|
2015-01-26 22:50:59 +00:00
|
|
|
require 'capybara/selector/filter_set'
|
2016-03-28 18:58:01 +00:00
|
|
|
|
2010-08-27 18:37:39 +00:00
|
|
|
module Capybara
|
|
|
|
class Selector
|
2013-03-08 13:18:56 +00:00
|
|
|
|
2015-01-26 22:50:59 +00:00
|
|
|
attr_reader :name, :format
|
2011-02-10 15:59:26 +00:00
|
|
|
|
2010-08-27 18:37:39 +00:00
|
|
|
class << self
|
|
|
|
def all
|
|
|
|
@selectors ||= {}
|
|
|
|
end
|
|
|
|
|
2013-02-18 22:41:44 +00:00
|
|
|
def add(name, &block)
|
|
|
|
all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block)
|
2010-08-27 18:37:39 +00:00
|
|
|
end
|
|
|
|
|
2016-01-07 01:11:00 +00:00
|
|
|
def update(name, &block)
|
|
|
|
all[name.to_sym].instance_eval(&block)
|
|
|
|
end
|
|
|
|
|
2010-08-27 18:37:39 +00:00
|
|
|
def remove(name)
|
|
|
|
all.delete(name.to_sym)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-18 22:41:44 +00:00
|
|
|
def initialize(name, &block)
|
2010-08-27 18:37:39 +00:00
|
|
|
@name = name
|
2015-01-26 22:50:59 +00:00
|
|
|
@filter_set = FilterSet.add(name){}
|
2012-01-08 13:50:41 +00:00
|
|
|
@match = nil
|
2012-12-02 06:13:37 +00:00
|
|
|
@label = nil
|
2012-01-08 13:50:55 +00:00
|
|
|
@failure_message = nil
|
2014-07-02 18:17:53 +00:00
|
|
|
@description = nil
|
2016-04-06 19:42:02 +00:00
|
|
|
@format = nil
|
|
|
|
@expression = nil
|
2010-10-22 11:29:08 +00:00
|
|
|
instance_eval(&block)
|
|
|
|
end
|
|
|
|
|
2015-01-26 22:50:59 +00:00
|
|
|
def custom_filters
|
|
|
|
@filter_set.filters
|
|
|
|
end
|
|
|
|
|
2010-10-22 11:29:08 +00:00
|
|
|
def xpath(&block)
|
2016-04-06 19:42:02 +00:00
|
|
|
@format, @expression = :xpath, block if block
|
|
|
|
format == :xpath ? @expression : nil
|
2010-10-22 11:29:08 +00:00
|
|
|
end
|
|
|
|
|
2011-09-29 20:04:51 +00:00
|
|
|
def css(&block)
|
2016-04-06 19:42:02 +00:00
|
|
|
@format, @expression = :css, block if block
|
|
|
|
format == :css ? @expression : nil
|
2011-09-29 20:04:51 +00:00
|
|
|
end
|
|
|
|
|
2010-10-22 11:29:08 +00:00
|
|
|
def match(&block)
|
|
|
|
@match = block if block
|
|
|
|
@match
|
2010-08-27 18:37:39 +00:00
|
|
|
end
|
|
|
|
|
2012-06-08 13:53:25 +00:00
|
|
|
def label(label=nil)
|
|
|
|
@label = label if label
|
|
|
|
@label
|
2011-02-04 15:16:46 +00:00
|
|
|
end
|
|
|
|
|
2014-07-02 18:17:53 +00:00
|
|
|
def description(options={})
|
2015-01-26 22:50:59 +00:00
|
|
|
@filter_set.description(options)
|
2014-07-02 18:17:53 +00:00
|
|
|
end
|
|
|
|
|
2012-01-03 18:33:39 +00:00
|
|
|
def call(locator)
|
2016-04-06 19:42:02 +00:00
|
|
|
if format
|
|
|
|
@expression.call(locator)
|
2013-02-19 17:30:16 +00:00
|
|
|
else
|
2016-04-06 19:42:02 +00:00
|
|
|
warn "Selector has no format"
|
2013-02-19 17:30:16 +00:00
|
|
|
end
|
2010-08-27 18:37:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def match?(locator)
|
2010-10-22 11:29:08 +00:00
|
|
|
@match and @match.call(locator)
|
2010-08-27 18:37:39 +00:00
|
|
|
end
|
2012-01-02 11:46:04 +00:00
|
|
|
|
2013-03-08 13:18:56 +00:00
|
|
|
def filter(name, options={}, &block)
|
2015-01-26 22:50:59 +00:00
|
|
|
custom_filters[name] = Filter.new(name, block, options)
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
def filter_set(name, filters_to_use = nil)
|
2015-01-26 22:50:59 +00:00
|
|
|
f_set = FilterSet.all[name]
|
|
|
|
f_set.filters.each do | name, filter |
|
2016-04-27 05:44:48 +00:00
|
|
|
custom_filters[name] = filter if filters_to_use.nil? || filters_to_use.include?(name)
|
2015-01-26 22:50:59 +00:00
|
|
|
end
|
|
|
|
f_set.descriptions.each { |desc| @filter_set.describe &desc }
|
2012-01-02 11:46:04 +00:00
|
|
|
end
|
2014-07-02 18:17:53 +00:00
|
|
|
|
|
|
|
def describe &block
|
2015-01-26 22:50:59 +00:00
|
|
|
@filter_set.describe &block
|
2014-07-02 18:17:53 +00:00
|
|
|
end
|
2016-03-24 18:18:12 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def locate_field(xpath, locator)
|
|
|
|
locate_field = xpath[XPath.attr(:id).equals(locator) |
|
|
|
|
XPath.attr(:name).equals(locator) |
|
|
|
|
XPath.attr(:placeholder).equals(locator) |
|
|
|
|
XPath.attr(:id).equals(XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for))]
|
|
|
|
locate_field += XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(xpath)
|
|
|
|
locate_field
|
|
|
|
end
|
2010-08-27 18:37:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-22 11:29:08 +00:00
|
|
|
Capybara.add_selector(:xpath) do
|
2011-09-05 16:14:10 +00:00
|
|
|
xpath { |xpath| xpath }
|
2010-10-22 11:29:08 +00:00
|
|
|
end
|
|
|
|
|
2013-02-18 22:41:44 +00:00
|
|
|
Capybara.add_selector(:css) do
|
2011-09-29 20:17:32 +00:00
|
|
|
css { |css| css }
|
2010-10-22 11:29:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:id) do
|
2011-09-05 16:14:10 +00:00
|
|
|
xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
|
2010-10-22 11:29:08 +00:00
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
Capybara::Selector::FilterSet.add(:_field) do
|
|
|
|
filter(:id) { |node, id| node['id'] == id }
|
|
|
|
filter(:name) { |node, name| node['name'] == name }
|
|
|
|
filter(:placeholder) { |node, placeholder| node['placeholder'] == placeholder }
|
|
|
|
filter(:checked, boolean: true) { |node, value| not(value ^ node.checked?) }
|
|
|
|
filter(:unchecked, boolean: true) { |node, value| (value ^ node.checked?) }
|
|
|
|
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
2016-06-11 19:09:23 +00:00
|
|
|
filter(:multiple, boolean: true) { |node, value| !(value ^ node.multiple?) }
|
2016-04-27 05:44:48 +00:00
|
|
|
|
|
|
|
describe do |options|
|
|
|
|
desc, states = String.new, []
|
|
|
|
[:id, :name, :placeholder].each do |opt|
|
|
|
|
desc << " with #{opt.to_s} #{options[opt]}" if options.has_key?(opt)
|
|
|
|
end
|
|
|
|
states << 'checked' if options[:checked] || (options[:unchecked] === false)
|
|
|
|
states << 'not checked' if options[:unchecked] || (options[:checked] === false)
|
|
|
|
states << 'disabled' if options[:disabled] == true
|
|
|
|
desc << " that is #{states.join(' and ')}" unless states.empty?
|
|
|
|
desc << " with the multiple attribute" if options[:multiple] == true
|
|
|
|
desc << " without the multiple attribute" if options[:multiple] === false
|
|
|
|
desc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-27 02:16:15 +00:00
|
|
|
Capybara.add_selector(:field) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:input, :textarea, :select)[~XPath.attr(:type).one_of('submit', 'image', 'hidden')]
|
|
|
|
xpath = locate_field(xpath, locator.to_s) unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
2016-04-26 15:51:22 +00:00
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter_set(:_field)
|
2016-04-26 15:51:22 +00:00
|
|
|
|
2016-06-11 19:09:23 +00:00
|
|
|
filter(:readonly, boolean: true) { |node, value| not(value ^ node.readonly?) }
|
2013-09-25 13:07:02 +00:00
|
|
|
filter(:with) { |node, with| node.value == with.to_s }
|
2013-03-07 17:59:16 +00:00
|
|
|
filter(:type) do |node, type|
|
|
|
|
if ['textarea', 'select'].include?(type)
|
|
|
|
node.tag_name == type
|
|
|
|
else
|
|
|
|
node[:type] == type
|
|
|
|
end
|
|
|
|
end
|
2014-07-02 18:17:53 +00:00
|
|
|
describe do |options|
|
2016-03-01 21:53:19 +00:00
|
|
|
desc, states = String.new, []
|
2014-07-02 18:17:53 +00:00
|
|
|
desc << " of type #{options[:type].inspect}" if options[:type]
|
|
|
|
desc << " with value #{options[:with].to_s.inspect}" if options.has_key?(:with)
|
|
|
|
desc
|
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
2011-08-27 21:57:12 +00:00
|
|
|
Capybara.add_selector(:fieldset) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:fieldset)
|
|
|
|
xpath = xpath[XPath.attr(:id).equals(locator.to_s) | XPath.child(:legend)[XPath.string.n.is(locator.to_s)]] unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:link) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:a)[XPath.attr(:href)]
|
|
|
|
unless locator.nil?
|
|
|
|
locator = locator.to_s
|
|
|
|
xpath = xpath[XPath.attr(:id).equals(locator) |
|
|
|
|
XPath.string.n.is(locator) |
|
|
|
|
XPath.attr(:title).is(locator) |
|
|
|
|
XPath.descendant(:img)[XPath.attr(:alt).is(locator)]]
|
|
|
|
end
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
2015-08-25 21:25:42 +00:00
|
|
|
filter(:href) do |node, href|
|
2015-04-28 00:33:39 +00:00
|
|
|
if href.is_a? Regexp
|
|
|
|
node[:href].match href
|
|
|
|
else
|
|
|
|
node.first(:xpath, XPath.axis(:self)[XPath.attr(:href).equals(href.to_s)], minimum: 0)
|
|
|
|
end
|
2012-01-03 08:43:11 +00:00
|
|
|
end
|
2016-03-24 18:18:12 +00:00
|
|
|
|
2014-07-02 18:17:53 +00:00
|
|
|
describe { |options| " with href #{options[:href].inspect}" if options[:href] }
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:button) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')]
|
|
|
|
btn_xpath = XPath.descendant(:button)
|
|
|
|
image_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).equals('image')]
|
|
|
|
|
|
|
|
unless locator.nil?
|
|
|
|
locator = locator.to_s
|
|
|
|
input_btn_xpath = input_btn_xpath[XPath.attr(:id).equals(locator) | XPath.attr(:value).is(locator) | XPath.attr(:title).is(locator)]
|
|
|
|
btn_xpath = btn_xpath[XPath.attr(:id).equals(locator) | XPath.attr(:value).is(locator) | XPath.string.n.is(locator) | XPath.attr(:title).is(locator)]
|
|
|
|
image_btn_xpath = image_btn_xpath[XPath.attr(:alt).is(locator)]
|
|
|
|
end
|
|
|
|
|
|
|
|
input_btn_xpath + btn_xpath + image_btn_xpath
|
|
|
|
end
|
|
|
|
|
2015-09-19 18:42:45 +00:00
|
|
|
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
|
2016-03-24 18:18:12 +00:00
|
|
|
|
2015-09-19 03:22:19 +00:00
|
|
|
describe { |options| " that is disabled" if options[:disabled] == true }
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
2016-03-24 18:18:12 +00:00
|
|
|
Capybara.add_selector(:link_or_button) do
|
|
|
|
label "link or button"
|
|
|
|
xpath do |locator|
|
|
|
|
self.class.all.values_at(:link, :button).map {|selector| selector.xpath.call(locator)}.reduce(:+)
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| node.tag_name == "a" or not(value ^ node.disabled?) }
|
2016-03-24 18:18:12 +00:00
|
|
|
|
|
|
|
describe { |options| " that is disabled" if options[:disabled] }
|
|
|
|
end
|
|
|
|
|
2011-08-27 02:16:15 +00:00
|
|
|
Capybara.add_selector(:fillable_field) do
|
2012-06-08 15:07:12 +00:00
|
|
|
label "field"
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:input, :textarea)[~XPath.attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
|
|
|
|
xpath = locate_field(xpath, locator.to_s) unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter_set(:_field, [:id, :name, :placeholder, :disabled, :multiple])
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:radio_button) do
|
2012-06-08 15:07:12 +00:00
|
|
|
label "radio button"
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:input)[XPath.attr(:type).equals('radio')]
|
|
|
|
xpath = locate_field(xpath, locator.to_s) unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter_set(:_field, [:id, :name, :checked, :unchecked, :disabled])
|
2016-04-26 15:51:22 +00:00
|
|
|
|
2013-10-20 17:59:07 +00:00
|
|
|
filter(:option) { |node, value| node.value == value.to_s }
|
2016-03-24 18:18:12 +00:00
|
|
|
|
2014-07-02 18:17:53 +00:00
|
|
|
describe do |options|
|
2016-04-27 05:44:48 +00:00
|
|
|
desc = String.new
|
2014-07-02 18:17:53 +00:00
|
|
|
desc << " with value #{options[:option].inspect}" if options[:option]
|
|
|
|
desc
|
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:checkbox) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:input)[XPath.attr(:type).equals('checkbox')]
|
|
|
|
xpath = locate_field(xpath, locator.to_s) unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter_set(:_field, [:id, :name, :checked, :unchecked, :disabled])
|
2016-04-26 15:51:22 +00:00
|
|
|
|
2013-10-20 17:59:07 +00:00
|
|
|
filter(:option) { |node, value| node.value == value.to_s }
|
2016-03-24 18:18:12 +00:00
|
|
|
|
2014-07-02 18:17:53 +00:00
|
|
|
describe do |options|
|
2016-04-27 05:44:48 +00:00
|
|
|
desc = String.new
|
2014-07-02 18:17:53 +00:00
|
|
|
desc << " with value #{options[:option].inspect}" if options[:option]
|
|
|
|
desc
|
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:select) do
|
2012-06-08 15:07:12 +00:00
|
|
|
label "select box"
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:select)
|
|
|
|
xpath = locate_field(xpath, locator.to_s) unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter_set(:_field, [:id, :name, :placeholder, :disabled, :multiple])
|
2016-04-26 15:51:22 +00:00
|
|
|
|
2012-03-16 03:14:47 +00:00
|
|
|
filter(:options) do |node, options|
|
2015-10-06 20:42:45 +00:00
|
|
|
if node.visible?
|
|
|
|
actual = node.all(:xpath, './/option').map { |option| option.text }
|
|
|
|
else
|
|
|
|
actual = node.all(:xpath, './/option', visible: false).map { |option| option.text(:all) }
|
|
|
|
end
|
2012-03-16 03:14:47 +00:00
|
|
|
options.sort == actual.sort
|
|
|
|
end
|
2015-10-06 20:42:45 +00:00
|
|
|
filter(:with_options) do |node, options|
|
|
|
|
finder_settings = { minimum: 0 }
|
|
|
|
if !node.visible?
|
|
|
|
finder_settings[:visible] = false
|
|
|
|
end
|
|
|
|
options.all? { |option| node.first(:option, option, finder_settings) }
|
|
|
|
end
|
2012-01-02 16:12:21 +00:00
|
|
|
filter(:selected) do |node, selected|
|
2015-10-06 20:42:45 +00:00
|
|
|
actual = node.all(:xpath, './/option', visible: false).select { |option| option.selected? }.map { |option| option.text(:all) }
|
2012-03-25 04:29:24 +00:00
|
|
|
[selected].flatten.sort == actual.sort
|
2012-01-02 16:12:21 +00:00
|
|
|
end
|
2016-03-24 18:18:12 +00:00
|
|
|
|
2014-07-02 18:17:53 +00:00
|
|
|
describe do |options|
|
2016-03-01 21:53:19 +00:00
|
|
|
desc = String.new
|
2014-07-02 18:17:53 +00:00
|
|
|
desc << " with options #{options[:options].inspect}" if options[:options]
|
|
|
|
desc << " with at least options #{options[:with_options].inspect}" if options[:with_options]
|
|
|
|
desc << " with #{options[:selected].inspect} selected" if options[:selected]
|
|
|
|
desc
|
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:option) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:option)
|
|
|
|
xpath = xpath[XPath.string.n.is(locator.to_s)] unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
2016-03-24 21:50:42 +00:00
|
|
|
|
|
|
|
filter(:disabled, boolean: true) { |node, value| not(value ^ node.disabled?) }
|
|
|
|
filter(:selected, boolean: true) { |node, value| not(value ^ node.selected?) }
|
|
|
|
|
|
|
|
describe do |options|
|
|
|
|
desc = String.new
|
|
|
|
desc << " that is#{' not' unless options[:disabled]} disabled" if options.has_key?(:disabled)
|
|
|
|
desc << " that is#{' not' unless options[:selected]} selected" if options.has_key?(:selected)
|
|
|
|
desc
|
|
|
|
end
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.add_selector(:file_field) do
|
2012-06-08 15:07:12 +00:00
|
|
|
label "file field"
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:input)[XPath.attr(:type).equals('file')]
|
|
|
|
xpath = locate_field(xpath, locator.to_s) unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
2016-04-27 05:44:48 +00:00
|
|
|
filter_set(:_field, [:id, :name, :disabled, :multiple])
|
2011-08-27 02:16:15 +00:00
|
|
|
end
|
2011-08-27 21:54:55 +00:00
|
|
|
|
2016-04-06 17:59:11 +00:00
|
|
|
Capybara.add_selector(:label) do
|
|
|
|
label "label"
|
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:label)
|
|
|
|
xpath = xpath[XPath.string.n.is(locator.to_s) | XPath.attr(:id).equals(locator.to_s)] unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
|
|
|
|
filter(:for) do |node, field_or_value|
|
|
|
|
if field_or_value.is_a? Capybara::Node::Element
|
|
|
|
if field_or_value[:id] && (field_or_value[:id] == node[:for])
|
|
|
|
true
|
|
|
|
else
|
2016-04-06 21:20:23 +00:00
|
|
|
field_or_value.find_xpath('./ancestor::label[1]').include? node.base
|
2016-04-06 17:59:11 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
node[:for] == field_or_value.to_s
|
|
|
|
end
|
|
|
|
end
|
2016-04-21 21:25:14 +00:00
|
|
|
|
|
|
|
describe do |options|
|
|
|
|
desc = String.new
|
|
|
|
desc << " for #{options[:for]}" if options[:for]
|
2016-04-27 05:44:48 +00:00
|
|
|
desc
|
2016-04-21 21:25:14 +00:00
|
|
|
end
|
2016-04-06 17:59:11 +00:00
|
|
|
end
|
|
|
|
|
2011-08-27 21:54:55 +00:00
|
|
|
Capybara.add_selector(:table) do
|
2016-03-24 18:18:12 +00:00
|
|
|
xpath do |locator|
|
|
|
|
xpath = XPath.descendant(:table)
|
|
|
|
xpath = xpath[XPath.attr(:id).equals(locator.to_s) | XPath.descendant(:caption).is(locator.to_s)] unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
2011-08-27 21:54:55 +00:00
|
|
|
end
|
2016-07-18 20:17:22 +00:00
|
|
|
|
|
|
|
Capybara.add_selector(:frame) do
|
|
|
|
xpath do |locator|
|
2016-07-24 00:17:46 +00:00
|
|
|
xpath = XPath.descendant(:iframe) + XPath.descendant(:frame)
|
2016-07-18 20:17:22 +00:00
|
|
|
xpath = xpath[XPath.attr(:id).equals(locator.to_s) | XPath.attr(:name).equals(locator)] unless locator.nil?
|
|
|
|
xpath
|
|
|
|
end
|
|
|
|
end
|