druid-ts 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +18 -3
  3. data/ChangeLog +27 -0
  4. data/Gemfile +9 -7
  5. data/README.md +2 -2
  6. data/Rakefile +1 -1
  7. data/druid.gemspec +6 -5
  8. data/features/async.feature +2 -10
  9. data/features/audio.feature +20 -24
  10. data/features/element.feature +31 -0
  11. data/features/html/multi_elements.html +1 -0
  12. data/features/html/static_elements.html +5 -11
  13. data/features/image.feature +4 -0
  14. data/features/italic.feature +21 -0
  15. data/features/link.feature +8 -0
  16. data/features/multi_elements.feature +6 -0
  17. data/features/{html → sample-app/public}/04-Death_Becomes_Fur.mp4 +0 -0
  18. data/features/{html → sample-app/public}/04-Death_Becomes_Fur.oga +0 -0
  19. data/features/sample-app/public/audio_video.html +19 -0
  20. data/features/section.feature +4 -0
  21. data/features/select_list.feature +1 -1
  22. data/features/step_definations/audio_steps.rb +26 -10
  23. data/features/step_definations/div_steps.rb +1 -1
  24. data/features/step_definations/element_steps.rb +44 -0
  25. data/features/step_definations/image_steps.rb +8 -0
  26. data/features/step_definations/italic_steps.rb +11 -0
  27. data/features/step_definations/multi_elements_steps.rb +17 -0
  28. data/features/step_definations/section_steps.rb +9 -0
  29. data/features/step_definations/select_list_steps.rb +1 -1
  30. data/features/step_definations/table_row_steps.rb +23 -0
  31. data/features/step_definations/video_steps.rb +11 -3
  32. data/features/support/audio_video_page.rb +23 -0
  33. data/features/support/env.rb +1 -1
  34. data/features/support/hooks.rb +0 -4
  35. data/features/support/page.rb +20 -18
  36. data/features/support/persistent_browser.rb +3 -3
  37. data/features/table_row.feature +30 -0
  38. data/features/text_field.feature +0 -1
  39. data/features/video.feature +24 -7
  40. data/lib/druid.rb +22 -4
  41. data/lib/druid/accessors.rb +81 -5
  42. data/lib/druid/assist.rb +47 -1
  43. data/lib/druid/elements.rb +1 -0
  44. data/lib/druid/elements/canvas.rb +0 -13
  45. data/lib/druid/elements/element.rb +101 -26
  46. data/lib/druid/elements/italic.rb +9 -0
  47. data/lib/druid/elements/option.rb +6 -0
  48. data/lib/druid/elements/ordered_list.rb +7 -5
  49. data/lib/druid/elements/text_area.rb +14 -0
  50. data/lib/druid/elements/text_field.rb +1 -1
  51. data/lib/druid/elements/unordered_list.rb +11 -5
  52. data/lib/druid/elements/video.rb +0 -9
  53. data/lib/druid/locator_generator.rb +47 -0
  54. data/lib/druid/section_collection.rb +17 -0
  55. data/lib/druid/version.rb +1 -1
  56. data/spec/druid/accessors_spec.rb +29 -1
  57. data/spec/druid/druid_spec.rb +36 -3
  58. data/spec/druid/element_locators_spec.rb +44 -0
  59. data/spec/druid/elements/canvas_spec.rb +2 -2
  60. data/spec/druid/elements/element_spec.rb +98 -13
  61. data/spec/druid/elements/itatic_spec.rb +20 -0
  62. data/spec/druid/elements/media_spec.rb +61 -0
  63. data/spec/druid/elements/option_spec.rb +11 -0
  64. data/spec/druid/elements/ordered_list_spec.rb +2 -9
  65. data/spec/druid/elements/text_field_spec.rb +1 -1
  66. data/spec/druid/elements/unordered_list_spec.rb +2 -9
  67. data/spec/druid/elements/video_spec.rb +25 -0
  68. data/spec/druid/javascript_framework_facade_spec.rb +2 -2
  69. data/spec/druid/page_factory_spec.rb +1 -1
  70. data/spec/druid/page_section_spec.rb +10 -1
  71. data/spec/spec_helper.rb +1 -1
  72. metadata +49 -16
  73. data/lib/druid/sections.rb +0 -29
@@ -0,0 +1,9 @@
1
+ module Druid
2
+ module Elements
3
+ class Italic < Element
4
+
5
+ end
6
+
7
+ Druid::Elements.tag_to_class[:i] = Druid::Elements::Italic
8
+ end
9
+ end
@@ -2,6 +2,12 @@ module Druid
2
2
  module Elements
