druid-ts 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/ChangeLog +15 -0
  4. data/Gemfile +1 -0
  5. data/druid.gemspec +1 -0
  6. data/features/button.feature +2 -1
  7. data/features/checkbox.feature +2 -1
  8. data/features/div.feature +2 -1
  9. data/features/element.feature +2 -0
  10. data/features/file_field.feature +2 -1
  11. data/features/form.feature +2 -1
  12. data/features/hidden_field.feature +2 -1
  13. data/features/html/nested_elements.html +20 -0
  14. data/features/image.feature +2 -1
  15. data/features/javascript.feature +13 -0
  16. data/features/link.feature +1 -1
  17. data/features/list_item.feature +2 -1
  18. data/features/nested_elements.feature +12 -0
  19. data/features/ordered_list.feature +2 -1
  20. data/features/paragraph.feature +2 -1
  21. data/features/radio_button.feature +2 -1
  22. data/features/sample-app/public/jquery-1.3.2.js +4376 -0
  23. data/features/sample-app/public/jquery.html +28 -0
  24. data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
  25. data/features/sample-app/public/prototype.html +32 -0
  26. data/features/sample-app/sample_app.rb +30 -0
  27. data/features/select_list.feature +13 -1
  28. data/features/span.feature +2 -1
  29. data/features/step_definations/button_steps.rb +4 -0
  30. data/features/step_definations/checkbox_steps.rb +4 -0
  31. data/features/step_definations/div_steps.rb +4 -0
  32. data/features/step_definations/element_steps.rb +8 -0
  33. data/features/step_definations/file_field_steps.rb +4 -0
  34. data/features/step_definations/form_steps.rb +4 -0
  35. data/features/step_definations/hidden_field_steps.rb +4 -0
  36. data/features/step_definations/image_steps.rb +4 -0
  37. data/features/step_definations/javasript_steps.rb +29 -0
  38. data/features/step_definations/list_item_steps.rb +4 -0
  39. data/features/step_definations/nested_elements_steps.rb +15 -0
  40. data/features/step_definations/ordered_list_steps.rb +4 -0
  41. data/features/step_definations/paragraph_steps.rb +4 -0
  42. data/features/step_definations/radio_button_steps.rb +4 -0
  43. data/features/step_definations/select_list_steps.rb +16 -0
  44. data/features/step_definations/span_steps.rb +4 -0
  45. data/features/step_definations/table_cell_steps.rb +4 -0
  46. data/features/step_definations/table_steps.rb +4 -0
  47. data/features/step_definations/text_area_steps.rb +4 -0
  48. data/features/step_definations/text_field_steps.rb +8 -0
  49. data/features/step_definations/unordered_list_steps.rb +4 -0
  50. data/features/support/ajax_test_environment.rb +26 -0
  51. data/features/support/url_helper.rb +1 -0
  52. data/features/table.feature +2 -1
  53. data/features/table_cell.feature +2 -1
  54. data/features/text_area.feature +2 -1
  55. data/features/text_field.feature +7 -1
  56. data/features/unordered_list.feature +2 -1
  57. data/lib/druid.rb +39 -1
  58. data/lib/druid/accessors.rb +230 -82
  59. data/lib/druid/elements/element.rb +7 -1
  60. data/lib/druid/elements/ordered_list.rb +18 -3
  61. data/lib/druid/elements/select_list.rb +24 -0
  62. data/lib/druid/elements/text_area.rb +1 -1
  63. data/lib/druid/elements/text_field.rb +4 -0
  64. data/lib/druid/elements/unordered_list.rb +18 -3
  65. data/lib/druid/javascript/jquery.rb +12 -0
  66. data/lib/druid/javascript/prototype.rb +12 -0
  67. data/lib/druid/javascript_framework_facade.rb +72 -0
  68. data/lib/druid/version.rb +1 -1
  69. data/spec/druid/druid_spec.rb +18 -3
  70. data/spec/druid/elements/element_spec.rb +5 -0
  71. data/spec/druid/elements/ordered_list_spec.rb +12 -4
  72. data/spec/druid/elements/select_list_spec.rb +17 -0
  73. data/spec/druid/elements/text_area_spec.rb +1 -1
  74. data/spec/druid/elements/text_field_spec.rb +5 -0
  75. data/spec/druid/elements/unordered_list_spec.rb +12 -4
  76. data/spec/druid/javascript_framework_facade_spec.rb +59 -0
  77. metadata +36 -1
@@ -119,6 +119,12 @@ module Druid
119
119
  element.enabled?
120
120
  end
121
121
 
122
+ #
123
+ # return true if the element is not enabled
124
+ def disabled?
125
+ not enabled?
126
+ end
127
+
122
128
  def visible?
123
129
  element.visible?
124
130
  end
@@ -279,7 +285,7 @@ module Druid
279
285
  # delegate calls to driver element
280
286
  def method_missing(m, *args, &block)
281
287
  puts "*** DEPRECATION WARNING"
282
- puts "*** You are calling a method named #{m}."
288
+ puts "*** You are calling a method named #{m} at #{caller[0]}."
283
289
  puts "*** This method does not exist in druid so it is being passed to the driver."
284
290
  puts "*** This feature will be removed in the near future."
285
291
  puts "*** Please change your code to call the correct druid method."
@@ -8,12 +8,11 @@ module Druid
8
8
  end
9
9
 
10
10
  def [](idx)
11
- li = element.li(:xpath, ".//li[#{idx+1}]")
12
- Druid::Elements::ListItem.new(li)
11
+ Druid::Elements::ListItem.new(children[idx])
13
12
  end
14
13
 
15
14
  def items
16
- element.lis.size
15
+ children.size
17
16
  end
18
17
 
19
18
  def each
@@ -22,6 +21,22 @@ module Druid
22
21
  end
23
22
  end
24
23
 
24
+ protected
25
+
26
+ def child_xpath
27
+ ".//child::li"
28
+ end
29
+
30
+ private
31
+
32
+ def children
33
+ list_items.find_all { |item| item.parent == element }
34
+ end
35
+
36
+ def list_items
37
+ element.ols(:xpath => child_xpath)
38
+ end
39
+
25
40
  end
26
41
 
27
42
  Druid::Elements.tag_to_class[:ol] = Druid::Elements::OrderedList
@@ -20,6 +20,30 @@ module Druid
20
20
  def select(value)
21
21
  element.select(value)
22
22
  end
23
+
24
+ #
25
+ # @return [Array<sTRING>] An array of strings representing the text value of the currently selected options.
26
+ #
27
+ def selected_options
28
+ element.selected_options.map { |e| e.text }.compact
29
+ end
30
+
31
+ #
32
+ # Returns true if the select list has one or more options where text or label matches the given value.
33
+ #
34
+ # @param [String, Regexp] value A value
35
+ # @return [Boolean]
36
+ def include? value
37
+ element.include? value
38
+ end
39
+
40
+ #
41
+ # Returns true if any of the selected options' text or label match the given value.
42
+ # @param [String, Regexp] value A value
43
+ # @return [Boolean]
44
+ def selected? value
45
+ element.selected? value
46
+ end
23
47
  end
24
48
 
25
49
  Druid::Elements.tag_to_class[:select] = Druid::Elements::SelectList
@@ -14,7 +14,7 @@ module Druid
14
14
  # Set the value of the TextArea
15
15
  #
16
16
  def value=(new_value)
17
- element.send_keys(new_value)
17
+ element.set(new_value)
18
18
  end
19
19
 
20
20
  end
@@ -12,6 +12,10 @@ module Druid
12
12
  def value=(new_value)
13
13
  element.set(new_value)
14
14
  end
15
+
16
+ def append text
17
+ element.send_keys text
18
+ end
15
19
  end
16
20
 
17
21
  Druid::Elements.type_to_class[:text] = Druid::Elements::TextField
@@ -7,12 +7,11 @@ module Druid
7
7
  end
8
8
 
9
9
  def [](idx)
