page-object 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/ChangeLog +9 -0
  4. data/Gemfile +1 -0
  5. data/features/section.feature +4 -0
  6. data/features/step_definitions/section_steps.rb +10 -1
  7. data/lib/page-object.rb +16 -8
  8. data/lib/page-object/accessors.rb +2 -2
  9. data/lib/page-object/elements/button.rb +0 -7
  10. data/lib/page-object/elements/canvas.rb +1 -13
  11. data/lib/page-object/elements/check_box.rb +0 -12
  12. data/lib/page-object/elements/element.rb +52 -9
  13. data/lib/page-object/elements/file_field.rb +0 -12
  14. data/lib/page-object/elements/form.rb +0 -12
  15. data/lib/page-object/elements/image.rb +0 -12
  16. data/lib/page-object/elements/link.rb +0 -12
  17. data/lib/page-object/elements/ordered_list.rb +0 -13
  18. data/lib/page-object/elements/radio_button.rb +0 -12
  19. data/lib/page-object/elements/select_list.rb +0 -13
  20. data/lib/page-object/elements/table.rb +0 -13
  21. data/lib/page-object/elements/table_row.rb +0 -13
  22. data/lib/page-object/elements/text_area.rb +0 -14
  23. data/lib/page-object/elements/text_field.rb +0 -12
  24. data/lib/page-object/elements/unordered_list.rb +0 -12
  25. data/lib/page-object/elements/video.rb +0 -10
  26. data/lib/page-object/platforms/selenium_webdriver/element.rb +1 -1
  27. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +26 -5
  28. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +1 -1
  29. data/lib/page-object/platforms/selenium_webdriver/table.rb +1 -1
  30. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +1 -1
  31. data/lib/page-object/platforms/watir_webdriver/element.rb +9 -2
  32. data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +1 -1
  33. data/lib/page-object/platforms/watir_webdriver/page_object.rb +25 -4
  34. data/lib/page-object/platforms/watir_webdriver/select_list.rb +1 -1
  35. data/lib/page-object/platforms/watir_webdriver/table.rb +1 -1
  36. data/lib/page-object/platforms/watir_webdriver/table_row.rb +1 -1
  37. data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +1 -1
  38. data/lib/page-object/section_collection.rb +16 -0
  39. data/lib/page-object/version.rb +1 -1
  40. data/lib/page-object/widgets.rb +14 -36
  41. data/spec/page-object/elements/canvas_spec.rb +3 -2
  42. data/spec/page-object/elements/ordered_list_spec.rb +2 -2
  43. data/spec/page-object/elements/select_list_spec.rb +2 -2
  44. data/spec/page-object/elements/unordered_list_spec.rb +2 -2
  45. data/spec/page-object/elements/video_spec.rb +12 -6
  46. data/spec/page-object/page-object_spec.rb +51 -23
  47. data/spec/page-object/page_section_spec.rb +9 -2
  48. data/spec/page-object/watir_accessors_spec.rb +1 -0
  49. metadata +4 -4
  50. data/lib/page-object/sections.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9da44e461744eab4d446edf6dae5566da91c771
4
- data.tar.gz: 76d49ecd39139b07d5883a6ce88b29443e65e47c
3
+ metadata.gz: 441fe4c75e361d33bb3938c23b47d55701f83074
4
+ data.tar.gz: 81d70fd600660240c761665482abed0eabde01bc
5
5
  SHA512:
