1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Provide the ability to handle multiple cached initial values

This commit is contained in:
Thomas Walpole 2019-01-08 15:51:05 -08:00
parent 2ffbb3c6a5
commit ac82714b8c
10 changed files with 22 additions and 28 deletions

View file

@ -3,12 +3,12 @@
module Capybara
module Driver
class Node
attr_reader :driver, :native, :initial_visibility
attr_reader :driver, :native, :initial_cache
def initialize(driver, native, initial_visibility = nil)
def initialize(driver, native, initial_cache = {})
@driver = driver
@native = native
@initial_visibility = initial_visibility
@initial_cache = initial_cache
end
def all_text

View file

@ -105,7 +105,7 @@ module Capybara
# @api private
def find_xpath(xpath, **options)
if base.method(:find_css).arity != 1
if base.method(:find_xpath).arity != 1
base.find_xpath(xpath, **options)
else
base.find_xpath(xpath)

View file

@ -465,12 +465,9 @@ module Capybara
%(Obsolete #<Capybara::Node::Element>)
end
def initial_visibility
if base.respond_to? :initial_visibility
base.initial_visibility
else
nil
end
# @api private
def initial_cache
base.respond_to?(:initial_cache) ? base.initial_cache : {}
end
STYLE_SCRIPT = <<~JS

View file

@ -178,8 +178,9 @@ module Capybara
Capybara.session_options
end
def initial_visibility
nil
# @api private
def initial_cache
{}
end
private

View file

@ -416,9 +416,9 @@ module Capybara
def matches_visible_filter?(node)
case visible
when :visible then
node.initial_visibility || (node.initial_visibility.nil? && node.visible?)
node.initial_cache[:visible] || (node.initial_cache[:visible].nil? && node.visible?)
when :hidden then
(node.initial_visibility == false) || (node.initial_visibility.nil? && !node.visible?)
(node.initial_cache[:visible] == false) || (node.initial_cache[:visbile].nil? && !node.visible?)
else true
end
end

View file

@ -346,8 +346,8 @@ private
browser
end
def build_node(native_node, initial_visibility = nil)
::Capybara::Selenium::Node.new(self, native_node, initial_visibility)
def build_node(native_node, initial_cache = {})
::Capybara::Selenium::Node.new(self, native_node, initial_cache)
end
def specialize_driver(sel_driver)

View file

@ -51,8 +51,8 @@ private
result['value']
end
def build_node(native_node, initial_visibility = nil)
::Capybara::Selenium::ChromeNode.new(self, native_node, initial_visibility)
def build_node(native_node, initial_cache = {})
::Capybara::Selenium::ChromeNode.new(self, native_node, initial_cache)
end
def bridge

View file

@ -44,7 +44,7 @@ module Capybara::Selenium::Driver::FirefoxDriver
private
def build_node(native_node, initial_visibility = nil)
::Capybara::Selenium::FirefoxNode.new(self, native_node, initial_visibility)
def build_node(native_node, initial_cache = {})
::Capybara::Selenium::FirefoxNode.new(self, native_node, initial_cache)
end
end

View file

@ -16,12 +16,8 @@ module Capybara
def find_by(format, selector, uses_visibility:, texts:)
els = find_context.find_elements(format, selector)
els = filter_by_text(els, texts) if (els.size > 1) && !texts.empty?
visibilities = if uses_visibility && els.size > 1
element_visibilities(els)
else
[]
end
els.map.with_index { |el, idx| build_node(el, visibilities[idx]) }
visibilities = uses_visibility && els.size > 1 ? element_visibilities(els) : []
els.map.with_index { |el, idx| build_node(el, visible: visibilities[idx]) }
end
def element_visibilities(elements)

View file

@ -349,8 +349,8 @@ private
native
end
def build_node(native_node, initial_visibility = nil)
self.class.new(driver, native_node, initial_visibility)
def build_node(native_node, initial_cache = {})
self.class.new(driver, native_node, initial_cache)
end
GET_XPATH_SCRIPT = <<~'JS'