pincers 0.4.2 → 0.4.3

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: 9c0078909c37a17fd576c2406f34e2ac442ebd9e
4
- data.tar.gz: 9eee825c40a7046971993756cc3470e1c3a0c801
3
+ metadata.gz: afcbc879c147d169e6aad79cf754a63087d4c19d
4
+ data.tar.gz: cb45e178c172df008ad21d599b43eb9d19d876dc
5
5
  SHA512:
6
- metadata.gz: 168d81dd0e6e107a72272d8363ed8d0907af0e44b65af11c371a4f1dceec9cf8bf251479b71634c13fa788a26a640666f5cd094d7afaa7b3a31ee6145c8a6a14
7
- data.tar.gz: 9cb9cca61f9c194623a3bc04ecc96cb01e7f4827befd35c813a266b06efda8234a258cb0c65ec69834b4f70f31e68fa00d9f4778b06afa5941748014ff2b5990
6
+ metadata.gz: 7fb0a694e3a07b9dbe26f9d75c791c954967111b036f1d39442ebbad690fa972622872482278127a3b81411edbc14f12e18b910458efb9bfee6f693eef6e95e8
7
+ data.tar.gz: bef7aad58f7ed7dc93f109fcda0f06c3e43bb1423bf4b1f91b1b72661e4da943f091d9c419b0cbfca0e4fd3273d9264f8800b2b61d5920cbbb1abf59b24ae46d
@@ -2,6 +2,7 @@ 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'
5
6
 
6
7
  module Pincers::Core
7
8
  class SearchContext
@@ -74,6 +75,7 @@ module Pincers::Core
74
75
  end
75
76
 
76
77
  def first
78
+ wait?(:present) unless frozen? or advanced_mode?
77
79
  if element.nil? then nil else wrap_siblings [element] end
78
80
  end
79
81
 
@@ -92,7 +94,15 @@ module Pincers::Core
92
94
  end
93
95
  end
94
96
 
95
- def xpath(_selector, _options={})
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
106
  wrap_errors do
97
107
  query = Pincers::Support::Query.new backend, :xpath, _selector, _options[:limit]
98
108
  wrap_childs query
@@ -0,0 +1,50 @@
1
+ module Pincers::Support
2
+ class XPathBuilder
3
+
4
+ def initialize
5
+ @parts = []
6
+ end
7
+
8
+ def expression
9
+ "//*[#{@parts.join(' and ')}]"
10
+ end
11
+
12
+ def by_tag(_name)
13
+ add "name()='#{_name.downcase}'"
14
+ self
15
+ end
16
+
17
+ def by_contents(_contents, _options={})
18
+ # TODO: more options, lowercase support?
19
+ # xpath("//*[text()='#{_contents}'] | //*[@value='#{_contents}']", _options)
20
+ add "(contains(text(), '#{_contents}') or contains(@value, '#{_contents}'))"
21
+ end
22
+
23
+ def by_class(_class, _options={})
24
+ add "contains(concat(' ', @class, ' '), ' #{_class} ')"
25
+ end
26
+
27
+ def by_attribute(_attribute, _options={})
28
+ add(if _options.key? :equals
29
+ "@#{_attribute}='#{_options.delete(:equals)}'"
30
+ elsif _options.key? :starts_with
31
+ "starts-with(@#{_attribute}, '#{_options.delete(:starts_with)}')"
32
+ elsif _options.key? :ends_with
33
+ ends_with = _options.delete(:ends_with)
34
+ "substring(@#{_attribute}, string-length(@#{_attribute}) - string-length('#{ends_with}') + 1)='#{ends_with}'"
35
+ elsif _options.key? :contains
36
+ "contains(@#{_attribute}, '#{_options.delete(:contains)}')"
37
+ else
38
+ "#{_attribute}"
39
+ end)
40
+ end
41
+
42
+ private
43
+
44
+ def add(_condition)
45
+ @parts << _condition
46
+ self
47
+ end
48
+
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Pincers
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pincers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -213,6 +213,7 @@ executables: []
213
213
  extensions: []
214
214
  extra_rdoc_files: []
215
215
  files:
216
+ - lib/pincers.rb
216
217
  - lib/pincers/backend/base.rb
217
218
  - lib/pincers/backend/nokogiri.rb
218
219
  - lib/pincers/backend/webdriver.rb
@@ -229,8 +230,8 @@ files:
229
230
  - lib/pincers/support/configuration.rb
230
231
  - lib/pincers/support/cookie_jar.rb
231
232
  - lib/pincers/support/query.rb
233
+ - lib/pincers/support/xpath_builder.rb
232
234
  - lib/pincers/version.rb
233
- - lib/pincers.rb
234
235
  homepage: https://github.com/platanus/pincers
235
236
  licenses:
236
237
  - MIT
@@ -251,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
252
  version: '0'
252
253
  requirements: []
253
254
  rubyforge_project:
254
- rubygems_version: 2.0.14
255
+ rubygems_version: 2.4.8
255
256
  signing_key:
256
257
  specification_version: 4
257
258
  summary: Web automation framework with multiple backend support