6
- metadata.gz: ed083f8285b0c1ed5cad169b809e89263f8a4bb4d2ea99e803df0c79d7f8178ef272c9b133b01227d9fd07e92f14318900dd26f457add8e9d120e15dc0847497
7
- data.tar.gz: d789f587282a2106d9543ca7e23e735e315c653d3c3b8289a3467e7c2ff0be1eafc4008b99f7eba84929fe54af92271e9d03a99560014d42b6159ca5c00ec410
6
+ metadata.gz: 312e009090468c99cde07ab1bdf51082018952303849f902846cfdf96c9cac8364fbb601d2f1d8db164bf54d326277aa0163c130f3dcedce1bc6b87929e7cb92
7
+ data.tar.gz: ee8d3bcd265dfc90ecef27c3473a2010afeafb14a7c44907fcbac8165a3ec1dadaa2ba82a2e56270005ed9dfb4224c26a15c9a6de2095182a63d9a52927e050a
@@ -1 +1 @@
1
- ruby-2.1.2
1
+ ruby-2.3.1
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ Version 1.2.0 / 2016-6-15
2
+ * Enhancements
3
+ * Added array methods to section collections (Thanks Cohen Carlisle)
4
+ * Ensuring that method_missing is always forwarded to the root element (Thanks Cohen Carlisle)
5
+ * Added ability to call style method with no parameters (Thanks Justin Watts)
6
+ - with Watir will return all styles; with Selenium will return empty string
7
+ * Cleaned up frame and iframe nesting (Thanks Jon Snow)
8
+ * Support for adding other platforms (Thanks pvmeerbe)
9
+
1
10
  === Version 1.1.1 / 2016-1-7
2
11
  * Enhancements
3
12
  * Added row accessor method and support for finding row elements directly (Thanks Ethan Hedrick)
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem 'fuubar-cucumber', '>= 0.0.22'
7
7
  gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
8
8
  gem 'growl'
9
9
  gem 'guard-rspec'
10
+ gem 'listen', '3.0.8' #Last version that supports ruby 2.0
10
11
  gem 'guard-cucumber'
11
12
  gem 'net-http-persistent'
12
13
  gem 'coveralls', require: false
@@ -116,6 +116,10 @@ Feature: Sections
116
116
  Given I search for a link in an indexed property located in a section
117
117
  Then I should see the text "Success" in the section indexed link
118
118
 
119
+ Scenario: Sections roots can be accessed
120
+ When I have a page section
121
+ Then methods called on the section are passed to the root if missing
122
+
119
123
  Scenario: Selecting multiple sections
120
124
  When I select multiple sections
121
125
  Then I should have a section collection containing the sections
@@ -265,4 +265,13 @@ end
265
265
 
266
266
  Given(/^I search for a link in an indexed property located in a section$/) do
267
267
  @link = @page.container.indexed_list['success'].indexed_link_element
268
- end
268
+ end
269
+
270
+ When(/^I have a page section$/) do
271
+ @section = @page.container
272
+ end
273
+
274
+ Then(/^methods called on the section are passed to the root if missing$/) do
275
+ expect(-> { @section.visible? }).not_to raise_error
276
+ expect(@section.visible?).to be true
277
+ end
@@ -7,7 +7,7 @@ require 'page-object/page_factory'
7
7
  require 'page-object/page_populator'
8
8
  require 'page-object/javascript_framework_facade'
9
9
  require 'page-object/indexed_properties'
10
- require 'page-object/sections'
10
+ require 'page-object/section_collection'
11
11
  require 'page-object/widgets'
12
12
 
13
13
  require 'watir-webdriver'
@@ -26,7 +26,7 @@ require 'selenium/webdriver/common/error'
26
26
  # button we might define our page like the one below. We can then interact with
27
27
  # the object using the generated methods.
28
28
  #
29
- # @example Login page example
29
+ # @example Login page example
30
30
  # class LoginPage
31
31
  # include PageObject
32
32
  #
@@ -49,10 +49,18 @@ module PageObject
49
49
  include LoadsPlatform
50
50
  include ElementLocators
51
51
  include PagePopulator
52
- extend Forwardable
53
52
 
54
- # Forward visibility checks to root so page sections can be tested for existence.
55
- def_delegators :root, :visible?, :present?, :exists?
53
+ def method_missing(method, *args, &block)
54
+ if @root_element && @root_element.respond_to?(method)
55
+ @root_element.send(method, *args, &block)
56
+ else
57
+ super
58
+ end
59
+ end
60
+
61
+ def respond_to_missing?(method, include_all = false)
62
+ @root_element && @root_element.respond_to?(method) || super
63
+ end
56
64
 
57
65
  # @return [Watir::Browser or Selenium::WebDriver::Driver] the platform browser passed to the constructor
58
66
  attr_reader :browser
@@ -61,7 +69,7 @@ module PageObject
61
69
 
62
70
  #
63
71
  # Construct a new page object. Prior to browser initialization it will call