3
3
  class Option < Element
4
4
 
5
+ #
6
+ # returns true if the option is selected
7
+ #
8
+ def selected?
9
+ element.selected?
10
+ end
5
11
  end
6
12
 
7
13
  Druid::Elements.tag_to_class[:option] = Druid::Elements::Option
@@ -21,19 +21,21 @@ module Druid
21
21
  end
22
22
  end
23
23
 
24
+ def list_items
25
+ children.collect do |obj|
26
+ Druid::Elements::ListItem.new(obj)
27
+ end
28
+ end
29
+
24
30
  protected
25
31
 
26
32
  def child_xpath
27
- ".//child::li"
33
+ "./child::li"
28
34
  end
29
35
 
30
36
  private
31
37
 
32
38
  def children
33
- list_items.find_all { |item| item.parent == element }
34
- end
35
-
36
- def list_items
37
39
  element.ols(:xpath => child_xpath)
38
40
  end
39
41
 
@@ -12,6 +12,20 @@ module Druid
12
12
  element.set(new_value)
13
13
  end
14
14
 
15
+ #
16
+ # Clear the TextArea
17
+ #
18
+ def clear
19
+ element.clear
20
+ end
21
+
22
+ #
23
+ # append the text to the end of the text in the text area
24
+ #
25
+ def append(text)
26
+ element.append(text)
27
+ end
28
+
15
29
  end
16
30
 
17
31
  Druid::Elements.tag_to_class[:textarea] = Druid::Elements::TextArea
@@ -14,7 +14,7 @@ module Druid
14
14
  end
15
15
 
16
16
  def append text
17
- element.send_keys text
17
+ element.append text
18
18
  end
19
19
  end
20
20
 
@@ -20,19 +20,25 @@ module Druid
20
20
  end
21
21
  end
22
22
 
23
+ #
24
+ # return the ListItem objects that are children of the
25
+ # UnOrderedList
26
+ #
27
+ def list_items
28
+ children.collect do |obj|
29
+ Druid::Elements::ListItem.new(obj)
30
+ end
31
+ end
32
+
23
33
  protected
24
34
 
25
35
  def child_xpath
26
- ".//child::li"
36
+ "./child::li"
27
37
  end
28
38
 
29
39
  private
30
40
 
31
41
  def children
32
- list_items.find_all { |item| item.parent == element}
33
- end
34
-
35
- def list_items
36
42
  element.uls(:xpath => child_xpath)
37
43
  end
38
44
  end
@@ -2,15 +2,6 @@ module Druid
2
2
  module Elements
3
3
  class Video < Media
4
4
 
5
- def height
6
- height = attribute(:height)
7
- return height.to_i if height
8
- end
9
-
10
- def width
11
- width = attribute(:width)
12
- return width.to_i if width
13
- end
14
5
  end
15
6
  Druid::Elements.type_to_class[:video] = Druid::Elements::Video
16
7
  end
@@ -3,71 +3,116 @@ module Druid
3
3
 
4
4
  BASIC_ELEMENTS = [:abbr,
5
5
  :address,
6
+ :animate,
7
+ :animate_motion,
8
+ :animate_transform,
6
9
  :article,
7
10
  :as,
8
11
  :aside,
12
+ :base,
9
13
  :bdi,
10
14
  :bdo,
11
15
  :blockquote,
12
16
  :body,
13
17
  :br,
14
18
  :caption,
19
+ :circle,
15
20
  :cite,
16
21
  :code,
17
22
  :col,
18
23
  :colgroup,
19
24
  :command,
25
+ :cursor,
20
26
  :data,
21
27
  :datalist,
22
28
  :dd,
29
+ :defs,
23
30
  :del,
31
+ :desc,
24
32
  :details,
25
33
  :dfn,
26
34
  :dialog,
35
+ :discard,
27
36
  :dl,
28
37
  :dt,
38
+ :ellipse,
29
39
  :em,
30
40
  :embed,
31
41
  :fieldset,
32
42
  :figcaption,
33
43
  :figure,
44
+ :foot,
34
45
  :footer,
46
+ :foreign_object,
47
+ :g,
35
48
  :head,
36
49
  :header,
37
50
  :hgroup,
38
51
  :hr,
52
+ :html,
39
53
  :ins,
40
54
  :kbd,
41
55
  :keygen,
42
56
  :legend,
57
+ :line,
58
+ :linear_gradient,
59
+ :main,
43
60
  :map,
44
61
  :mark,
62
+ :marker,
45
63
  :menu,
64
+ :menuitem,
65
+ :mesh_gradient,
66
+ :mesh_patch,
67
+ :mesh_row,
46
68
  :meta,
69
+ :metadata,
47
70
  :meter,
71
+ :mpath,
48
72
  :nav,
49
73
  :noscript,
50
74
  :object,
51
75
  :optgroup,
52
76
  :output,
77
+ :p,
53
78
  :param,
79
+ :path,
80
+ :pattern,
81
+ :polygon,
82
+ :polyline,
54
83
  :pre,
55
84
  :progress,
85
+ :q,
86
+ :radial_gradient,
87
+ :rect,
56
88
  :rp,
57
89
  :rt,
58
90
  :ruby,
91
+ :s,
59
92
  :samp,
93
+ :script,
60
94
  :section,
61
95
  :small,
96
+ :source,
97
+ :stop,
62
98
  :strong,
63
99
  :style,
64
100
  :sub,
65
101
  :summary,
66
102
  :sup,
103
+ :switch,
104
+ :symbol,
105
+ :template,
106
+ :text_path,
107
+ :thread,
67
108
  :time,
68
109
  :title,
69
110
  :track,
111
+ :tspan,
112
+ :u,
113
+ :use,
70
114
  :var,
115
+ :view,
71
116
  :wbr]