10
- li = element.li(:xpath,".//li[#{idx+1}]")
11
- Druid::Elements::ListItem.new(li)
10
+ Druid::Elements::ListItem.new(children[idx])
12
11
  end
13
12
 
14
13
  def items
15
- element.lis.size
14
+ children.size
16
15
  end
17
16
 
18
17
  def each
@@ -20,6 +19,22 @@ module Druid
20
19
  yield self[index-1]
21
20
  end
22
21
  end
22
+
23
+ protected
24
+
25
+ def child_xpath
26
+ ".//child::li"
27
+ end
28
+
29
+ private
30
+
31
+ def children
32
+ list_items.find_all { |item| item.parent == element}
33
+ end
34
+
35
+ def list_items
36
+ element.uls(:xpath => child_xpath)
37
+ end
23
38
  end
24
39
 
25
40
  Druid::Elements.tag_to_class[:ul] = Druid::Elements::UnOrderedList
@@ -0,0 +1,12 @@
1
+ module Druid
2
+ module Javascript
3
+ module JQuery
4
+ #
5
+ # return the number of pending ajax requests
6
+ #
7
+ def self.pending_requests
8
+ 'return jQuery.active'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Druid
2
+ module Javascript
3
+ module Prototype
4
+ #
5
+ # return the number of pending ajax requests
6
+ #
7
+ def self.pending_requests
8
+ 'return Ajax.activeRequestCount'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,72 @@
1
+ require 'druid/javascript/jquery'
2
+ require 'druid/javascript/prototype'
3
+
4
+ module Druid
5
+ #
6
+ # Provide hooks into different common Javascript Frameworks.
7
+ # Currently this module only supports jQuery and Prototype but it
8
+ # has ability for you to plug your own framework into it and
9
+ # therefore have it work with this gem. You do this by calling the
10
+ # #add_framework method. The module you provide must implement the
11
+ # necessary methods. Please look at the jQuery or Prototype
12
+ # implementations to determine the necessary methods
13
+ #
14
+ module JavascriptFrameworkFacade
15
+
16
+ class << self
17
+ #
18
+ # Set the framework to use
19
+ #
20
+ # @param [Symbol] the framework to use. :jquery and :prototype
21
+ # are supported
22
+ #
23
+ def framework=(framework)
24
+ initialize_script_builder unless @builder
25
+ raise unknown_framework(framework) unless @builder[framework]
26
+ @framework = framework
27
+ end
28
+
29
+ def add_framework(key, value)
30
+ raise invalid_framework unless value.respond_to? :pending_requests
31
+ initialize_script_builder unless @builder
32
+ @builder[key] = value
33
+ end
34
+
35
+ #
36
+ # Get the framework that will be used
37
+ #
38
+ def framework
39
+ @framework
40
+ end
41
+
42
+ def script_builder
43
+ initialize_script_builder unless @builder
44
+ @builder[@framework]
45
+ end
46
+
47
+ #
48
+ # get the javascript to determine number of pending requests
49
+ #
50
+ def pending_requests
51
+ script_builder.pending_requests
52
+ end
53
+
54
+ private
55
+
56
+ def initialize_script_builder
57
+ @builder = {
58
+ :jquery => Druid::Javascript::JQuery,
59
+ :prototype => Druid::Javascript::Prototype
60
+ }
61
+ end
62
+
63
+ def unknown_framework(framework)
64
+ "You specified the Javascript framework #{framework} and it is unknow to the system"
65
+ end
66
+
67
+ def invalid_framework
68
+ "The Javascript framework you provided does not implement the necessary methods"
69
+ end
70
+ end
71
+ end
72
+ end
data/lib/druid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Druid
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -144,7 +144,8 @@ describe Druid do
144
144
  end
145
145
 
146
146
  it "should know how to clear all of the cookies from the browser" do
147
- expect(driver).to receive(:clear_cookies)
147
+ expect(driver).to receive(:cookies).and_return(driver)
148
+ expect(driver).to receive(:clear)
148
149
  druid.clear_cookies
149
150
  end
150
151
 