64
- # a method named initialize_accessors if it exists. Upon initialization of
72
+ # a method named initialize_accessors if it exists. Upon initialization of
65
73
  # the page it will call a method named initialize_page if it exists.
66
74
  #
67
75
  # @param [Watir::Browser, Watir::HTMLElement or Selenium::WebDriver::Driver, Selenium::WebDriver::Element] the platform browser/element to use
@@ -269,7 +277,7 @@ module PageObject
269
277
  #
270
278
  def execute_script(script, *args)
271
279
  args.map! { |e| e.kind_of?(PageObject::Elements::Element) ? e.element : e }
272
- platform.execute_script(script, *args)
280
+ platform.execute_script(script, *args)
273
281
  end
274
282
 
275
283
  #
@@ -313,7 +321,7 @@ module PageObject
313
321
  #
314
322
  def in_iframe(identifier, frame=nil, &block)
315
323
  platform.in_iframe(identifier, frame, &block)
316
- end
324
+ end
317
325
 
318
326
  #
319
327
  # Override the normal showModalDialog call is it opens a window instead
@@ -153,7 +153,7 @@ module PageObject
153
153
  # @param block that contains the calls to elements that exist inside the frame.
154
154
  #
155
155
  def in_frame(identifier, frame=nil, &block)
156
- frame = [] if frame.nil?
156
+ frame = frame.nil? ? [] : frame.dup
157
157
  frame << {frame: identifier}
158
158
  block.call(frame)
159
159
  end
@@ -177,7 +177,7 @@ module PageObject
177
177
  # @param block that contains the calls to elements that exist inside the iframe.
178
178
  #
179
179
  def in_iframe(identifier, frame=nil, &block)
180
- frame = [] if frame.nil?
180
+ frame = frame.nil? ? [] : frame.dup
181
181
  frame << {iframe: identifier}
182
182
  block.call(frame)
183
183
  end
@@ -18,13 +18,6 @@ module PageObject
18
18
  super + [:value, :src, :alt]
19
19
  end
20
20
 
21
- def include_platform_for platform
22
- super
23
- if platform[:platform] == :selenium_webdriver
24
- require 'page-object/platforms/selenium_webdriver/button'
25
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Button
26
- end
27
- end
28
21
  end
29
22
 
30
23
  ::PageObject::Elements.type_to_class[:submit] = ::PageObject::Elements::Button
@@ -2,20 +2,8 @@
2
2
  module PageObject
3
3
  module Elements
4
4
  class Canvas < Element
5
- #
6
- # return the width of the canvas
7
- #
8
- def width
9
- attribute(:width).to_i
10
- end
11
5
 
12
- #
13
- # return the height of the canvas
14
- #
15
- def height
16
- attribute(:height).to_i
17
- end
18
-
6
+
19
7
  end
20
8
  ::PageObject::Elements.type_to_class[:canvas] = ::PageObject::Elements::Canvas
21
9
  end
@@ -17,18 +17,6 @@ module PageObject
17
17
  super + [:value, :label, :css]
18
18
  end
19
19
 
20
- def include_platform_for platform
21
- super
22
- if platform[:platform] == :watir_webdriver
23
- require 'page-object/platforms/watir_webdriver/check_box'
24
- self.class.send :include, PageObject::Platforms::WatirWebDriver::CheckBox
25
- elsif platform[:platform] == :selenium_webdriver
26
- require 'page-object/platforms/selenium_webdriver/check_box'
27
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::CheckBox
28
- else
29
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
30
- end
31
- end
32
20
  end
33
21
 
34
22
  ::PageObject::Elements.type_to_class[:checkbox] = ::PageObject::Elements::CheckBox
@@ -44,7 +44,7 @@ module PageObject
44
44
  #
45
45
  # get the value of the given CSS property
46
46
  #
47
- def style(property)
47
+ def style(property = nil)
48
48
  element.style property
49
49
  end
50
50
 
@@ -207,20 +207,63 @@ module PageObject
207
207
  end
208
208
 
209
209
  def include_platform_for platform