72
117
 
73
118
  ADVANCED_ELEMENTS = [:text_field,
@@ -82,6 +127,7 @@ module Druid
82
127
  :span,
83
128
  :table,
84
129
  :cell,
130
+ :row,
85
131
  :image,
86
132
  :form,
87
133
  :list_item,
@@ -101,6 +147,7 @@ module Druid
101
147
  :audio,
102
148
  :video,
103
149
  :b,
150
+ :i,
104
151
  :svg]
105
152
 
106
153
  def self.generate_locators(target)
@@ -0,0 +1,17 @@
1
+ module Druid
2
+ class SectionCollection < Array
3
+
4
+ def find_by values_hash
5
+ find do |section|
6
+ values_hash.all? { |key, value| value === section.public_send(key) }
7
+ end
8
+ end
9
+
10
+ def select_by values_hash
11
+ matches = select do |section|
12
+ values_hash.all? { |key, value| value === section.public_send(key) }
13
+ end
14
+ self.class[*matches]
15
+ end
16
+ end
17
+ end
data/lib/druid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Druid
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -205,7 +205,7 @@ describe Druid::Accessors do
205
205
 
206
206
  it "should raise error when it does not have expected title" do
207
207
  expect(driver).to receive(:title).and_return("Not Expected")
208
- expect {druid.has_expected_title? }.to raise_error
208
+ expect {druid.has_expected_title? }.to raise_error "Expected title \'Expected Title\' instead of \'Not Expected\'"
209
209
  end
210
210
  end
211
211
 
@@ -225,6 +225,33 @@ describe Druid::Accessors do
225
225
  end
226
226
  end
227
227
 
228
+ context "using element accessor" do
229
+ class DefaultElementTagToElement
230
+ include Druid
231
+ # verify that the explicit :element tag can be omitted
232
+ # element('button', :element, {:css => 'some css'})
233
+ element('button', { :css => 'some css' })
234
+ elements('button2', { :css => 'some css' })
235
+ end
236
+
237
+ let(:page) { DefaultElementTagToElement.new(driver) }
238
+
239
+ def mock_driver_for(tag)
240
+ expect(driver).to receive(tag).with(:css => 'some css').and_return(driver)
241
+ end
242
+
243
+ it "should default element tag to element" do
244
+ mock_driver_for :element
245
+ page.button_element
246
+ end
247
+
248
+ it "should default elements tag to element" do
249
+ mock_driver_for :elements
250
+ expect(driver).to receive(:map).and_return([])
251
+ page.button2_elements.to_a
252
+ end
253
+ end
254
+
228
255
  describe "using default identifiers" do
229
256
  class DefaultIdentifier
230
257
  include Druid
@@ -699,6 +726,7 @@ describe Druid::Accessors do
699
726
  context "when called on a page object" do
700
727
  it "should generate accessor methods" do
701
728
  expect(druid).to respond_to :logo_element
729
+ expect(druid).to respond_to :logo_loaded?
702
730
  end
703
731
 
704
732
  it "should call a block on the element method when present " do
@@ -70,7 +70,7 @@ describe Druid do
70
70
  end
71
71
  end
72
72
 
73
- context "when created with a watir-webdriver browser" do
73
+ context "when created with a watir browser" do
74
74
  it "should include the Druid module" do
75
75
  expect(druid).to be_kind_of Druid
76
76
  end
