Class: Capybara::Query
- Inherits:
-
Object
- Object
- Capybara::Query
- Defined in:
- lib/capybara/query.rb
Constant Summary collapse
- VALID_KEYS =
[:text, :visible, :between, :count, :maximum, :minimum, :exact, :match, :wait]
- VALID_MATCH =
[:first, :smart, :prefer_exact, :one]
Instance Attribute Summary collapse
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#find ⇒ Object
Returns the value of attribute find.
-
#locator ⇒ Object
Returns the value of attribute locator.
-
#negative ⇒ Object
Returns the value of attribute negative.
-
#options ⇒ Object
Returns the value of attribute options.
-
#selector ⇒ Object
Returns the value of attribute selector.
Instance Method Summary collapse
- #css ⇒ Object
- #description ⇒ Object
- #exact? ⇒ Boolean
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #label ⇒ Object
- #match ⇒ Object
- #matches_filters?(node) ⇒ Boolean
- #name ⇒ Object
- #visible ⇒ Object
- #wait ⇒ Object
- #xpath(exact = nil) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Query
Returns a new instance of Query.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/capybara/query.rb', line 8 def initialize(*args) @options = if args.last.is_a?(Hash) then args.pop.dup else {} end if args[0].is_a?(Symbol) @selector = Selector.all[args[0]] @locator = args[1] else @selector = Selector.all.values.find { |s| s.match?(args[0]) } @locator = args[0] end @selector ||= Selector.all[Capybara.default_selector] # for compatibility with Capybara 2.0 if Capybara. and @selector == Selector.all[:option] @options[:exact] = true end @expression = @selector.call(@locator) assert_valid_keys! end |
Instance Attribute Details
#expression ⇒ Object
Returns the value of attribute expression.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def expression @expression end |
#find ⇒ Object
Returns the value of attribute find.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def find @find end |
#locator ⇒ Object
Returns the value of attribute locator.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def locator @locator end |
#negative ⇒ Object
Returns the value of attribute negative.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def negative @negative end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def @options end |
#selector ⇒ Object
Returns the value of attribute selector.
3 4 5 |
# File 'lib/capybara/query.rb', line 3 def selector @selector end |
Instance Method Details
#css ⇒ Object
105 106 107 |
# File 'lib/capybara/query.rb', line 105 def css @expression end |
#description ⇒ Object
32 33 34 35 36 |
# File 'lib/capybara/query.rb', line 32 def description @description = "#{label} #{locator.inspect}" @description << " with text #{[:text].inspect}" if [:text] @description end |
#exact? ⇒ Boolean
80 81 82 83 84 85 86 |
# File 'lib/capybara/query.rb', line 80 def exact? if .has_key?(:exact) @options[:exact] else Capybara.exact end end |
#label ⇒ Object
30 |
# File 'lib/capybara/query.rb', line 30 def label; selector.label or selector.name; end |
#match ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/capybara/query.rb', line 88 def match if .has_key?(:match) @options[:match] else Capybara.match end end |
#matches_filters?(node) ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/capybara/query.rb', line 38 def matches_filters?(node) if [:text] regexp = [:text].is_a?(Regexp) ? [:text] : Regexp.escape([:text].to_s) return false if not node.text(visible).match(regexp) end case visible when :visible then return false unless node.visible? when :hidden then return false if node.visible? end selector.custom_filters.each do |name, filter| if .has_key?(name) return false unless filter.matches?(node, [name]) elsif filter.default? return false unless filter.matches?(node, filter.default) end end end |
#name ⇒ Object
29 |
# File 'lib/capybara/query.rb', line 29 def name; selector.name; end |
#visible ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/capybara/query.rb', line 56 def visible if .has_key?(:visible) case @options[:visible] when true then :visible when false then :all else @options[:visible] end else if Capybara.ignore_hidden_elements :visible else :all end end end |
#wait ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/capybara/query.rb', line 72 def wait if .has_key?(:wait) @options[:wait] or 0 else Capybara.default_wait_time end end |
#xpath(exact = nil) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/capybara/query.rb', line 96 def xpath(exact=nil) exact = self.exact? if exact == nil if @expression.respond_to?(:to_xpath) and exact @expression.to_xpath(:exact) else @expression.to_s end end |