210
- if platform[:platform] == :watir_webdriver
211
- self.class.send :include, ::PageObject::Platforms::WatirWebDriver::Element
212
- @platform = ::PageObject::Platforms::WatirWebDriver::PageObject.new(@element)
213
- elsif platform[:platform] == :selenium_webdriver
214
- self.class.send :include, ::PageObject::Platforms::SeleniumWebDriver::Element
215
- @platform = ::PageObject::Platforms::SeleniumWebDriver::PageObject.new(@element)
216
- else
217
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
210
+ platform_information = PageObject::Platforms.get
211
+ raise ArgumentError,"Expected hash with at least a key :platform for platform information! (#{platform.inspect})" unless platform.class == Hash && platform.has_key?(:platform)
212
+ platform_name = platform[:platform]
213
+
214
+ raise ArgumentError, "Unknown platform #{platform_name}! Expect platform to be one of the following: #{platform_information.keys.inspect}" unless platform_information.keys.include?(platform_name)
215
+ base_platform_class = "#{platform_information[platform_name]}::"
216
+
217
+ self.send :extend, constantize_classname(base_platform_class + "Element")
218
+ @platform = constantize_classname(base_platform_class+ "PageObject").new(@element)
219
+
220
+ # include class specific code
221
+ class_to_include = case
222
+ when self.class == PageObject::Elements::Element
223
+ # already loaded
224
+ return true
225
+ when self.class.name =~/PageObject:Elements::/
226
+ self.class
227
+ # inherited classes for example the widgets
228
+ else
229
+ parent_classes = self.class.ancestors.select { |item| item.name =~/PageObject::Elements::/ }
230
+ raise RuntimeError,"Could not identify page-object inherited class for #{self.class}!" if parent_classes.empty?
231
+ parent_classes.first
232
+ end
233
+
234
+ element_type_specific_code = File.expand_path(File.dirname(__FILE__) + "../../platforms/#{platform_name}/"+ get_element_type_underscored(class_to_include) )
235
+ if File.exist? element_type_specific_code + '.rb'
236
+ require element_type_specific_code
237
+ self.send :extend, constantize_classname( base_platform_class + get_element_type(class_to_include) )
218
238
  end
239
+
219
240
  end
220
241
 
221
242
  def to_ary
222
243
  nil
223
244
  end
245
+
246
+ private
247
+
248
+
249
+ def constantize_classname name
250
+ name.split("::").inject(Object) { |k,n| k.const_get(n) }
251
+ end
252
+
253
+
254
+ def get_element_type(class_name = self.class)
255
+ class_name.name.split('::').last
256
+ end
257
+
258
+ # retrieved from ruby on rails underscore method
259
+ def get_element_type_underscored(class_name = self.class)
260
+ get_element_type(class_name).to_s.gsub(/::/, '/').
261
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
262
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
263
+ tr("-", "_").
264
+ downcase
265
+ end
266
+
224
267
  end
225
268
  end
226
269
  end
@@ -18,18 +18,6 @@ module PageObject
18
18
  super + [:title, :label]
19
19
  end
20
20
 
21
- def include_platform_for platform
22
- super
23
- if platform[:platform] == :watir_webdriver
24
- require 'page-object/platforms/watir_webdriver/file_field'
25
- self.class.send :include, PageObject::Platforms::WatirWebDriver::FileField
26
- elsif platform[:platform] == :selenium_webdriver
27
- require 'page-object/platforms/selenium_webdriver/file_field'
28
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::FileField
29
- else
30
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
31
- end
32
- end
33
21
  end
34
22
 
35
23
  ::PageObject::Elements.type_to_class[:file] = ::PageObject::Elements::FileField
@@ -17,18 +17,6 @@ module PageObject
17
17
  super + [:action]
18
18
  end
19
19
 
20
- def include_platform_for platform
21
- super
22
- if platform[:platform] == :watir_webdriver
23
- require 'page-object/platforms/watir_webdriver/form'
24
- self.class.send :include, PageObject::Platforms::WatirWebDriver::Form
25
- elsif platform[:platform] == :selenium_webdriver
26
- require 'page-object/platforms/selenium_webdriver/form'
27
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Form
28
- else
29
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
30
- end
31
- end
32
20
  end
33
21
 
34
22
  ::PageObject::Elements.tag_to_class[:form] = ::PageObject::Elements::Form
@@ -16,18 +16,6 @@ module PageObject
16
16
  super + [:alt, :src, :css]
17
17
  end
18
18
 
