pincers 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afcbc879c147d169e6aad79cf754a63087d4c19d
4
- data.tar.gz: cb45e178c172df008ad21d599b43eb9d19d876dc
3
+ metadata.gz: e16b32dabf298054ed5e1d29154cba02910c1820
4
+ data.tar.gz: 2b4a3b62cdaeca0b9339abc309eefff40a6d7aaa
5
5
  SHA512:
6
- metadata.gz: 7fb0a694e3a07b9dbe26f9d75c791c954967111b036f1d39442ebbad690fa972622872482278127a3b81411edbc14f12e18b910458efb9bfee6f693eef6e95e8
7
- data.tar.gz: bef7aad58f7ed7dc93f109fcda0f06c3e43bb1423bf4b1f91b1b72661e4da943f091d9c419b0cbfca0e4fd3273d9264f8800b2b61d5920cbbb1abf59b24ae46d
6
+ metadata.gz: d13a6b8b6c4cfadc7a995654c2a0f745861c4aadbee9e725d452cb895d2d43ec0141027245a3d39bb0e5d8ad3ba423d7e53c42846e97f52836e43949e18aa77d
7
+ data.tar.gz: a7adb7894c79e32000cb61d8d54d20c803886d4aa3be30b226e3d526525483e529ea22442250fe4cefca2ed5d90489a1d60fffcfb5486e78fee658d407f3f3ed
@@ -2,7 +2,6 @@ require 'pincers/extension/queries'
2
2
  require 'pincers/extension/actions'
3
3
  require 'pincers/extension/labs'
4
4
  require 'pincers/support/query'
5
- require 'pincers/support/xpath_builder'
6
5
 
7
6
  module Pincers::Core
8
7
  class SearchContext
@@ -94,15 +93,7 @@ module Pincers::Core
94
93
  end
95
94
  end
96
95
 
97
- def xpath(_selector=nil, _options={}, &_block)
98
- _options = _selector if _selector.is_a? Hash
99
-
100
- unless _block.nil?
101
- builder = Pincers::Support::XPathBuilder.new
102
- _block.call builder
103
- _selector = builder.expression
104
- end
105
-
96
+ def xpath(_selector, _options={})
106
97
  wrap_errors do
107
98
  query = Pincers::Support::Query.new backend, :xpath, _selector, _options[:limit]
108
99
  wrap_childs query
@@ -1,8 +1,21 @@
1
+ require 'pincers/support/xpath_builder'
2
+
1
3
  module Pincers::Extension
2
4
  module Queries
3
5
 
4
6
  TEXT_INPUTS = ['text', 'email', 'number', 'email', 'color', 'password', 'search', 'tel', 'url']
5
7
 
8
+ def search(_options={}, &_block)
9
+ query_options = {
10
+ limit: _options.delete(:limit)
11
+ }
12
+
13
+ builder = Pincers::Support::XPathBuilder.new _options
14
+ _block.call builder unless _block.nil?
15
+
16
+ xpath builder.expression, query_options
17
+ end
18
+
6
19
  def value
7
20
  case input_mode
8
21
  when :checkbox, :radio
@@ -1,12 +1,22 @@
1
1
  module Pincers::Support
2
2
  class XPathBuilder
3
3
 
4
- def initialize
4
+ def initialize(_options={})
5
5
  @parts = []
6
+ by_tag _options.delete(:tag) if _options.key? :tag
7
+ by_content _options.delete(:content) if _options.key? :content
8
+
9
+ if _options.key? :class
10
+ _options.delete(:class).split(' ').each { |c| by_class c }
11
+ end
12
+
13
+ _options.each do |key, value|
14
+ by_attribute key, contains: value
15
+ end
6
16
  end
7
17
 
8
18
  def expression
9
- "//*[#{@parts.join(' and ')}]"
19
+ ".//*[#{@parts.join(' and ')}]"
10
20
  end
11
21
 
12
22
  def by_tag(_name)
@@ -14,7 +24,7 @@ module Pincers::Support
14
24
  self
15
25
  end
16
26
 
17
- def by_contents(_contents, _options={})
27
+ def by_content(_contents, _options={})
18
28
  # TODO: more options, lowercase support?
19
29
  # xpath("//*[text()='#{_contents}'] | //*[@value='#{_contents}']", _options)
20
30
  add "(contains(text(), '#{_contents}') or contains(@value, '#{_contents}'))"
@@ -1,3 +1,3 @@
1
1
  module Pincers
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pincers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas