druid-ts 1.1.0 → 1.1.1

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.
@@ -4,98 +4,194 @@ module Druid
4
4
  link_for(identifier)
5
5
  end
6
6
 
7
+ def link_elements(identifier={:index => 0})
8
+ links_for(identifier)
9
+ end
10
+
7
11
  def button_element(identifier={:index => 0})
8
12
  button_for(identifier)
9
13
  end
10
14
 
15
+ def button_elements(identifier={:index => 0})
16
+ buttons_for(identifier)
17
+ end
18
+
11
19
  def text_field_element(identifier={:index => 0})
12
20
  text_field_for(identifier)
13
21
  end
14
22
 
23
+ def text_field_elements(identifier={:index => 0})
24
+ text_fields_for(identifier)
25
+ end
26
+
15
27
  def hidden_field_element(identifier={:index => 0})
16
28
  hidden_field_for(identifier)
17
29
  end
18
30
 
31
+ def hidden_field_elements(identifier={:index => 0})
32
+ hidden_fields_for(identifier)
33
+ end
34
+
19
35
  def text_area_element(identifier={:index => 0})
20
36
  text_area_for(identifier)
21
37
  end
22
38
 
39
+ def text_area_elements(identifier={:index => 0})
40
+ text_areas_for(identifier)
41
+ end
42
+
23
43
  def select_list_element(identifier={:index => 0})
24
44
  select_list_for(identifier)
25
45
  end
26
46
 
47
+ def select_list_elements(identifier={:index => 0})
48
+ select_lists_for(identifier)
49
+ end
50
+
27
51
  def checkbox_element(identifier={:index => 0})
28
52
  checkbox_for(identifier)
29
53
  end
30
54
 
55
+ def checkbox_elements(identifier={:index => 0})
56
+ checkboxs_for(identifier)
57
+ end
58
+
31
59
  def radio_button_element(identifier={:index => 0})
32
60
  radio_button_for(identifier)
33
61
  end
34
62
 
63
+ def radio_button_elements(identifier={:index => 0})
64
+ radio_buttons_for(identifier)
65
+ end
66
+
35
67
  def div_element(identifier={:index => 0})
36
68
  div_for(identifier)
37
69
  end
38
70
 
71
+ def div_elements(identifier={:index => 0})
72
+ divs_for(identifier)
73
+ end
74
+
39
75
  def span_element(identifier={:index => 0})
40
76
  span_for(identifier)
41
77
  end
42
78
 
79
+ def span_elements(identifier={:index => 0})
80
+ spans_for(identifier)
81
+ end
82
+
43
83
  def table_element(identifier={:index => 0})
44
84
  table_for(identifier)
45
85
  end
46
86
 
87
+ def table_elements(identifier={:index => 0})
88
+ tables_for(identifier)
89
+ end
90
+
47
91
  def cell_element(identifier={:index => 0})
48
92
  cell_for(identifier)
49
93
  end
50
94
 
95
+ def cell_elements(identifier={:index => 0})
96
+ cells_for(identifier)
97
+ end
98
+
51
99
  def image_element(identifier={:index => 0})
52
100
  image_for(identifier)
53
101
  end
54
102
 
103
+ def image_elements(identifier={:index => 0})
104
+ images_for(identifier)
105
+ end
106
+
55
107
  def form_element(identifier={:index => 0})
56
108
  form_for(identifier)
57
109
  end
58
110
 
111
+ def form_elements(identifier={:index => 0})
112
+ forms_for(identifier)
113
+ end
114
+
59
115
  def ordered_list_element(identifier={:index => 0})
60
116
  ordered_list_for(identifier)
61
117
  end
62
118
 
119
+ def ordered_list_elements(identifier={:index => 0})
120
+ ordered_lists_for(identifier)
121
+ end
122
+
63
123
  def unordered_list_element(identifier={:index => 0})
64
124
  unordered_list_for(identifier)
65
125
  end
66
126
 
127
+ def unordered_list_elements(identifier={:index => 0})
128
+ unordered_lists_for(identifier)
129
+ end
130
+
67
131
  def list_item_element(identifier={:index => 0})
68
132
  list_item_for(identifier)
69
133
  end
70
134
 
