druid-ts 1.1.7 → 1.1.8

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +59 -0
  3. data/Gemfile +1 -0
  4. data/druid.gemspec +1 -0
  5. data/features/area.feature +1 -0
  6. data/features/audio.feature +1 -0
  7. data/features/canvas.feature +1 -0
  8. data/features/checkbox.feature +2 -0
  9. data/features/div.feature +1 -0
  10. data/features/element.feature +15 -0
  11. data/features/file_field.feature +2 -0
  12. data/features/form.feature +1 -0
  13. data/features/generic_elements.feature +5 -0
  14. data/features/heading.feature +6 -0
  15. data/features/hidden_field.feature +1 -0
  16. data/features/html/images/img_pulpit.jpg +0 -0
  17. data/features/html/static_elements.html +19 -1
  18. data/features/image.feature +1 -0
  19. data/features/label.feature +1 -0
  20. data/features/list_item.feature +1 -0
  21. data/features/multi_elements.feature +7 -0
  22. data/features/ordered_list.feature +1 -0
  23. data/features/paragraph.feature +1 -0
  24. data/features/radio_button.feature +2 -0
  25. data/features/select_list.feature +2 -2
  26. data/features/span.feature +2 -1
  27. data/features/step_definations/element_steps.rb +25 -0
  28. data/features/step_definations/generic_element_steps.rb +12 -0
  29. data/features/step_definations/multi_elements_steps.rb +5 -0
  30. data/features/support/page.rb +37 -2
  31. data/features/table.feature +1 -0
  32. data/features/table_cell.feature +1 -0
  33. data/features/text_area.feature +2 -0
  34. data/features/text_field.feature +2 -0
  35. data/features/unordered_list.feature +1 -0
  36. data/features/video.feature +1 -0
  37. data/lib/druid/accessors.rb +117 -84
  38. data/lib/druid/assist.rb +19 -1
  39. data/lib/druid/elements/canvas.rb +1 -1
  40. data/lib/druid/elements/check_box.rb +1 -1
  41. data/lib/druid/elements/element.rb +1 -1
  42. data/lib/druid/elements/file_field.rb +1 -1
  43. data/lib/druid/elements/radio_button.rb +1 -1
  44. data/lib/druid/elements/select_list.rb +1 -1
  45. data/lib/druid/elements/text_area.rb +3 -0
  46. data/lib/druid/locator_generator.rb +112 -58
  47. data/lib/druid/page_factory.rb +17 -83
  48. data/lib/druid/page_populator.rb +2 -1
  49. data/lib/druid/version.rb +1 -1
  50. data/spec/druid/druid_spec.rb +1 -1
  51. data/spec/druid/page_factory_spec.rb +12 -11
  52. data/spec/druid/page_populator_spec.rb +27 -0
  53. metadata +17 -1
@@ -63,7 +63,7 @@ module Druid
63
63
  end
64
64
 
65
65
  def select_list_value_for identifier
66
- process_call("select_list(identifier).options.each {|o| return o.text if o.selected?}", Elements::SelectList, identifier)
66
+ process_call("select_list(identifier).options.find {|o| o.selected?}.text", Elements::SelectList, identifier)
67
67
  end
68
68
 
69
69
  def select_list_for identifier
@@ -490,6 +490,24 @@ module Druid
490
490
  find_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
491
491
  end
492
492
 
493
+ def elements_for(tag, identifier)
494
+ find_elements("#{tag.to_s}s(identifier)", Elements::Element, identifier, tag.to_s)
495
+ end
496
+
497
+ #
498
+ # method to return a svg element
499
+ #
500
+ def svg_for(identifier)
501
+ find_element("element(identifier)", Elements::Element, identifier)
502
+ end
503
+
504
+ #
505
+ # method to return an array of svg elements
506
+ #
507
+ def svgs_for(identifier)
508
+ find_elements("element(identifier)", Elements::Element, identifier)
509
+ end
510
+
493
511
  private
494
512
 
495
513
  def find_elements(the_call, type, identifier, tag_name=nil)
@@ -1,7 +1,7 @@
1
1
  module Druid
2
2
  module Elements
3
3
  class Canvas < Element
4
-
4
+
5
5
  #
6
6
  # return the width of the canvas
7
7
  #