@@ -84,6 +84,39 @@ describe Druid do
84
84
  end
85
85
  end
86
86
 
87
+ context "when sent a missing method" do
88
+ it "should not respond to it if the @root_element doesn't exist" do
89
+ expect(nil).to respond_to :to_i
90
+ expect(druid.instance_variable_get(:@root_element)).to be nil
91
+ expect(druid).not_to respond_to :to_i
92
+ expect { druid.to_i }.to raise_error NoMethodError
93
+ end
94
+
95
+ it "should respond to it if the @root_element exists and responds" do
96
+ expect(druid.instance_variable_get(:@root_element)).to be nil
97
+ expect(druid).not_to respond_to :bar
98
+ expect(druid).not_to respond_to :baz
99
+ class Foo
100
+ def bar
101
+ :bar_called
102
+ end
103
+
104
+ private
105
+
106
+ def baz
107
+ end
108
+ end
109
+ druid.instance_variable_set(:@root_element, Foo.new)
110
+
111
+ expect(druid).to respond_to :bar
112
+ expect(druid).not_to respond_to :baz
113
+ expect(druid.bar).to eq :bar_called
114
+ expect { druid.baz }.to raise_error NoMethodError
115
+ expect(druid.respond_to?(:baz, true)).to be false
116
+ expect { druid.send(:baz) }.to raise_error NoMethodError
117
+ end
118
+ end
119
+
87
120
  describe "page level functionality" do
88
121
  context "when using PageObject" do
89
122
 
@@ -114,7 +147,7 @@ describe Druid do
114
147
  end
115
148
 
116
149
  it "should wait until a block returns true" do
117
- expect(driver).to receive(:wait_until).with(5, "too long")
150
+ expect(driver).to receive(:wait_until).with(timeout: 5, message: "too long")
118
151
  druid.wait_until(5, "too long")
119
152
  end
120
153
 
@@ -251,7 +284,7 @@ describe Druid do
251
284
 
252
285
  it "should use the overriden timeout value when set" do
253
286
  Druid.default_page_wait = 10
254
- expect(driver).to receive(:wait_until).with(10, nil)
287
+ expect(driver).to receive(:wait_until).with(timeout: 10, message: nil)
255
288
  druid.wait_until
256
289
  end
257
290
 
@@ -274,6 +274,28 @@ describe Druid::ElementLocators do
274
274
  page.cell_elements
275
275
  end
276
276
 
277
+ it "should find a table row" do
278
+ expect(driver).to receive(:tr).with(:id => 'blah').and_return(driver)
279
+ element = page.row_element(:id => 'blah')
280
+ expect(element).to be_instance_of Druid::Elements::TableRow
281
+ end
282
+
283
+ it "should find a table row using a default identifier" do
284
+ expect(driver).to receive(:tr).with(:index => 0).and_return(driver)
285
+ page.row_element
286
+ end
287
+
288
+ it "should find all table row" do
289
+ expect(driver).to receive(:trs).with(:id => 'blah').and_return([driver])
290
+ elements = page.row_elements(:id => 'blah')
291
+ expect(elements[0]).to be_instance_of Druid::Elements::TableRow
292
+ end
293
+
294
+ it "should find all table rows using no identifier" do
295
+ expect(driver).to receive(:trs).with({}).and_return([driver])
296
+ page.row_elements
297
+ end
298
+
277
299
  it "should find an image element" do
278
300
  expect(driver).to receive(:image).with(:id => 'blah').and_return(driver)
279
301
  element = page.image_element(:id => 'blah')
@@ -703,4 +725,26 @@ describe Druid::ElementLocators do
703
725
  page.b_elements
704
726
  end
705
727
 
728
+ it "should find a i element" do
729
+ expect(driver).to receive(:i).with(:id => 'blah').and_return(driver)
730
+ element = page.i_element(:id => 'blah')
731
+ expect(element).to be_instance_of Druid::Elements::Italic
732
+ end
733
+
734
+ it "should find a i element using a default identifier" do
735
+ expect(driver).to receive(:i).with(:index => 0).and_return(driver)
736
+ page.i_element
737
+ end
738
+
739
+ it "should find all i elements" do
740
+ expect(driver).to receive(:is).with(:id => 'blah').and_return([driver])
741
+ elements = page.i_elements(:id => 'blah')
742
+ expect(elements[0]).to be_instance_of Druid::Elements::Italic
743
+ end
744
+
745
+ it "should find all b elements using no parameters" do
746
+ expect(driver).to receive(:is).with({}).and_return([driver])
747
+ page.i_elements
748
+ end
749
+
706
750
  end