135
+ def list_item_elements(identifier={:index => 0})
136
+ list_items_for(identifier)
137
+ end
138
+
71
139
  def h1_element(identifier={:index => 0})
72
140
  h1_for(identifier)
73
141
  end
74
142
 
143
+ def h1_elements(identifier={:index => 0})
144
+ h1s_for(identifier)
145
+ end
146
+
75
147
  def h2_element(identifier={:index => 0})
76
148
  h2_for(identifier)
77
149
  end
78
150
 
151
+ def h2_elements(identifier={:index => 0})
152
+ h2s_for(identifier)
153
+ end
154
+
79
155
  def h3_element(identifier={:index => 0})
80
156
  h3_for(identifier)
81
157
  end
82
158
 
159
+ def h3_elements(identifier={:index => 0})
160
+ h3s_for(identifier)
161
+ end
162
+
83
163
  def h4_element(identifier={:index => 0})
84
164
  h4_for(identifier)
85
165
  end
86
166
 
167
+ def h4_elements(identifier={:index => 0})
168
+ h4s_for(identifier)
169
+ end
170
+
87
171
  def h5_element(identifier={:index => 0})
88
172
  h5_for(identifier)
89
173
  end
90
174
 
175
+ def h5_elements(identifier={:index => 0})
176
+ h5s_for(identifier)
177
+ end
178
+
91
179
  def h6_element(identifier={:index => 0})
92
180
  h6_for(identifier)
93
181
  end
94
182
 
183
+ def h6_elements(identifier={:index => 0})
184
+ h6s_for(identifier)
185
+ end
186
+
95
187
  def paragraph_element(identifier={:index => 0})
96
188
  paragraph_for(identifier)
97
189
  end
98
190
 
191
+ def paragraph_elements(identifier={:index => 0})
192
+ paragraphs_for(identifier)
193
+ end
194
+
99
195
  def file_field_element(identifier={:index =>0})
100
196
  file_field_for(identifier)
101
197
  end
@@ -18,6 +18,16 @@ module Druid
18
18
  # page.name.should == 'Tim'
19
19
  # end
20
20
  #
21
+ # If you plan to use the navigate_to method you will need to ensure you setup the possible
22
+ # routes ahead of time. You must always have a default route in order for this to work. Here
23
+ # is an example of how you define routes:
24
+ #
25
+ # @example Example routes defined in env.rb
26
+ # Druid::PageFactory.routes = {
27
+ # :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3],
28
+ # :another_route => [[PageOne,:method1], [PageTwoB,:method2b], [PageThree,:method3]]
29
+ # }
30
+ # You must also call the navigation_method on each page.
21
31
  module PageFactory
22
32
  # attr_accessor :page
23
33
  #
@@ -41,18 +51,85 @@ module Druid
41
51
  #
42
52
  def on_page(page_class, visit=false, &block)
43
53
  @current_page = page_class.new(@driver, visit)
44
- yield @current_page if block_given?
54
+ block.call @current_page if block
45
55
  @current_page
46
56
  end
47
- # def visit_page(page_class, &block)
48
- # page = page_class.new(@driver, true)
49
- # yield page if block_given?
50
- # page
51
- # end
57
+
58
+ #
59
+ # Navigate to a specific page following a predefined path.
60
+ #
61
+ # This method requires a lot of setup. See the documentation for
62
+ # this class. Once the setup is complete you can navigate to a
63
+ # page traversing through all other pages along the way. It will
64
+ # call the method you specified in the routes for each
65
+ # page as it navigates. Using the example setup defined in the
66
+ # documentation above you can call the method two ways:
67
+ #
68
+ # @example
69
+ # page.navigate_to(PageThree) # will use the default path
70
+ # page.navigate_to(PageThree, :using => :another_route)
71
+ #
72
+ # @param [PageObject] a class that has included the PageObject
73
+ # module and which has the navigation_method defined
74
+ # @param [Hash] a hash that contains an element with the key
75
+ # :using. This will be used to lookup the route. It has a
76
+ # default value of :default.
77
+ # @param [block] an optional block to be called
78
+ # @return [PageObject] the page you are navigating to
79
+ #
80
+ def navigate_to(page_cls, how = {:using => :default}, &block)
81
+ path = path_for how
82
+ to_index = find_index_for(path, page_cls)-1
83
+ navigate_through_pages(path[0..to_index])
84
+ on_page(page_cls, &block)
85
+ end
86
+
52
87
  #
53
- # def on_page(page, &block)
54
- # yield page if block_given?
55
- # page
56
- # end
88
+ # Same as navigate_to except it will start at the @current_page
89
+ # instead the beginning of the path.
90
+ #
91
+ # @param [Druid] a class that has included the Druid
92
+ # module and which has the navigation_method defined
93
+ # @param [Hash] a hash that contains an element with the key
94
+ # :using. This will be used to lookup the route. It has a default value of :default.
95
+ # @param [block] an optional block to be called
96
+ # @return [Druid] the page you are navigating to
97
+ #
98
+ def continue_navigation_to(page_cls, how = {:using => :default}, &block)
99
+ path = path_for how
100
+ from_index = find_index_for(path, @current_page.class)+1
101
+ to_index = find_index_for(path, page_cls)-1
102
+ navigate_through_pages(path[from_index..to_index])
103
+ on_page(page_cls, &block)
104
+ end
105
+
106
+ private
107
+
108
+ def path_for(how)
109
+ path = Druid::PageFactory.page_object_routes[how[:using]]
110
+ fail("PageFactory route :#{how[:using].to_s} not found") unless path
111
+ path
112
+ end
113
+
114
+ def navigate_through_pages(pages)
115
+ pages.each do |cls, method|
116
+ page = on_page(cls)
117
+ fail("Navigation method not specified on #{cls}. Please call the ") unless page.respond_to? method
118
+ page.send method
119
+ end
120
+ end
121
+
122
+ def find_index_for(path, item)
123
+ path.each_with_index { |each, index| return index if each[0] == item }
124
+ end
125
+
126
+ class << self
127
+ attr_accessor :page_object_routes
128
+
129
+ def routes=(routes)
130
+ raise("You must provide a :default route for PageFactory routes") unless routes[:default]
131
+ @page_object_routes = routes
132
+ end
133
+ end
57
134
  end
58
135
  end
@@ -0,0 +1,3 @@
1
+ module Druid
2
+ VERSION = "1.1.1"
3
+ end
@@ -14,144 +14,291 @@ describe Druid::ElementLocators do
14
14
  expect(button).to be_instance_of Druid::Elements::Button
15
15
  end
16
16
 
17
+ it "should find all button elements" do
18
+ expect(driver).to receive(:buttons).with(:id => 'blah').and_return([driver])
19
+ elements = page.button_elements(:id => 'blah')
20
+ expect(elements[0]).to be_instance_of Druid::Elements::Button
21
+ end
22
+
17
23
  it "should find a text field element" do
18
24
  expect(driver).to receive(:text_field).with(:id => 'blah').and_return(driver)
19
25
  text_field = page.text_field_element(:id => 'blah')
20
26
  expect(text_field).to be_instance_of Druid::Elements::TextField
21
27
  end
22
28
 
29
+ it "should find all text field elemnts" do
30
+ expect(driver).to receive(:text_fields).with(:id => 'blah').and_return([driver])
31
+ elements = page.text_field_elements(:id => 'blah')
32
+ expect(elements[0]).to be_instance_of Druid::Elements::TextField
33
+ end
34
+
23
35
  it "should find a hidden field element" do
24
36
  expect(driver).to receive(:hidden).with(:id => 'blah').and_return(driver)
25
37
  element = page.hidden_field_element(:id => 'blah')
26
38
  expect(element).to be_instance_of Druid::Elements::HiddenField
27
39
  end
28
40
 
41
+ it "should find all hidden field elements" do
42
+ expect(driver).to receive(:hiddens).with(:id => 'blah').and_return([driver])
43
+ elements = page.hidden_field_elements(:id => 'blah')
44
+ expect(elements[0]).to be_instance_of Druid::Elements::HiddenField
45
+ end
46
+
29
47
  it "should find a text area element" do
30
48
  expect(driver).to receive(:textarea).with(:id => 'blah').and_return(driver)
31
49
  element = page.text_area_element(:id => "blah")
32
50
  expect(element).to be_instance_of Druid::Elements::TextArea
33
51
  end
34
52
 
53
+ it "should find all text area elements" do
54
+ expect(driver).to receive(:textareas).with(:id => 'blah').and_return([driver])
55
+ elements = page.text_area_elements(:id => 'blah')
56
+ expect(elements[0]).to be_instance_of Druid::Elements::TextArea
57
+ end
58
+
35
59
  it "should find a select list element" do
36
60
  expect(driver).to receive(:select_list).with(:id => 'blah').and_return(driver)
37
61
  element = page.select_list_element(:id => "blah")
38
62
  expect(element).to be_instance_of Druid::Elements::SelectList
39
63
  end
40
64
 
65
+ it "should find all select list elements" do
66
+ expect(driver).to receive(:select_lists).with(:id => 'blah').and_return([driver])
67
+ elements = page.select_list_elements(:id => 'blah')
68
+ expect(elements[0]).to be_instance_of Druid::Elements::SelectList
69
+ end
70
+
41
71
  it "should find a link element" do
42
72
  expect(driver).to receive(:link).with(:id => 'blah').and_return(driver)
43
73
  element = page.link_element(:id => 'blah')
44
74
  expect(element).to be_instance_of Druid::Elements::Link
45
75
  end
46
76
 
77
+ it "should find all link elements" do
78
+ expect(driver).to receive(:links).with(:id => 'blah').and_return([driver])
79
+ elements = page.link_elements(:id => 'blah')
80
+ expect(elements[0]).to be_instance_of Druid::Elements::Link
81
+ end
82
+
47
83
  it "should find a check box element" do
48
84
  expect(driver).to receive(:checkbox).with(:id => 'blah').and_return(driver)
49
85
  element = page.checkbox_element(:id => 'blah')
50
86
  expect(element).to be_instance_of Druid::Elements::CheckBox
51
87
  end
52
88
 
89
+ it "should find all check box elements" do
90
+ expect(driver).to receive(:checkboxes).with(:id => 'blah').and_return([driver])
91
+ elements = page.checkbox_elements(:id => 'blah')
92
+ expect(elements[0]).to be_instance_of Druid::Elements::CheckBox
93
+ end
94
+
53
95
  it "should find a radio button element" do
54
96
  expect(driver).to receive(:radio).with(:id => 'blah').and_return(driver)
55
97
  element = page.radio_button_element(:id => 'blah')
56
98
  expect(element).to be_instance_of Druid::Elements::RadioButton
57
99
  end
58
100
 
101
+ it "should find all radio button elements" do
102
+ expect(driver).to receive(:radios).with(:id => 'blah').and_return([driver])
103
+ elements = page.radio_button_elements(:id => 'blah')
104
+ expect(elements[0]).to be_instance_of Druid::Elements::RadioButton
105
+ end
106
+
107
+
59
108
  it "should find a div element" do
60
109
  expect(driver).to receive(:div).with(:id => 'blah').and_return(driver)
61
110
  element = page.div_element(:id => 'blah')
62
111
  expect(element).to be_instance_of Druid::Elements::Div
63
112
  end
64
113
 
114
+ it "should find all div elements" do
115
+ expect(driver).to receive(:divs).with(:id => 'blah').and_return([driver])
116
+ elements = page.div_elements(:id => 'blah')
117
+ expect(elements[0]).to be_instance_of Druid::Elements::Div
118
+ end
119
+
65
120
  it "should find a span element" do
66
121
  expect(driver).to receive(:span).with(:id => 'blah').and_return(driver)
67
122
  element = page.span_element(:id => 'blah')
68
123
  expect(element).to be_instance_of Druid::Elements::Span
69
124
  end
70
125
 
126
+ it "should find all span elements" do
127
+ expect(driver).to receive(:spans).with(:id => 'blah').and_return([driver])
128
+ elements = page.span_elements(:id => 'blah')
129
+ expect(elements[0]).to be_instance_of Druid::Elements::Span
130
+ end
131
+
71
132
  it "should find a table element" do
72
133
  expect(driver).to receive(:table).with(:id => 'blah').and_return(driver)
73
134
  element = page.table_element(:id => 'blah')
74
135
  expect(element).to be_instance_of Druid::Elements::Table
75
136
  end
76
137
 
138
+ it "should find all table elements" do
139
+ expect(driver).to receive(:tables).with(:id => 'blah').and_return([driver])
140
+ elements = page.table_elements(:id => 'blah')
141
+ expect(elements[0]).to be_instance_of Druid::Elements::Table
142
+ end
143
+
77
144
  it "should find a table cell element" do
78
145
  expect(driver).to receive(:td).with(:id => 'blah').and_return(driver)
79
146
  element = page.cell_element(:id => 'blah')
80
147
  expect(element).to be_instance_of Druid::Elements::TableCell
81
148
  end
82
149
 
150
+ it "should find all table cells" do
151
+ expect(driver).to receive(:tds).with(:id => 'blah').and_return([driver])
152
+ elements = page.cell_elements(:id => 'blah')
153
+ expect(elements[0]).to be_instance_of Druid::Elements::TableCell
154
+ end
155
+
83
156
  it "should find an image element" do
84
157
  expect(driver).to receive(:image).with(:id => 'blah').and_return(driver)
85
158
  element = page.image_element(:id => 'blah')
86
159
  expect(element).to be_instance_of Druid::Elements::Image
87
160
  end
88
161
 
162
+ it "should find all image elements" do
163
+ expect(driver).to receive(:images).with(:id => 'blah').and_return([driver])
164
+ elements = page.image_elements(:id => 'blah')
165
+ expect(elements[0]).to be_instance_of Druid::Elements::Image
166
+ end
167
+
89
168
  it "should find a form element" do
90
169
  expect(driver).to receive(:form).with(:id => 'blah').and_return(driver)
91
170
  element = page.form_element(:id => 'blah')
92
171
  expect(element).to be_instance_of Druid::Elements::Form
93
172
  end
94
173
 
174
+ it "should find all form elements" do
175
+ expect(driver).to receive(:forms).with(:id => 'blah').and_return([driver])
176
+ elements = page.form_elements(:id => 'blah')
177
+ expect(elements[0]).to be_instance_of Druid::Elements::Form
178
+ end
179
+
95
180
  it "should find a list item element" do
96
181
  expect(driver).to receive(:li).with(:id => 'blah').and_return(driver)
97
182
  element = page.list_item_element(:id => 'blah')
98
183
  expect(element).to be_instance_of Druid::Elements::ListItem
99
184
  end
100
185
 
186
+ it "should find all list item elements" do
187
+ expect(driver).to receive(:lis).with(:id => 'blah').and_return([driver])
188
+ elements = page.list_item_elements(:id => 'blah')
189
+ expect(elements[0]).to be_instance_of Druid::Elements::ListItem
190
+ end
191
+
101
192
  it "should find an ordered list element" do
102
193
  expect(driver).to receive(:ol).with(:id => 'blah').and_return(driver)
103
194
  element = page.ordered_list_element(:id => 'blah')
104
195
  expect(element).to be_instance_of Druid::Elements::OrderedList
105
196
  end
106
197
 
198
+ it "should find all ordered list elements" do
199
+ expect(driver).to receive(:ols).with(:id => 'blah').and_return([driver])
200
+ elements = page.ordered_list_elements(:id => 'blah')
201
+ expect(elements[0]).to be_instance_of Druid::Elements::OrderedList
202
+ end
203
+
204
+
107
205
  it "should find an unordered list element" do
108
206
  expect(driver).to receive(:ul).with(:id => 'blah').and_return(driver)
109
207
  element = page.unordered_list_element(:id => 'blah')
110
208
  expect(element).to be_instance_of Druid::Elements::UnOrderedList
111
209
  end
112
210
 
211
+ it "should find all unordered list elements" do
212
+ expect(driver).to receive(:uls).with(:id => 'blah').and_return([driver])
213
+ elements = page.unordered_list_elements(:id => 'blah')
214
+ expect(elements[0]).to be_instance_of Druid::Elements::UnOrderedList
215
+ end
216
+
217
+
113
218
  it "should find a h1 element" do
114
219
  expect(driver).to receive(:h1).with(:id => 'blah').and_return(driver)
115
220
  element = page.h1_element(:id => 'blah')
116
221
  expect(element).to be_instance_of Druid::Elements::Heading
117
222
  end
118
223
 
224
+ it "should find all h1 elements" do
225
+ expect(driver).to receive(:h1s).with(:id => 'blah').and_return([driver])
226
+ elements = page.h1_elements(:id => 'blah')
227
+ expect(elements[0]).to be_instance_of Druid::Elements::Heading
228
+ end
229
+
119
230
  it "should find a h2 element" do
120
231
  expect(driver).to receive(:h2).with(:id => 'blah').and_return(driver)
121
232
  element = page.h2_element(:id => 'blah')
122
233
  expect(element).to be_instance_of Druid::Elements::Heading
123
234
  end
124
235
 
236
+ it "should find all h2 elements" do
237
+ expect(driver).to receive(:h2s).with(:id => 'blah').and_return([driver])
238
+ elements = page.h2_elements(:id => 'blah')
239
+ expect(elements[0]).to be_instance_of Druid::Elements::Heading
240
+ end
241
+
125
242
  it "should find a h3 element" do
126
243
  expect(driver).to receive(:h3).with(:id => 'blah').and_return(driver)
127
244
  element = page.h3_element(:id => 'blah')
128
245
  expect(element).to be_instance_of Druid::Elements::Heading
129
246
  end
130
247
 
248
+ it "should find all h3 elements" do
249
+ expect(driver).to receive(:h3s).with(:id => 'blah').and_return([driver])
250
+ elements = page.h3_elements(:id => 'blah')
251
+ expect(elements[0]).to be_instance_of Druid::Elements::Heading
252
+ end
253
+
131
254
  it "should find a h4 element" do
132
255
  expect(driver).to receive(:h4).with(:id => 'blah').and_return(driver)
133
256
  element = page.h4_element(:id => 'blah')
134
257
  expect(element).to be_instance_of Druid::Elements::Heading
135
258
  end
136
259
 
260
+ it "should find all h4 elements" do
261
+ expect(driver).to receive(:h4s).with(:id => 'blah').and_return([driver])
262
+ elements = page.h4_elements(:id => 'blah')
263
+ expect(elements[0]).to be_instance_of Druid::Elements::Heading
264
+ end
265
+
137
266
  it "should find a h5 element" do
138
267
  expect(driver).to receive(:h5).with(:id => 'blah').and_return(driver)
139
268
  element = page.h5_element(:id => 'blah')
140
269
  expect(element).to be_instance_of Druid::Elements::Heading
141
270
  end
142
271
 
272
+ it "should find all h5 elements" do
273
+ expect(driver).to receive(:h5s).with(:id => 'blah').and_return([driver])
274
+ elements = page.h5_elements(:id => 'blah')
275
+ expect(elements[0]).to be_instance_of Druid::Elements::Heading
276
+ end
277
+
143
278
  it "should find a h6 element" do
144
279
  expect(driver).to receive(:h6).with(:id => 'blah').and_return(driver)
145
280
  element = page.h6_element(:id => 'blah')
146
281
  expect(element).to be_instance_of Druid::Elements::Heading
147
282
  end
148
283
 
284
+ it "should find all h6 elements" do
285
+ expect(driver).to receive(:h6s).with(:id => 'blah').and_return([driver])
286
+ elements = page.h6_elements(:id => 'blah')
287
+ expect(elements[0]).to be_instance_of Druid::Elements::Heading
288
+ end
289
+
149
290
  it "should find a paragraph element" do
150
291
  expect(driver).to receive(:p).with(:id => 'blah').and_return(driver)
151
292
  element = page.paragraph_element(:id => 'blah')
152
293
  expect(element).to be_instance_of Druid::Elements::Paragraph
153
294
  end
154
295
 
296
+ it "should find all paragraph elements" do
297
+ expect(driver).to receive(:ps).with(:id => 'blah').and_return([driver])
298
+ elements = page.paragraph_elements(:id => 'blah')
299
+ expect(elements[0]).to be_instance_of Druid::Elements::Paragraph
300
+ end
301
+
155
302
  it "should find a file field element" do
156
303
  expect(driver).to receive(:file_field).with(:id => 'blah').and_return(driver)
157
304
  element = page.file_field_element(:id => 'blah')