@@ -3,7 +3,7 @@ module Druid
3
3
  class CheckBox < Element
4
4
 
5
5
  def self.finders
6
- super + [:value]
6
+ super + [:value, :label]
7
7
  end
8
8
 
9
9
  #
@@ -349,7 +349,7 @@ module Druid
349
349
  how, what = identifier.keys.first, identifier.values.first
350
350
  return how => what if find_by.include? how
351
351
  return find_by_mapping[how] => what if find_by_mapping[how]
352
- return nil => what
352
+ identifier
353
353
  end
354
354
 
355
355
  def self.finders
@@ -2,7 +2,7 @@ module Druid
2
2
  module Elements
3
3
  class FileField < Element
4
4
  def self.finders
5
- super + [:title]
5
+ super + [:title, :label]
6
6
  end
7
7
 
8
8
  #
@@ -3,7 +3,7 @@ module Druid
3
3
  class RadioButton < Element
4
4
 
5
5
  def self.finders
6
- super + [:value]
6
+ super + [:value, :label]
7
7
  end
8
8
  #
9
9
  # Select the RadioButton
@@ -3,7 +3,7 @@ module Druid
3
3
  class SelectList < Element
4
4
 
5
5
  def self.finders
6
- super + [:value, :text]
6
+ super + [:value, :text, :label]
7
7
  end
8
8
 
9
9
  def [](idx)
@@ -2,6 +2,9 @@ module Druid
2
2
  module Elements
3
3
  class TextArea < Element
4
4
 
5
+ def self.finders
6
+ super + [:label]
7
+ end
5
8
  #
6
9
  # Set the value of the TextArea
7
10
  #
@@ -1,65 +1,109 @@
1
1
  module Druid
2
2
  module LocatorGenerator
3
3
 
4
+ BASIC_ELEMENTS = [:abbr,
5
+ :address,
6
+ :article,
7
+ :as,
8
+ :aside,
9
+ :bdi,
10
+ :bdo,
11
+ :blockquote,
12
+ :body,
13
+ :br,
14
+ :caption,
15
+ :cite,
16
+ :code,
17
+ :col,
18
+ :colgroup,
19
+ :command,
20
+ :data,
21
+ :datalist,
22
+ :dd,
23
+ :del,
24
+ :details,
25
+ :dfn,
26
+ :dialog,
27
+ :dl,
28
+ :dt,
29
+ :em,
30
+ :embed,
31
+ :fieldset,
32
+ :figcaption,
33
+ :figure,
34
+ :footer,
35
+ :head,
36
+ :header,
37
+ :hgroup,
38
+ :hr,
39
+ :ins,
40
+ :kbd,
41
+ :keygen,
42
+ :legend,
43
+ :map,
44
+ :mark,
45
+ :menu,
46
+ :meta,
47
+ :meter,
48
+ :nav,
49
+ :noscript,
50
+ :object,
51
+ :optgroup,
52
+ :output,
53
+ :param,
54
+ :pre,
55
+ :progress,
56
+ :rp,
57
+ :rt,
58
+ :ruby,
59
+ :samp,
60
+ :section,
61
+ :small,
62
+ :strong,
63
+ :style,
64
+ :sub,
65
+ :summary,
66
+ :sup,
67
+ :time,
68
+ :title,
69
+ :track,
70
+ :var,
71
+ :wbr]
72
+
73
+ ADVANCED_ELEMENTS = [:text_field,
74
+ :hidden_field,
75
+ :text_area,
76
+ :select_list,
77
+ :link,
78
+ :checkbox,
79
+ :radio_button,
80
+ :button,
81
+ :div,
82
+ :span,
83
+ :table,
84
+ :cell,
85
+ :image,
86
+ :form,
87
+ :list_item,
88
+ :unordered_list,
89
+ :ordered_list,
90
+ :h1,
91
+ :h2,
92
+ :h3,
93
+ :h4,
94
+ :h5,
95
+ :h6,
96
+ :paragraph,
97
+ :label,
98
+ :file_field,
99
+ :area,
100
+ :canvas,
101
+ :audio,
102
+ :video,
103
+ :svg]
104
+
4
105
  def self.generate_locators(target)
