site_prism 2.14 → 2.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b74604cbe9c1815149c4bce7c747d9087098ade
4
- data.tar.gz: 5043802657e6d0f88d6f52ea8790b49b8e634dd5
3
+ metadata.gz: f4e3fd2e00cf2bb78219d9f9fbeabd2f7508acc6
4
+ data.tar.gz: 49f28a586eead92eaf7be65e8471a713a9d07f49
5
5
  SHA512:
6
- metadata.gz: 4683666aa25142921dfab489841ef22eed10768978cd6c0ba69d768517a28cfcd7ef236fa5291c9a951836ea3bf3f762e2c25451ff5ad30940ec7db071c204cb
7
- data.tar.gz: 5ade19c3956fbf314b096831c72f9c0d9f572ab5995384d389cfd795ada012b4e63e3036ca612fafa3b78658bb037391bddc19f09a1e6fa97f27772901a0a1c1
6
+ metadata.gz: 054cfa56172cf001d9c3e3b131f9fb382fe901034bbf913831189a6b091e01f4ddc2e73af69c9c60ac5c7ad5fe32e1dc615eca04e84fe4a5aec398166c430b16
7
+ data.tar.gz: c539b113a2b70cb84467675346132599cc75512012860676ab21c53fd1b1e853d633809df6122d3bbaa0cc0295bc5ae2be5dc44626529799db25ac685c827ce0
data/README.md CHANGED
@@ -17,7 +17,7 @@ We have a brief set of setup docs [HERE](https://github.com/natritmeyer/site_pri
17
17
 
18
18
  ## Supported Rubies / Browsers
19
19
 
20
- SitePrism is built and tested to work on Ruby 2.1 - 2.5. There is also some limited support for Ruby 2.0.0.
20
+ SitePrism is built and tested to work on Ruby 2.2 - 2.5. There is also some limited support for the Ruby 2.1 series.
21
21
 
22
22
  SitePrism should run on all major browsers. The gem's integration tests are ran on the latest versions of Chrome and Firefox.
23
23
 
@@ -521,7 +521,7 @@ Another method added by calling `element` is the
521
521
  `wait_until_<element_name>_visible` method. Calling this method will
522
522
  cause the test to wait for Capybara's default wait time for the element
523
523
  to become visible (*not* the same as existence!). You can customise the
524
- wait time be supplying a number of seconds to wait. Using the above
524
+ wait time by supplying a number of seconds to wait. Using the above
525
525
  example:
526
526
 
527
527
  ```ruby
@@ -651,7 +651,7 @@ it wil return `false`. For example, with the following page:
651
651
 
652
652
  ```ruby
653
653
  class Friends < SitePrism::Page
654
- elements(:names, 'ul#names li a')
654
+ elements :names, 'ul#names li a'
655
655
  end
656
656
  ```
657
657
 
@@ -1733,6 +1733,18 @@ with this:
1733
1733
  @search_page.search_results
1734
1734
  ```
1735
1735
 
1736
+ Note that even with implicit waits on you can temporarily modify wait times in SitePrism to help work-around special circumstances.
1737
+
1738
+ ```rb
1739
+ # Option 1: using wait_for
1740
+ @search_page.wait_for_search_results(30) # will wait up to 30seconds
1741
+
1742
+ # Option 2: using Capybara directly
1743
+ Capybara.using_wait_time(30) do
1744
+ @search_page.subsection.search_results
1745
+ end
1746
+ ```
1747
+
1736
1748
  ## Raising Errors on wait_for
1737
1749
 
1738
1750
  By default, when using `wait_for_*` and `wait_for_no_*` methods, SitePrism will not raise
@@ -47,10 +47,9 @@ module SitePrism
47
47
  def all_expected_mappings_match?(expected_mappings, actual_mappings)
48
48
  expected_mappings.all? do |key, expected_value|
49
49
  actual_value = actual_mappings[key.to_s]
50
- case expected_value
51
- when Numeric
50
+ if expected_value.is_a?(Numeric)
52
51
  actual_value == expected_value.to_s
53
- when Regexp
52
+ elsif expected_value.is_a?(Regexp)
54
53
  actual_value.match(expected_value)
55
54
  else
56
55
  expected_value == actual_value
@@ -8,6 +8,10 @@ module SitePrism
8
8
 
9
9
  private
10
10
 
11
+ def max_wait_time
12
+ Capybara.default_max_wait_time
13
+ end
14
+
11
15
  def raise_if_block(obj, name, has_block)
12
16
  return unless has_block
13
17
 
@@ -28,6 +32,11 @@ module SitePrism
28
32
  "Timed out after #{timeout}s waiting for no #{obj.class}##{name}"
29
33
  end
30
34
 
35
+ # Sanitize method called before calling any SitePrism DSL method or
36
+ # meta-programmed method. This ensures that the Capybara query is correct.
37
+ #
38
+ # Accepts any combination of arguments sent at DSL definition or runtime
39
+ # and combines them in such a way that Capybara can operate with them.
31
40
  def merge_args(find_args, runtime_args, override_options = {})
32
41
  find_args = find_args.dup
33
42
  runtime_args = runtime_args.dup
@@ -35,64 +44,81 @@ module SitePrism
35
44
  options.merge!(find_args.pop) if find_args.last.is_a? Hash
36
45
  options.merge!(runtime_args.pop) if runtime_args.last.is_a? Hash
37
46
  options.merge!(override_options)
47
+ options[:wait] = false unless wait_required?(options)
48
+
49
+ return [*find_args, *runtime_args] if options.empty?
50
+
38
51
  [*find_args, *runtime_args, options]
39
52
  end
40
53
 
54
+ def wait_required?(options)
55
+ SitePrism.use_implicit_waits || options.key?(:wait)
56
+ end
57
+
58
+ # rubocop:disable Metrics/ModuleLength
41
59
  module ClassMethods
42
60
  attr_reader :mapped_items, :expected_items
43
61
 
44
- def element(element_name, *find_args)
45
- build(element_name, *find_args) do
46
- define_method(element_name.to_s) do |*runtime_args, &element_block|
47
- raise_if_block(self, element_name.to_s, !element_block.nil?)
48
- find_first(*merge_args(find_args, runtime_args))
62
+ def element(name, *find_args)
63
+ build(name, *find_args) do
64
+ define_method(name) do |*runtime_args, &element_block|
65
+ raise_if_block(self, name, !element_block.nil?)
66
+ _find(*merge_args(find_args, runtime_args))
49
67
  end
50
68
  end
51
69
  end
52
70
 
53
- def elements(collection_name, *find_args)
54
- build(collection_name, *find_args) do
55
- define_method(collection_name.to_s) do |*runtime_args, &element_block|
56
- raise_if_block(self, collection_name.to_s, !element_block.nil?)
57
- find_all(*merge_args(find_args, runtime_args))
71
+ def elements(name, *find_args)
72
+ build(name, *find_args) do
73
+ define_method(name) do |*runtime_args, &element_block|
74
+ raise_if_block(self, name, !element_block.nil?)
75
+ _all(*merge_args(find_args, runtime_args))
58
76
  end
59
77
  end
60
78
  end
61
- alias collection elements
79
+
80
+ def collection(name, *find_args)
81
+ warn 'Using collection is now deprecated and will be removed.'
82
+ warn 'Use elements DSL notation instead.'
83
+ elements(name, *find_args)
84
+ end
62
85
 
63
86
  def expected_elements(*elements)
64
87
  @expected_items = elements
65
88
  end
66
89
 
67
- def section(section_name, *args, &block)
90
+ def section(name, *args, &block)
68
91
  section_class, find_args = extract_section_options(args, &block)
69
- build(section_name, *find_args) do
70
- define_method section_name do |*runtime_args, &runtime_block|
71
- section_class.new self, find_first(*merge_args(find_args, runtime_args)), &runtime_block
92
+ build(name, *find_args) do
93
+ define_method(name) do |*runtime_args, &runtime_block|
94
+ section_element = _find(*merge_args(find_args, runtime_args))
95
+ section_class.new(self, section_element, &runtime_block)
72
96
  end
73
97
  end
74
98
  end
75
99
 
76
- def sections(section_collection_name, *args, &block)
100
+ def sections(name, *args, &block)
77
101
  section_class, find_args = extract_section_options(args, &block)
78
- build(section_collection_name, *find_args) do
79
- define_method(section_collection_name) do |*runtime_args, &element_block|
80
- raise_if_block(self, section_collection_name.to_s, !element_block.nil?)
81
- find_all(*merge_args(find_args, runtime_args)).map do |element|
102
+ build(name, *find_args) do
103
+ define_method(name) do |*runtime_args, &element_block|
104
+ raise_if_block(self, name, !element_block.nil?)
105
+ _all(*merge_args(find_args, runtime_args)).map do |element|
82
106
  section_class.new(self, element)
83
107
  end
84
108
  end
85
109
  end
86
110
  end
87
111
 
88
- def iframe(iframe_name, iframe_page_class, *args)
112
+ def iframe(name, klass, *args)
89
113
  element_find_args = deduce_iframe_element_find_args(args)
90
114
  scope_find_args = deduce_iframe_scope_find_args(args)
91
- add_to_mapped_items(iframe_name)
92
- add_iframe_helper_methods(iframe_name, *element_find_args)
93
- define_method(iframe_name) do |&block|
115
+ add_to_mapped_items(name)
116
+ add_iframe_helper_methods(name, *element_find_args)
117
+ define_method(name) do |&block|
118
+ raise BlockMissingError unless block
119
+
94
120
  within_frame(*scope_find_args) do
95
- block.call iframe_page_class.new
121
+ block.call(klass.new)
96
122
  end
97
123
  end
98
124
  end
@@ -142,10 +168,9 @@ module SitePrism
142
168
  method_name = "has_#{element_name}?"
143
169
  create_helper_method(method_name, *find_args) do
144
170
  define_method(method_name) do |*runtime_args|
145
- wait_time = SitePrism.use_implicit_waits ? Capybara.default_max_wait_time : 0
146
- Capybara.using_wait_time(wait_time) do
147
- element_exists?(*merge_args(find_args, runtime_args))
148
- end
171
+ wait_time = SitePrism.use_implicit_waits ? max_wait_time : 0
172
+ visibility_args = { wait: wait_time }
173
+ element_exists?(*merge_args(find_args, runtime_args, **visibility_args))
149
174
  end
150
175
  end
151
176
  end
@@ -154,10 +179,11 @@ module SitePrism
154
179
  method_name = "has_no_#{element_name}?"
155
180
  create_helper_method(method_name, *find_args) do
156
181
  define_method(method_name) do |*runtime_args|
157
- wait_time = SitePrism.use_implicit_waits ? Capybara.default_max_wait_time : 0
158
- Capybara.using_wait_time(wait_time) do
159
- element_does_not_exist?(*merge_args(find_args, runtime_args))
160
- end
182
+ wait_time = SitePrism.use_implicit_waits ? max_wait_time : 0
183
+ visibility_args = { wait: wait_time }
184
+ element_does_not_exist?(
185
+ *merge_args(find_args, runtime_args, **visibility_args)
186
+ )
161
187
  end
162
188
  end
163
189
  end
@@ -165,10 +191,9 @@ module SitePrism
165
191
  def create_waiter(element_name, *find_args)
166
192
  method_name = "wait_for_#{element_name}"
167
193
  create_helper_method(method_name, *find_args) do
168
- define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args|
169
- result = Capybara.using_wait_time(timeout) do
170
- element_exists?(*merge_args(find_args, runtime_args))
171
- end
194
+ define_method(method_name) do |timeout = max_wait_time, *runtime_args|
195
+ visibility_args = { wait: timeout }
196
+ result = element_exists?(*merge_args(find_args, runtime_args, **visibility_args))
172
197
  raise_wait_for_if_failed(self, element_name.to_s, timeout, !result)
173
198
  result
174
199
  end
@@ -178,12 +203,11 @@ module SitePrism
178
203
  def create_nonexistence_waiter(element_name, *find_args)
179
204
  method_name = "wait_for_no_#{element_name}"
180
205
  create_helper_method(method_name, *find_args) do
181
- define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args|
182
- result = Capybara.using_wait_time(timeout) do
183
- element_does_not_exist?(*merge_args(find_args, runtime_args))
184
- end
185
- raise_wait_for_no_if_failed(self, element_name.to_s, timeout, !result)
186
- result
206
+ define_method(method_name) do |timeout = max_wait_time, *runtime_args|
207
+ visibility_args = { wait: timeout }
208
+ res = element_does_not_exist?(*merge_args(find_args, runtime_args, **visibility_args))
209
+ raise_wait_for_no_if_failed(self, element_name.to_s, timeout, !res)
210
+ res
187
211
  end
188
212
  end
189
213
  end
@@ -191,10 +215,11 @@ module SitePrism
191
215
  def create_visibility_waiter(element_name, *find_args)
192
216
  method_name = "wait_until_#{element_name}_visible"
193
217
  create_helper_method(method_name, *find_args) do
194
- define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args|
195
- unless element_exists?(*merge_args(find_args, runtime_args, visible: true, wait: timeout))
196
- raise SitePrism::TimeOutWaitingForElementVisibility
197
- end
218
+ define_method(method_name) do |timeout = max_wait_time, *runtime_args|
219
+ visibility_args = { visible: true, wait: timeout }
220
+ args = merge_args(find_args, runtime_args, **visibility_args)
221
+ return true if element_exists?(*args)
222
+ raise SitePrism::TimeOutWaitingForElementVisibility
198
223
  end
199
224
  end
200
225
  end
@@ -202,17 +227,19 @@ module SitePrism
202
227
  def create_invisibility_waiter(element_name, *find_args)
203
228
  method_name = "wait_until_#{element_name}_invisible"
204
229
  create_helper_method(method_name, *find_args) do
205
- define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args|
206
- unless element_does_not_exist?(*merge_args(find_args, runtime_args, visible: true, wait: timeout))
207
- raise SitePrism::TimeOutWaitingForElementInvisibility
208
- end
230
+ define_method(method_name) do |timeout = max_wait_time, *runtime_args|
231
+ visibility_args = { visible: true, wait: timeout }
232
+ args = merge_args(find_args, runtime_args, **visibility_args)
233
+ return true if element_does_not_exist?(*args)
234
+ raise SitePrism::TimeOutWaitingForElementInvisibility
209
235
  end
210
236
  end
211
237
  end
212
238
 
213
239
  def create_no_selector(method_name)
214
240
  define_method(method_name) do
215
- raise SitePrism::NoSelectorForElement.new, "#{self.class.name} => :#{method_name} needs a selector"
241
+ raise SitePrism::NoSelectorForElement.new,
242
+ "#{self.class.name} => :#{method_name} needs a selector"
216
243
  end
217
244
  end
218
245
 
@@ -255,8 +282,8 @@ module SitePrism
255
282
  klass = Class.new(klass || SitePrism::Section, &block) if block_given?
256
283
 
257
284
  unless klass
258
- raise ArgumentError, "You should provide descendant of SitePrism::Section \
259
- class or/and a block as the second argument."
285
+ raise ArgumentError, "You should provide descendant of \
286
+ SitePrism::Section class or/and a block as the second argument."
260
287
  end
261
288
  klass
262
289
  end
@@ -272,5 +299,6 @@ in section creation or set_default_search_arguments within section class")
272
299
  args if args && !args.empty?
273
300
  end
274
301
  end
302
+ # rubocop:enable Metrics/ModuleLength
275
303
  end
276
304
  end
@@ -30,5 +30,11 @@ Templated port numbers are unsupported."
30
30
  end
31
31
  end
32
32
 
33
+ class BlockMissingError < StandardError
34
+ def message
35
+ 'You can only use iFrames in a block context. See docs for more details.'
36
+ end
37
+ end
38
+
33
39
  NotLoadedError = Class.new(StandardError)
34
40
  end
@@ -80,8 +80,8 @@ module SitePrism
80
80
  @url_matcher = page_url_matcher
81
81
  end
82
82
 
83
- def self.url
84
- @url
83
+ class << self
84
+ attr_reader :url
85
85
  end
86
86
 
87
87
  def self.url_matcher
@@ -103,11 +103,11 @@ module SitePrism
103
103
 
104
104
  private
105
105
 
106
- def find_first(*find_args)
106
+ def _find(*find_args)
107
107
  page.find(*find_args)
108
108
  end
109
109
 
110
- def find_all(*find_args)
110
+ def _all(*find_args)
111
111
  page.all(*find_args)
112
112
  end
113
113
 
@@ -51,9 +51,9 @@ module SitePrism
51
51
  end
52
52
 
53
53
  def parent_page
54
- candidate_page = parent
55
- candidate_page = candidate_page.parent until candidate_page.is_a?(SitePrism::Page)
56
- candidate_page
54
+ candidate = parent
55
+ candidate = candidate.parent until candidate.is_a?(SitePrism::Page)
56
+ candidate
57
57
  end
58
58
 
59
59
  def native
@@ -62,16 +62,20 @@ module SitePrism
62
62
 
63
63
  private
64
64
 
65
- def find_first(*find_args)
66
- root_element.find(*find_args)
65
+ def _find(*find_args)
66
+ page.find(*find_args)
67
+ end
68
+
69
+ def _all(*find_args)
70
+ page.all(*find_args)
67
71
  end
68
72
 
69
73
  def element_exists?(*find_args)
70
- root_element.has_selector?(*find_args) unless root_element.nil?
74
+ page && page.has_selector?(*find_args)
71
75
  end
72
76
 
73
77
  def element_does_not_exist?(*find_args)
74
- root_element.has_no_selector?(*find_args) unless root_element.nil?
78
+ page && page.has_no_selector?(*find_args)
75
79
  end
76
80
  end
77
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- VERSION = '2.14'.freeze
4
+ VERSION = '2.15'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_prism
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.14'
4
+ version: '2.15'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nat Ritmeyer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-22 00:00:00.000000000 Z
12
+ date: 2018-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -29,44 +29,50 @@ dependencies:
29
29
  name: capybara
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '2.14'
35
+ - - "<"
33
36
  - !ruby/object:Gem::Version
34
- version: '2.12'
37
+ version: '3.1'
35
38
  type: :runtime
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
- - - "~>"
42
+ - - ">="
40
43
  - !ruby/object:Gem::Version
41
- version: '2.12'
44
+ version: '2.14'
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: cucumber
44
50
  requirement: !ruby/object:Gem::Requirement
45
51
  requirements:
46
- - - '='
52
+ - - "~>"
47
53
  - !ruby/object:Gem::Version
48
- version: 3.0.1
54
+ version: '3.0'
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
52
58
  requirements:
53
- - - '='
59
+ - - "~>"
54
60
  - !ruby/object:Gem::Version
55
- version: 3.0.1
61
+ version: '3.0'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: dotenv
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
66
  - - "~>"
61
67
  - !ruby/object:Gem::Version
62
- version: '2.2'
68
+ version: '2.5'
63
69
  type: :development
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - "~>"
68
74
  - !ruby/object:Gem::Version
69
- version: '2.2'
75
+ version: '2.5'
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: rake
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -87,28 +93,28 @@ dependencies:
87
93
  requirements:
88
94
  - - "~>"
89
95
  - !ruby/object:Gem::Version
90
- version: '3.5'
96
+ version: '3.6'
91
97
  type: :development
92
98
  prerelease: false
93
99
  version_requirements: !ruby/object:Gem::Requirement
94
100
  requirements:
95
101
  - - "~>"
96
102
  - !ruby/object:Gem::Version
97
- version: '3.5'
103
+ version: '3.6'
98
104
  - !ruby/object:Gem::Dependency
99
105
  name: rubocop
100
106
  requirement: !ruby/object:Gem::Requirement
101
107
  requirements:
102
108
  - - "~>"
103
109
  - !ruby/object:Gem::Version
104
- version: '0.50'
110
+ version: '0.52'
105
111
  type: :development
106
112
  prerelease: false
107
113
  version_requirements: !ruby/object:Gem::Requirement
108
114
  requirements:
109
115
  - - "~>"
110
116
  - !ruby/object:Gem::Version
111
- version: '0.50'
117
+ version: '0.52'
112
118
  - !ruby/object:Gem::Dependency
113
119
  name: selenium-webdriver
114
120
  requirement: !ruby/object:Gem::Requirement
@@ -129,14 +135,14 @@ dependencies:
129
135
  requirements:
130
136
  - - "~>"
131
137
  - !ruby/object:Gem::Version
132
- version: '0.12'
138
+ version: '0.14'
133
139
  type: :development
134
140
  prerelease: false
135
141
  version_requirements: !ruby/object:Gem::Requirement
136
142
  requirements:
137
143
  - - "~>"
138
144
  - !ruby/object:Gem::Version
139
- version: '0.12'
145
+ version: '0.14'
140
146
  description: |-
141
147
  SitePrism gives you a simple, clean and semantic DSL for describing your site.
142
148
  SitePrism implements the Page Object Model pattern on top of Capybara.
@@ -159,10 +165,13 @@ files:
159
165
  - lib/site_prism/section.rb
160
166
  - lib/site_prism/version.rb
161
167
  - lib/site_prism/waiter.rb
162
- homepage: http://github.com/natritmeyer/site_prism
168
+ homepage: https://github.com/natritmeyer/site_prism
163
169
  licenses:
164
- - BSD3
165
- metadata: {}
170
+ - BSD-3-Clause
171
+ metadata:
172
+ bug_tracker_uri: https://github.com/natritmeyer/site_prism/issues
173
+ changelog_uri: https://github.com/natritmeyer/site_prism/blob/master/HISTORY.md
174
+ source_code_uri: https://github.com/natritmeyer/site_prism
166
175
  post_install_message:
167
176
  rdoc_options: []
168
177
  require_paths: