mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Document Capybara::Node::Simple
This commit is contained in:
parent
d223d542f7
commit
77eb69260a
1 changed files with 45 additions and 0 deletions
|
@ -1,5 +1,16 @@
|
|||
module Capybara
|
||||
module Node
|
||||
|
||||
##
|
||||
#
|
||||
# A {Capybara::Node::Simple} is a simpler version of {Capybara::Node::Base} which
|
||||
# includes only {Capybara::Node::Finders} and {Capybara::Node::Matchers} and does
|
||||
# not include {Capybara::Node::Actions}. This type of node is returned when
|
||||
# using {Capybara.string}.
|
||||
#
|
||||
# It is useful in that it does not require a session, an application or a driver,
|
||||
# but can still use Capybara's finders and matchers on any string that contains HTML.
|
||||
#
|
||||
class Simple
|
||||
include Capybara::Node::Finders
|
||||
include Capybara::Node::Matchers
|
||||
|
@ -11,10 +22,23 @@ module Capybara
|
|||
@native = native
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# @return [String] The text of the element
|
||||
#
|
||||
def text
|
||||
native.text
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Retrieve the given attribute
|
||||
#
|
||||
# element[:title] # => HTML title attribute
|
||||
#
|
||||
# @param [Symbol] attribute The attribute to retrieve
|
||||
# @return [String] The value of the attribute
|
||||
#
|
||||
def [](name)
|
||||
attr_name = name.to_s
|
||||
if attr_name == 'value'
|
||||
|
@ -26,14 +50,28 @@ module Capybara
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# @return [String] The tag name of the element
|
||||
#
|
||||
def tag_name
|
||||
native.node_name
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# An XPath expression describing where on the page the element can be found
|
||||
#
|
||||
# @return [String] An XPath expression
|
||||
#
|
||||
def path
|
||||
native.path
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# @return [String] The value of the form element
|
||||
#
|
||||
def value
|
||||
if tag_name == 'textarea'
|
||||
native.content
|
||||
|
@ -49,6 +87,13 @@ module Capybara
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Whether or not the element is visible. Does not support CSS, so
|
||||
# the result may be inaccurate.
|
||||
#
|
||||
# @return [Boolean] Whether the element is visible
|
||||
#
|
||||
def visible?
|
||||
native.xpath("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none')]").size == 0
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue