fluent 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +9 -0
  3. data/lib/fluent/errors.rb +1 -0
  4. data/lib/fluent/factory.rb +9 -0
  5. data/lib/fluent/generators.rb +65 -4
  6. data/lib/fluent/platform_watir/platform_object.rb +92 -3
  7. data/lib/fluent/platform_watir/platform_web_elements/ordered_list.rb +26 -0
  8. data/lib/fluent/platform_watir/platform_web_elements/table.rb +25 -0
  9. data/lib/fluent/platform_watir/platform_web_elements/table_row.rb +27 -0
  10. data/lib/fluent/platform_watir/platform_web_elements/text_area.rb +21 -0
  11. data/lib/fluent/platform_watir/platform_web_elements/text_field.rb +4 -0
  12. data/lib/fluent/platform_watir/platform_web_elements/unordered_list.rb +26 -0
  13. data/lib/fluent/platform_watir/platform_web_elements/web_element.rb +7 -0
  14. data/lib/fluent/version.rb +1 -1
  15. data/lib/fluent/web_elements.rb +20 -0
  16. data/lib/fluent/web_elements/button.rb +6 -1
  17. data/lib/fluent/web_elements/cell.rb +3 -0
  18. data/lib/fluent/web_elements/checkbox.rb +3 -1
  19. data/lib/fluent/web_elements/div.rb +2 -0
  20. data/lib/fluent/web_elements/form.rb +18 -0
  21. data/lib/fluent/web_elements/heading.rb +23 -0
  22. data/lib/fluent/web_elements/hidden.rb +18 -0
  23. data/lib/fluent/web_elements/image.rb +18 -0
  24. data/lib/fluent/web_elements/label.rb +18 -0
  25. data/lib/fluent/web_elements/link.rb +2 -0
  26. data/lib/fluent/web_elements/list_item.rb +2 -0
  27. data/lib/fluent/web_elements/option.rb +2 -0
  28. data/lib/fluent/web_elements/ordered_list.rb +19 -1
  29. data/lib/fluent/web_elements/paragraph.rb +2 -0
  30. data/lib/fluent/web_elements/radio.rb +3 -1
  31. data/lib/fluent/web_elements/select_list.rb +2 -0
  32. data/lib/fluent/web_elements/span.rb +3 -0
  33. data/lib/fluent/web_elements/table.rb +32 -0
  34. data/lib/fluent/web_elements/table_row.rb +38 -0
  35. data/lib/fluent/web_elements/text_area.rb +6 -0
  36. data/lib/fluent/web_elements/text_field.rb +3 -0
  37. data/lib/fluent/web_elements/unordered_list.rb +20 -1
  38. data/spec/factory_spec.rb +7 -0
  39. data/spec/generators/form_generators_spec.rb +42 -0
  40. data/spec/generators/heading_generators_spec.rb +87 -0
  41. data/spec/generators/hidden_generators_spec.rb +49 -0
  42. data/spec/generators/image_generators_spec.rb +42 -0
  43. data/spec/generators/label_generators_spec.rb +49 -0
  44. data/spec/generators/text_area_generators_spec.rb +3 -3
  45. data/spec/generators_spec.rb +5 -0
  46. data/spec/spec_helper.rb +2 -0
  47. data/spec/web_element_watir_spec.rb +6 -0
  48. data/spec/web_elements/button_spec.rb +21 -0
  49. data/spec/web_elements/cell_spec.rb +13 -0
  50. data/spec/web_elements/checkbox_spec.rb +4 -0
  51. data/spec/web_elements/div_spec.rb +9 -0
  52. data/spec/web_elements/form_spec.rb +9 -0
  53. data/spec/web_elements/heading_spec.rb +28 -0
  54. data/spec/web_elements/hidden_spec.rb +9 -0
  55. data/spec/web_elements/image_spec.rb +9 -0
  56. data/spec/web_elements/label_spec.rb +9 -0
  57. data/spec/web_elements/link_spec.rb +9 -0
  58. data/spec/web_elements/list_item_spec.rb +9 -0
  59. data/spec/web_elements/option_spec.rb +9 -0
  60. data/spec/web_elements/ordered_list_spec.rb +42 -0
  61. data/spec/web_elements/paragraph_spec.rb +9 -0
  62. data/spec/web_elements/radio_spec.rb +4 -0
  63. data/spec/web_elements/select_list_spec.rb +4 -0
  64. data/spec/web_elements/span_spec.rb +9 -0
  65. data/spec/web_elements/table_row_spec.rb +47 -0
  66. data/spec/web_elements/table_spec.rb +54 -0
  67. data/spec/web_elements/text_area_spec.rb +27 -0
  68. data/spec/web_elements/text_field_spec.rb +13 -0
  69. data/spec/web_elements/unordered_list_spec.rb +42 -0
  70. metadata +61 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 865fd6926b13f1303315bd27fdf75450a651bd96
4
- data.tar.gz: 2580430caa258e3d409a0b231d7b39a18d804f66
3
+ metadata.gz: 53bf5738dcf39690dc07ba2dddb31c18a6258738
4
+ data.tar.gz: 6d0786f388d7317f0b973da560f9acb1e9fb72e6
5
5
  SHA512:
6
- metadata.gz: 28d8369390312cf460c41cce6fe3cb321cdef0af8b22418477bf222be8e062e7a92d9ce1297a3b7b8f8220a6f09094823e77234e1333a930cb9cf3edbf2be6e9
7
- data.tar.gz: aaa9eb4cef3b0ab94213c3e408703bcf93663c9ce6baa89151809ae6fa682e6e5a98a4f27959eceda43a7f331c829cd487c081ee40005d3ad22d74301bad3d99
6
+ metadata.gz: 44341db669c208f238ee6ea76845f7de15d441a116bfd7865c51d0bcf1230acc7d260416c254f1c543b9bf2af5bb83f93a7d368466a7748d7ddb9e508db9b879
7
+ data.tar.gz: 9153f09f1b8a7b31e847ae69e3de19281dd5543f4dbd51da2a77f479e2b387f5f8182760bdc5209ceff11fc5938e068fe42a379f65f2c28ca0c7363d1ecc7fc0
data/HISTORY.md CHANGED
@@ -1,6 +1,15 @@
1
1
  Change Log and History
2
2
  ======================
3
3
 
4
+ Version 0.3.0 / 2013-10-29
5
+ --------------------------
6
+
7
+ This release has some added generators: label, hidden, headings (h1 through h6), form, and image. That means you can now interact with those elements via the Fluent interface.
8
+
9
+ Elements now map their type (i.e., Button) and their tag (i.e., "submit"). This allows for certain actions like getting the parent of elements, which is now an action that is available on each element.
10
+
11
+ Tables rows have been added as an element and that was done so that tables could be enumerated. This means table rows and columns can be more easily discovered. Finally, lists (unordered and ordered) have also been enumerated so that it is possible to get the text contents of those lists.
12
+
4
13
  Version 0.2.0 / 2013-10-21
5
14
  --------------------------
6
15
 
@@ -3,6 +3,7 @@ module Fluent
3
3
  class NoUrlForDefinition < StandardError; end
4
4
  class NoTitleForDefinition < StandardError; end
5
5
  class TitleNotMatched < StandardError; end
6
+ class UrlNotMatched < StandardError; end
6
7
  class UnableToCreatePlatform < StandardError; end
7
8
  end
8
9
  end
@@ -7,9 +7,12 @@ module Fluent
7
7
  # @param block [Proc] logic to execute within the context of the definition
8
8
  # @return [Object] instance of the definition
9
9
  def on(definition, visit=false, &block)
10
+ definition = get_object_for(definition) if definition.is_a? String
11
+
10
12
  return @active if @active.kind_of?(definition)
11
13
  @active = definition.new(@browser, visit)
12
14
  block.call @active if block
15
+
13
16
  @active
14
17
  end
15
18
 