@@ -153,9 +154,23 @@ describe Druid do
153
154
  druid.save_screenshot('tim.png')
154
155
  end
155
156
 
156
- end
157
- end
157
+ it "should wait until there are no pending ajax requests" do
158
+ expect(Druid::JavascriptFrameworkFacade).to receive(:pending_requests).and_return('pending requests')
159
+ expect(driver).to receive(:execute_script).with('pending requests').and_return(0)
160
+ druid.wait_for_ajax
161
+ end
162
+
163
+ it "should set the javascript framework" do
164
+ expect(Druid::JavascriptFrameworkFacade).to receive(:framework=)
165
+ Druid.javascript_framework = :foo
166
+ end
158
167
 
168
+ it "should add the javascript framework" do
169
+ expect(Druid::JavascriptFrameworkFacade).to receive(:add_framework)
170
+ Druid.add_framework(:foo, :bar)
171
+ end
159
172
 
173
+ end
174
+ end
160
175
 
161
176
  end
@@ -146,5 +146,10 @@ describe Druid::Elements::Element do
146
146
  expect(we).to receive(:focus)
147
147
  element.focus
148
148
  end
149
+
150
+ it "should know if the element is disabled" do
151
+ expect(we).to receive(:enabled?).and_return(false)
152
+ expect(element).to be_disabled
153
+ end
149
154
  end
150
155
  end
@@ -16,13 +16,21 @@ describe Druid::Elements::OrderedList do
16
16
  let(:ol) { Druid::Elements::OrderedList.new(element) }
17
17
 
18
18
  it "should return a list item when indexed" do
19
- expect(element).to receive(:li)
20
- expect(ol[1]).to be_instance_of Druid::Elements::ListItem
19
+ allow(element).to receive(:ols).and_return(element)
20
+ allow(element).to receive(:find_all).and_return([element])
21
+ allow(element).to receive(:parent).and_return(element)
22
+ allow(element).to receive(:element).and_return(element)
23
+ allow(element).to receive(:==).and_return(true)
24
+ ol[1]
21
25
  end
22
26
 
23
27
  it "should know how many list items it contains" do
24
- expect(element).to receive_message_chain(:lis, :size).and_return(2)
25
- expect(ol.items).to eql 2
28
+ allow(element).to receive(:ols).and_return(element)
29
+ allow(element).to receive(:find_all).and_return([element])
30
+ allow(element).to receive(:parent).and_return(element)
31
+ allow(element).to receive(:element).and_return(element)
32
+ allow(element).to receive(:==).and_return(true)
33
+ expect(ol.items).to eql 1
26
34
  end
27
35
 
28
36
  it "should iterate over the list items" do
@@ -13,6 +13,7 @@ describe Druid::Elements::SelectList do
13
13
 
14
14
  describe "interface" do
15
15
  let(:element) { double 'element' }
16
+ let(:opts) { [element, element] }
16
17
  let(:select_list) { Druid::Elements::SelectList.new(element) }
17
18
 
18
19
  it "should return an option when indexed" do
@@ -33,5 +34,21 @@ describe Druid::Elements::SelectList do
33
34
  it "should register with tag_name :select" do
34
35
  expect(Druid::Elements.element_class_for(:select)).to be Druid::Elements::SelectList
35
36
  end
37
+
38
+ it "should return an array of selected options" do
39
+ allow(element).to receive(:selected_options).and_return(opts)
40
+ allow(element).to receive(:text).and_return(element)
41
+ expect(select_list.selected_options).to eql opts
42
+ end
43
+
44
+ it "should know if it includes some value" do
45
+ expect(element).to receive(:include?).with('blah').and_return(true)
46
+ select_list.include?('blah')
47
+ end
48
+
49
+ it "should know if an option is selected" do
50
+ expect(element).to receive(:selected?).with("blah").and_return(true)
51
+ select_list.selected?('blah')
52
+ end
36
53
  end
37
54
  end
@@ -20,7 +20,7 @@ describe Druid::Elements::TextArea do
20
20
  let(:element) { double "element" }