5
- [:text_field,
6
- :hidden_field,
7
- :text_area,
8
- :select_list,
9
- :link,
10
- :checkbox,
11
- :radio_button,
12
- :button,
13
- :div,
14
- :span,
15
- :table,
16
- :cell,
17
- :image,
18
- :form,
19
- :list_item,
20
- :unordered_list,
21
- :ordered_list,
22
- :h1,
23
- :h2,
24
- :h3,
25
- :h4,
26
- :h5,
27
- :h6,
28
- :paragraph,
29
- :label,
30
- :file_field,
31
- :area,
32
- :canvas,
33
- :audio,
34
- :video,
35
- :abbr,
36
- :address,
37
- :article,
38
- :aside,
39
- :bdi,
40
- :cite,
41
- :code,
42
- :dd,
43
- :em,
44
- :figcaption,
45
- :figure,
46
- :footer,
47
- :header,
48
- :hgroup,
49
- :kbd,
50
- :mark,
51
- :nav,
52
- :noscript,
53
- :rp,
54
- :rt,
55
- :ruby,
56
- :samp,
57
- :section,
58
- :sub,
59
- :summary,
60
- :sup,
61
- :var,
62
- :wbr].each do |tag|
106
+ ADVANCED_ELEMENTS.each do |tag|
63
107
  target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
64
108
  self.send "#{tag.to_s}_for", locator(identifier).clone
65
109
  end
@@ -68,6 +112,16 @@ module Druid
68
112
  self.send "#{tag.to_s}s_for", identifier[0] ? identifier[0].clone : {}
69
113
  end
70
114
  end
115
+
116
+ BASIC_ELEMENTS.each do |tag|
117
+ target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
118
+ self.send :element_for, tag, locator(identifier)
119
+ end
120
+
121
+ target.send(:define_method, "#{tag.to_s}_elements") do |*identifier|
122
+ self.send(:elements_for, tag, identifier[0] ? identifier[0] : {})
123
+ end
124
+ end
71
125
  end
72
126
  end
73
127
  end
@@ -1,3 +1,5 @@
1
+ require 'page_navigation'
2
+
1
3
  module Druid
2
4
  #
3
5
  # Module to facilitate to creating of page objects in step definitions. You
@@ -31,20 +33,21 @@ module Druid
31
33
  # to the method
32
34
  # You must also call the navigation_method on each page.
33
35
  module PageFactory
36
+ include PageNavigation
34
37
  # attr_accessor :page
35
38
  #
36
39
  # Create and navigate to a page object. The navigation will only work if the
37
40
  # 'page_url' method was call on the page object.
38
41
  #
39
- # @param [PageObject, String] a class that has included the Druid module or a string containing the name of the class
42
+ # @param [PageObject, String] a class that has included the
43
+ # Druid module or a string containing the name of the class
44
+ # @param Hash values that is pass through to page class a
45
+ # available in the @params instance variable
40
46
  # @param an optional block to be called
41
47
  # @return [PageObject] the newly created page object
42
48
  #
43
49
  def visit_page(page_class, params={:using_params => {}}, &block)
44
- page_class = class_from_string(page_class) if page_class.is_a? String
45
- merged = page_class.params.merge(params[:using_params])
46
- page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
47
- on_page page_class, true, &block
50
+ on_page page_class, params, true, &block
48
51
  end
49
52
 
50
53
  # Support 'visit' for readability of usage
@@ -53,12 +56,16 @@ module Druid
53
56
  # Create a page object.
54
57
  #
55
58
  # @param [PageObject, String] a class that has included the Druid module or a string containing the name of the class
59
+ # @param Hash values that is pass through to page class a
60
+ # available in the @params instance variable.
56
61
  # @param [Bool] should the page be visited? default is false.
57
62
  # @param an optional block to be called
58
63
  # @return [PageObject] the newly created page object
59
64
  #
60
- def on_page(page_class, visit=false, &block)
65
+ def on_page(page_class, params={:using_params => {}}, visit=false, &block)
61
66
  page_class = class_from_string(page_class) if page_class.is_a? String
67
+ merged = page_class.params.merge(params[:using_params])
68
+ page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
62
69
  @current_page = page_class.new(@driver, visit)
63
70
  block.call @current_page if block
64
71
  @current_page
@@ -82,65 +89,19 @@ module Druid
82
89
  # page.update
83
90
  # end
84
91
  # @param [PageObject, String] a class that has included the Druid module or a string containing the name of the class
92
+ # @param Hash values that is pass through to page class a
93
+ # available in the @params instance variable
85
94
  # @param [block] an optional block to be called
86
95
  # @return [PageObject] the newly created page object
87
- def if_page(page_class, &block)
96
+ def if_page(page_class, params={:using_params => {}}, &block)
88
97
  page_class = class_from_string(page_class) if page_class.is_a? String
89
98
  return @current_page unless @current_page.class == page_class
90
- on_page(page_class, false, &block)
99
+ on_page(page_class, params, false, &block)
91
100
  end
92
101
 
93
102
  # support 'if' for readability of usage
94
103
  alias_method :if, :if_page
95
104
 
96
- #
97
- # Navigate to a specific page following a predefined path.
98
- #
99
- # This method requires a lot of setup. See the documentation for
100
- # this class. Once the setup is complete you can navigate to a
101
- # page traversing through all other pages along the way. It will
102
- # call the method you specified in the routes for each
103
- # page as it navigates. Using the example setup defined in the
104
- # documentation above you can call the method two ways:
105
- #
106
- # @example
107
- # page.navigate_to(PageThree) # will use the default path
108
- # page.navigate_to(PageThree, :using => :another_route)
109
- #
110
- # @param [PageObject] a class that has included the PageObject
111
- # module and which has the navigation_method defined
112
- # @param [Hash] a hash that contains an element with the key
113
- # :using. This will be used to lookup the route. It has a
114
- # default value of :default.
115
- # @param [block] an optional block to be called
116
- # @return [PageObject] the page you are navigating to
117
- #
118
- def navigate_to(page_cls, how = {:using => :default}, &block)
119
- path = path_for how
120
- to_index = find_index_for(path, page_cls)-1
121
- navigate_through_pages(path[0..to_index])
122
- on_page(page_cls, &block)
123
- end
124
-
125
- #
126
- # Same as navigate_to except it will start at the @current_page
127
- # instead the beginning of the path.
128
- #
129
- # @param [Druid] a class that has included the Druid
130
- # module and which has the navigation_method defined
131
- # @param [Hash] a hash that contains an element with the key
132
- # :using. This will be used to lookup the route. It has a default value of :default.
133
- # @param [block] an optional block to be called
134
- # @return [Druid] the page you are navigating to
135
- #
136
- def continue_navigation_to(page_cls, how = {:using => :default}, &block)
137
- path = path_for how
138
- from_index = find_index_for(path, @current_page.class)+1
139
- to_index = find_index_for(path, page_cls)-1
140
- navigate_through_pages(path[from_index..to_index])
141
- on_page(page_cls, &block)
142
- end
143
-
144
105
  private
145
106
 
146
107
  def class_from_string(str)
@@ -149,32 +110,5 @@ module Druid
149
110
  end
150
111
  end
151
112
 
152
- def path_for(how)
153
- path = Druid::PageFactory.page_object_routes[how[:using]]
154
- fail("PageFactory route :#{how[:using].to_s} not found") unless path
155
- path
156
- end
157
-
158
- def navigate_through_pages(pages)
159
- pages.each do |cls, method, *args|
160
- page = on_page(cls)
161
- fail("Navigation method not specified on #{cls}.") unless page.respond_to? method
162
- page.send method unless args
163
- page.send method, *args if args
164
- end
165
- end
166
-
167
- def find_index_for(path, item)
168
- path.each_with_index { |each, index| return index if each[0] == item }
169
- end
170
-
171
- class << self
172
- attr_accessor :page_object_routes
173
-
174
- def routes=(routes)
175
- raise("You must provide a :default route for PageFactory routes") unless routes[:default]
176
- @page_object_routes = routes
177
- end
178
- end
179
113
  end
180
114
  end
@@ -66,7 +66,8 @@ module Druid
66
66
 
67
67
  def is_enabled?(key)
68
68
  return true if (self.send "#{key}_element").tag_name == "textarea"
69
- self.send("#{key}_element").enabled?
69
+ element = self.send("#{key}_element")
70
+ element.enabled? and element.visible?
70
71
  end
71
72
  end
72
73
  end