@@ -26,6 +29,12 @@ module Fluent
26
29
  end
27
30
 
28
31
  alias_method :on_visit, :on_view
32
+
33
+ def get_object_for(definition)
34
+ definition.split('::').inject(Object) do |obj, name|
35
+ obj.const_get(name)
36
+ end
37
+ end
29
38
 
30
39
  end
31
40
  end
@@ -8,6 +8,12 @@ module Fluent
8
8
  define_method('view') do
9
9
  platform.visit(url)
10
10
  end
11
+
12
+ define_method('check_url') do
13
+ msg = "Expected url: '#{url}'; Actual url: '#{browser.url}'"
14
+ valid_url = url == browser.url
15
+ raise Fluent::Errors::UrlNotMatched, msg unless valid_url
16
+ end
11
17
  end
12
18
 
13
19
  def title_is(title=nil)
@@ -48,6 +54,7 @@ module Fluent
48
54
  end
49
55
 
50
56
  common_definition_methods(identifier, locator, __method__)
57
+ common_definition_methods(identifier, locator, 'a')
51
58
  end
52
59
 
53
60
  def paragraph(identifier, locator)
@@ -56,6 +63,7 @@ module Fluent
56
63
  end
57
64
 
58
65
  common_definition_methods(identifier, locator, __method__)
66
+ common_definition_methods(identifier, locator, 'p')
59
67
  end
60
68
 
61
69
  def div(identifier, locator)
@@ -92,6 +100,7 @@ module Fluent
92
100
  end
93
101
 
94
102
  common_definition_methods(identifier, locator, __method__)
103
+ common_definition_methods(identifier, locator, 'textfield')
95
104
  end
96
105
 
97
106
  def text_area(identifier, locator)
@@ -104,6 +113,7 @@ module Fluent
104
113
  end
105
114
 
106
115
  common_definition_methods(identifier, locator, __method__)
116
+ common_definition_methods(identifier, locator, 'textarea')
107
117
  end
108
118
 
109
119
  def checkbox(identifier, locator)
@@ -158,6 +168,7 @@ module Fluent
158
168
  alias_method "set_#{identifier}".to_sym, "select_#{identifier}".to_sym
159
169
 
160
170
  common_definition_methods(identifier, locator, __method__)
171
+ common_definition_methods(identifier, locator, 'radio_button')
161
172
  end
162
173
 
163
174
  def ordered_list(identifier, locator)
@@ -204,14 +215,64 @@ module Fluent
204
215
  common_definition_methods(identifier, locator, 'td')
205
216
  end
206
217
 
207
- alias_method :radio_button, :radio ###
208
- alias_method :textarea, :text_area ###
209
- alias_method :textfield, :text_field ###
210
- alias_method :a, :link ###
218
+ def label(identifier, locator)
219
+ define_method(identifier) do
220
+ return platform.label_text(locator.clone)
221
+ end
222
+
223
+ common_definition_methods(identifier, locator, __method__)
224
+ end
225
+
226
+ def hidden(identifier, locator)
227
+ define_method(identifier) do
228
+ return platform.hidden_value(locator.clone)
229
+ end
230
+
231
+ common_definition_methods(identifier, locator, __method__)
232
+ end
233
+
234
+ def form(identifier, locator)
235
+ common_definition_methods(identifier, locator, __method__)
236
+ end
237
+
238
+ def image(identifier, locator)
239
+ common_definition_methods(identifier, locator, __method__)
240
+ common_definition_methods(identifier, locator, 'img')
241
+ end
242
+
243
+ [:h1, :h2, :h3, :h4, :h5, :h6].each do |method|
244
+ define_method(method) do |identifier, locator|
245
+ define_method(identifier) do
246
+ platform_method = "#{method.to_s}_text"
247
+ return platform.send(platform_method, locator.clone)
248
+ end
249
+
250
+ common_definition_methods(identifier, locator, method)
251
+ end
252
+ end
253
+
254
+ #def h1(identifier, locator)
255
+
256
+ #end
257
+
258
+ #def h2(identifier, locator)
259
+
260
+ #end
261
+
262
+ #def h3(identifier, locator)
263
+
264
+ #end
265
+
266
+ alias_method :radio_button, :radio
267
+ alias_method :textarea, :text_area
268
+ alias_method :textfield, :text_field
269
+ alias_method :a, :link
270
+ alias_method :p, :paragraph
211
271
  alias_method :ol, :ordered_list
212
272
  alias_method :ul, :unordered_list
213
273
  alias_method :li, :list_item
214
274
  alias_method :td, :cell
275
+ alias_method :img, :image
215
276
 
216
277
  def common_definition_methods(identifier, locator, method)
217
278
  define_method("#{identifier}_object") do
@@ -115,15 +115,15 @@ module Fluent
115
115
  end
116
116
 
117
117
  def text_area(locator)
118
- reference_web_element('text_area(locator)', WebElements::TextArea, locator)
118
+ reference_web_element('textarea(locator)', WebElements::TextArea, locator)
119
119
  end
120
120
 
121
121
  def text_area_set(locator, value)
122
- access_web_element('text_area(locator).set(value)', locator, value)
122
+ access_web_element('textarea(locator).set(value)', locator, value)
123
123
  end
124
124
 
125
125
  def text_area_get(locator)
126
- access_web_element('text_area(locator).value', locator)
126
+ access_web_element('textarea(locator).value', locator)
127
127
  end
128
128
 
129
129
  def checkbox(locator)
@@ -234,6 +234,89 @@ module Fluent
234
234
  access_web_element('td(locator).text', locator)
235
235
  end
236
236
 
237
+ def label(locator)
238
+ reference_web_element('label(locator)', WebElements::Label, locator)
239
+ end
240
+
241
+ def label_text(locator)
242
+ access_web_element('label(locator).text', locator)
243
+ end
244
+
245
+ def hidden(locator)
246
+ reference_web_element('hidden(locator)', WebElements::Hidden, locator)
247
+ end
248
+
249
+ def hidden_value(locator)
250
+ access_web_element('hidden(locator).value', locator)
251
+ end
252
+
253
+ def h1(locator)
254
+ reference_web_element('h1(locator)', WebElements::Heading, locator)
255
+ end
256
+
257
+ def h1_text(locator)
258
+ access_web_element('h1(locator).text', locator)
259
+ end
260
+
261
+ def h2(locator)
262
+ reference_web_element('h2(locator)', WebElements::Heading, locator)
263
+ end
264
+
265
+ def h2_text(locator)
266
+ access_web_element('h2(locator).text', locator)
267
+ end
268
+
269
+ def h3(locator)
270
+ reference_web_element('h3(locator)', WebElements::Heading, locator)
271
+ end
272
+
273
+ def h3_text(locator)
274
+ access_web_element('h3(locator).text', locator)
275
+ end
276
+
277
+ def h4(locator)
278
+ reference_web_element('h4(locator)', WebElements::Heading, locator)
279
+ end
280
+
281
+ def h4_text(locator)
282
+ access_web_element('h4(locator).text', locator)
283
+ end
284
+
285
+ def h5(locator)
286
+ reference_web_element('h5(locator)', WebElements::Heading, locator)
287
+ end
288
+
289
+ def h5_text(locator)
290
+ access_web_element('h5(locator).text', locator)
291
+ end
292
+
293
+ def h6(locator)
294
+ reference_web_element('h6(locator)', WebElements::Heading, locator)
295
+ end
296
+
297
+ def h6_text(locator)
298
+ access_web_element('h6(locator).text', locator)
299
+ end
300
+
301
+ def form(locator)
302
+ reference_web_element('form(locator)', WebElements::Form, locator)
303
+ end
304
+
305
+ def image(locator)
306
+ reference_web_element('image(locator)', WebElements::Image, locator)
307
+ end
308
+
309
+ alias_method :radio_button, :radio
310
+ alias_method :textarea, :text_area
311
+ alias_method :textfield, :text_field
312
+ alias_method :a, :link
313
+ alias_method :p, :paragraph
314
+ alias_method :ol, :ordered_list
315
+ alias_method :ul, :unordered_list
316
+ alias_method :li, :list_item
317
+ alias_method :td, :cell
318
+ alias_method :img, :image
319
+
237
320
  # This method is called by any platform methods that require getting