21
21
  let(:text_area) { Druid::Elements::TextArea.new(element) }
22
22
  it "should set its' value" do
23
- expect(element).to receive(:send_keys).with('test')
23
+ expect(element).to receive(:set).with('test')
24
24
  text_area.value = 'test'
25
25
  end
26
26
 
@@ -27,5 +27,10 @@ describe Druid::Elements::TextField do
27
27
  it "should register with type :password" do
28
28
  expect(Druid::Elements.element_class_for(:input, :password)).to be Druid::Elements::TextField
29
29
  end
30
+
31
+ it "should append text" do
32
+ expect(element).to receive(:send_keys).with('abc')
33
+ text_field.append('abc')
34
+ end
30
35
  end
31
36
  end
@@ -16,13 +16,21 @@ describe Druid::Elements::UnOrderedList do
16
16
  let(:ul) { Druid::Elements::UnOrderedList.new(element) }
17
17
 
18
18
  it "should return a list item when indexed" do
19
- expect(element).to receive(:li)
20
- expect(ul[1]).to be_instance_of Druid::Elements::ListItem
19
+ allow(element).to receive(:uls).and_return(element)
20
+ allow(element).to receive(:find_all).and_return([element])
21
+ allow(element).to receive(:parent).and_return(element)
22
+ allow(element).to receive(:element).and_return(element)
23
+ allow(element).to receive(:==).and_return(true)
24
+ ul[1]
21
25
  end
22
26
 
23
27
  it "should know how many items it contains" do
24
- expect(element).to receive_message_chain(:lis, :size).and_return(3)
25
- expect(ul.items).to eql 3
28
+ allow(element).to receive(:uls).and_return(element)
29
+ allow(element).to receive(:find_all).and_return([element])
30
+ allow(element).to receive(:parent).and_return(element)
31
+ allow(element).to receive(:element).and_return(element)
32
+ allow(element).to receive(:==).and_return(true)
33
+ expect(ul.items).to eql 1
26
34
  end
27
35
 
28
36
  it "should know how to iterate over the items" do
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'druid/javascript/jquery'
3
+
4
+ class TestClass
5
+ include Druid::JavascriptFrameworkFacade
6
+ end
7
+
8
+ describe Druid::JavascriptFrameworkFacade do
9
+ let(:facade) { Druid::JavascriptFrameworkFacade }
10
+
11
+ it "should allow the selection of a javascript framework" do
12
+ facade.framework = :jquery
13
+ expect(facade.framework).to eql :jquery
14
+ end
15
+
16
+ it "should register the jQuery script builder" do
17
+ facade.framework = :jquery
18
+ expect(facade.script_builder).to eql Druid::Javascript::JQuery
19
+ end
20
+
21
+ it "should return script for pending requests in jQuery" do
22
+ facade.framework = :jquery
23
+ expect(facade.pending_requests).to eql 'return jQuery.active'
24
+ end
25
+
26
+ it "should register the Prototype script builder" do
27
+ facade.framework = :prototype
28
+ expect(facade.script_builder).to eql Druid::Javascript::Prototype
29
+ end
30
+
31
+ it "should return script for pending requests in Prototype" do
32
+ facade.framework = :prototype
33
+ expect(facade.pending_requests).to eql "return Ajax.activeRequestCount"
34
+ end
35
+
36
+ it "should not allow you to set the framework to one it does not know about" do
37
+ expect{ facade.framework = :blah }.to raise_error
38
+ end
39
+
40
+ it "should allow you to add a new javascript framework" do
41
+ module GoodFake
42
+ def self.pending_requests
43
+ "fake"
44
+ end
45
+ end
46
+
47
+ facade.add_framework(:blah, GoodFake)
48
+ facade.framework = :blah
49
+ expect(facade.pending_requests).to eql "fake"
50
+ end
51
+
52
+ it "should not allow you to add a new javascript framework that is invalid" do
53
+ module BadFake
54
+ def self.blah
55
+ end
56
+ end
57
+ expect{ facade.add_framework(:blah, BadFake) }.to raise_error
58
+ end
59
+ end