Add boolean methods for some boolean attribute selectors to handle marionette differences

This commit is contained in:
Thomas Walpole 2016-06-11 12:09:23 -07:00
parent 292e00735b
commit c08a186bda
5 changed files with 48 additions and 17 deletions

View File

@ -42,23 +42,23 @@ module Capybara
def click
raise NotImplementedError
end
def right_click
raise NotImplementedError
end
def double_click
raise NotImplementedError
end
def send_keys(*args)
raise NotImplementedError
end
def hover
raise NotImplementedError
end
def drag_to(element)
raise NotImplementedError
end
@ -83,6 +83,14 @@ module Capybara
raise NotImplementedError
end
def readonly?
!!self[:readonly]
end
def multiple?
!!self[:multiple]
end
def path
raise NotSupportedByDriverError, 'Capybara::Driver::Node#path'
end

View File

@ -282,6 +282,26 @@ module Capybara
synchronize { base.disabled? }
end
##
#
# Whether or not the element is readonly.
#
# @return [Boolean] Whether the element is readonly
#
def readonly?
synchronize { base.readonly? }
end
##
#
# Whether or not the element supports multiple results.
#
# @return [Boolean] Whether the element supports multiple results.
#
def multiple?
synchronize { base.multiple? }
end
##
#
# An XPath expression describing where on the page the element can be found

View File

@ -17,7 +17,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
end
def set(value)
if (Array === value) && !self[:multiple]
if (Array === value) && !multiple?
raise ArgumentError.new "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
end

View File

@ -124,7 +124,7 @@ Capybara::Selector::FilterSet.add(:_field) do
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?) }
filter(:multiple, boolean: true) { |node, value| !(value ^ node[:multiple]) }
filter(:multiple, boolean: true) { |node, value| !(value ^ node.multiple?) }
describe do |options|
desc, states = String.new, []
@ -150,7 +150,7 @@ Capybara.add_selector(:field) do
filter_set(:_field)
filter(:readonly, boolean: true) { |node, value| not(value ^ node[:readonly]) }
filter(:readonly, boolean: true) { |node, value| not(value ^ node.readonly?) }
filter(:with) { |node, with| node.value == with.to_s }
filter(:type) do |node, type|
if ['textarea', 'select'].include?(type)
@ -159,7 +159,6 @@ Capybara.add_selector(:field) do
node[:type] == type
end
end
# filter(:multiple, boolean: true) { |node, value| !(value ^ node[:multiple]) }
describe do |options|
desc, states = String.new, []
desc << " of type #{options[:type].inspect}" if options[:type]

View File

@ -17,7 +17,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
end
def value
if tag_name == "select" and self[:multiple] and not self[:multiple] == "false"
if tag_name == "select" and multiple?
native.find_elements(:xpath, ".//option").select { |n| n.selected? }.map { |n| n[:value] || n.text }
else
native[:value]
@ -38,7 +38,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
def set(value, options={})
tag_name = self.tag_name
type = self[:type]
if (Array === value) && !self[:multiple]
if (Array === value) && !multiple?
raise ArgumentError.new "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
end
if tag_name == 'input' and type == 'radio'
@ -131,12 +131,21 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
selected = native.selected?
selected and selected != "false"
end
alias :checked? :selected?
def disabled?
!native.enabled?
end
alias :checked? :selected?
def readonly?
readonly = self[:readonly]
readonly and readonly != "false"
end
def multiple?
multiple = self[:multiple]
multiple and multiple != "false"
end
def find_xpath(locator)
native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
@ -175,11 +184,6 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
end
private
def readonly?
readonly = self[:readonly]
readonly and readonly != "false"
end
# a reference to the select node if this is an option node
def select_node
find_xpath('./ancestor::select').first