238
321
  # an object reference.
239
322
  #
@@ -274,6 +357,12 @@ module Fluent
274
357
  end
275
358
  end
276
359
 
360
+ # This require brings in the high-level web element mapping calls.
361
+ require 'fluent/web_elements'
362
+
363
+ # The statements below are used to bring in all of the web elements that
364
+ # Fluent recognizes. /web_elements/web_element must be brought in first
365
+ # so that happens and then it is rejected from being required twice.
277
366
  require 'fluent/web_elements/web_element'
278
367
  file_list = Dir["#{File.dirname(__FILE__)}/../web_elements/**/*.rb"].reject { |file| file =~ /web_element.rb/ }
279
368
  file_list.each { |file| require file }
@@ -0,0 +1,26 @@
1
+ module Fluent
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module OrderedList
5
+
6
+ # @return [Fluent::WebElements::ListItem]
7
+ def [](index)
8
+ ::Fluent::WebElements::ListItem.new(children[index], :platform => :watir_webdriver)
9
+ end
10
+
11
+ def list_items
12
+ web_element.ols(:xpath => list_item_xpath)
13
+ end
14
+
15
+ def children
16
+ list_items.find_all { |item| item.parent == web_element }
17
+ end
18
+
19
+ def items
20
+ children.size
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Fluent
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module Table
5
+
6
+ def [](index)
7
+ index = find_index_by_title(index) if index.kind_of?(String)
8
+ return nil unless index
9
+ initialize_row(web_element[index], :platform => :watir_webdriver)
10
+ end
11
+
12
+ def rows
13
+ web_element.wd.find_elements(:xpath, row_xpath).size
14
+ end
15
+
16
+ def find_index_by_title(row_title)
17
+ web_element.rows.find_index do |row|
18
+ row.cells.any? { |col| col.text.include? row_title }
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module Fluent
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module TableRow
5
+
6
+ # @return [Fluent::WebElements::Cell]
7
+ def [](index)
8
+ index = find_by_title(index) if index.kind_of?(String)
9
+ return nil unless index && columns >= index + 1
10
+ ::Fluent::WebElements::Cell.new(web_element[index], :platform => :watir_webdriver)
11
+ end
12
+
13
+ def columns
14
+ web_element.wd.find_elements(:xpath, cell_xpath).size
15
+ end
16
+
17
+ def find_by_title(column_text)
18
+ table = web_element.parent
19
+ table = table.parent if table.tag_name == 'tbody'
20
+ first_row = table[0]
21
+ first_row.cells.find_index {|column| column.text.include? column_text}
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module Fluent
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module TextArea
5
+
6
+ def value
7
+ web_element.value
8
+ end
9
+
10
+ def value=(value)
11
+ web_element.set(value)
12
+ end
13
+
14
+ def clear
15
+ web_element.wd.clear
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,6 +2,10 @@ module Fluent
2
2
  module Platforms
3
3
  module WatirWebDriver
4
4
  module TextField
5
+
6
+ def value
7
+ web_element.value
8
+ end
5
9
 
6
10
  def value=(text)
7
11
  web_element.set(text)
@@ -0,0 +1,26 @@
1
+ module Fluent
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module UnorderedList
5
+
6
+ # @return [Fluent::WebElements::ListItem]
7
+ def [](index)
8
+ ::Fluent::WebElements::ListItem.new(children[index], :platform => :watir_webdriver)
9
+ end
10
+
11
+ def list_items
12
+ web_element.uls(:xpath => list_item_xpath)
13
+ end
14
+
15
+ def children
16
+ list_items.find_all { |item| item.parent == web_element }
17
+ end
18
+
19
+ def items
20
+ children.size
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end