19
- def include_platform_for platform
20
- super
21
- if platform[:platform] == :watir_webdriver
22
- require 'page-object/platforms/watir_webdriver/image'
23
- self.class.send :include, PageObject::Platforms::WatirWebDriver::Image
24
- elsif platform[:platform] == :selenium_webdriver
25
- require 'page-object/platforms/selenium_webdriver/image'
26
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Image
27
- else
28
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
29
- end
30
- end
31
19
  end
32
20
 
33
21
  ::PageObject::Elements.tag_to_class[:img] = ::PageObject::Elements::Image
@@ -26,18 +26,6 @@ module PageObject
26
26
  super.merge(:text => :link_text)
27
27
  end
28
28
 
29
- def include_platform_for platform
30
- super
31
- if platform[:platform] == :watir_webdriver
32
- require 'page-object/platforms/watir_webdriver/link'
33
- self.class.send :include, PageObject::Platforms::WatirWebDriver::Link
34
- elsif platform[:platform] == :selenium_webdriver
35
- require 'page-object/platforms/selenium_webdriver/link'
36
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Link
37
- else
38
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
39
- end
40
- end
41
29
  end
42
30
 
43
31
  ::PageObject::Elements.tag_to_class[:a] = ::PageObject::Elements::Link
@@ -30,19 +30,6 @@ module PageObject
30
30
  [:class, :id, :index, :xpath]
31
31
  end
32
32
 
33
- def include_platform_for platform
34
- super
35
- if platform[:platform] == :watir_webdriver
36
- require 'page-object/platforms/watir_webdriver/ordered_list'
37
- self.class.send :include, PageObject::Platforms::WatirWebDriver::OrderedList
38
- elsif platform[:platform] == :selenium_webdriver
39
- require 'page-object/platforms/selenium_webdriver/ordered_list'
40
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::OrderedList
41
- else
42
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
43
- end
44
- end
45
-
46
33
  end
47
34
 
48
35
  ::PageObject::Elements.tag_to_class[:ol] = ::PageObject::Elements::OrderedList
@@ -18,18 +18,6 @@ module PageObject
18
18
  super + [:value, :label]
19
19
  end
20
20
 
21
- def include_platform_for platform
22
- super
23
- if platform[:platform] == :watir_webdriver
24
- require 'page-object/platforms/watir_webdriver/radio_button'
25
- self.class.send :include, PageObject::Platforms::WatirWebDriver::RadioButton
26
- elsif platform[:platform] == :selenium_webdriver
27
- require 'page-object/platforms/selenium_webdriver/radio_button'
28
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::RadioButton
29
- else
30
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
31
- end
32
- end
33
21
  end
34
22
 
35
23
  ::PageObject::Elements.type_to_class[:radio] = ::PageObject::Elements::RadioButton
@@ -22,19 +22,6 @@ module PageObject
22
22
  super + [:label]
23
23
  end
24
24
 
25
- def include_platform_for platform
26
- super
27
- if platform[:platform] == :watir_webdriver
28
- require 'page-object/platforms/watir_webdriver/select_list'
29
- self.class.send :include, PageObject::Platforms::WatirWebDriver::SelectList
30
- elsif platform[:platform] == :selenium_webdriver
31
- require 'page-object/platforms/selenium_webdriver/select_list'
32
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::SelectList
33
- else
34
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
35
- end
36
- end
37
-
38
25
  end
39
26
 
40
27
  ::PageObject::Elements.tag_to_class[:select] = ::PageObject::Elements::SelectList
@@ -59,19 +59,6 @@ module PageObject
59
59
  ::PageObject::Elements::TableRow.new(row_element, platform)
60
60
  end
61
61
 
62
-
63
- def include_platform_for platform
64
- super
65
- if platform[:platform] == :watir_webdriver
66
- require 'page-object/platforms/watir_webdriver/table'
67
- self.class.send :include, PageObject::Platforms::WatirWebDriver::Table
68
- elsif platform[:platform] == :selenium_webdriver
69
- require 'page-object/platforms/selenium_webdriver/table'
70
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::Table
71
- else
72
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
73
- end
74
- end
75
62
  end
76
63
 
77
64
  ::PageObject::Elements.tag_to_class[:table] = ::PageObject::Elements::Table