druid-ts 0.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +1 -2
  6. data/ChangeLog +218 -0
  7. data/Gemfile +2 -1
  8. data/README.md +64 -7
  9. data/Rakefile +1 -1
  10. data/druid.gemspec +25 -0
  11. data/features/async.feature +18 -0
  12. data/features/button.feature +42 -1
  13. data/features/checkbox.feature +7 -1
  14. data/features/div.feature +6 -0
  15. data/features/element.feature +100 -0
  16. data/features/file_field.feature +35 -0
  17. data/features/form.feature +12 -6
  18. data/features/frames.feature +57 -0
  19. data/features/heading.feature +164 -0
  20. data/features/hidden_field.feature +6 -0
  21. data/features/html/async.html +18 -0
  22. data/features/html/frame_1.html +18 -0
  23. data/features/html/frame_2.html +16 -0
  24. data/features/html/frame_3.html +14 -0
  25. data/features/html/frames.html +12 -0
  26. data/features/html/iframes.html +12 -0
  27. data/features/html/modal.html +17 -0
  28. data/features/html/modal_1.html +38 -0
  29. data/features/html/modal_2.html +27 -0
  30. data/features/html/nested_elements.html +52 -0
  31. data/features/html/nested_frame_1.html +1 -0
  32. data/features/html/nested_frame_2.html +11 -0
  33. data/features/html/nested_frame_3.html +14 -0
  34. data/features/html/nested_frames.html +10 -0
  35. data/features/html/static_elements.html +29 -23
  36. data/features/image.feature +8 -0
  37. data/features/link.feature +5 -0
  38. data/features/list_item.feature +5 -0
  39. data/features/modal_dialog.feature +9 -0
  40. data/features/nested_elements.feature +105 -0
  41. data/features/ordered_list.feature +6 -0
  42. data/features/page_level_actions.feature +48 -0
  43. data/features/paragraph.feature +33 -0
  44. data/features/radio_button.feature +6 -0
  45. data/features/select_list.feature +6 -1
  46. data/features/span.feature +6 -1
  47. data/features/step_definations/async_steps.rb +63 -0
  48. data/features/step_definations/button_steps.rb +25 -1
  49. data/features/step_definations/checkbox_steps.rb +5 -1
  50. data/features/step_definations/div_steps.rb +6 -1
  51. data/features/step_definations/element_steps.rb +55 -1
  52. data/features/step_definations/file_field_steps.rb +27 -0
  53. data/features/step_definations/form_steps.rb +8 -0
  54. data/features/step_definations/frame_steps.rb +112 -0
  55. data/features/step_definations/heading_steps.rb +39 -0
  56. data/features/step_definations/hidden_field_steps.rb +7 -3
  57. data/features/step_definations/image_steps.rb +7 -3
  58. data/features/step_definations/link_steps.rb +8 -3
  59. data/features/step_definations/list_item_steps.rb +9 -1
  60. data/features/step_definations/modal_dialog_steps.rb +38 -0
  61. data/features/step_definations/nested_elements_steps.rb +196 -0
  62. data/features/step_definations/ordered_list_steps.rb +11 -3
  63. data/features/step_definations/page_level_actions_steps.rb +72 -0
  64. data/features/step_definations/paragraph_steps.rb +15 -0
  65. data/features/step_definations/radio_button_steps.rb +5 -1
  66. data/features/step_definations/select_list_steps.rb +10 -2
  67. data/features/step_definations/span_steps.rb +5 -1
  68. data/features/step_definations/table_cell_steps.rb +5 -1
  69. data/features/step_definations/table_steps.rb +17 -3
  70. data/features/step_definations/text_area_steps.rb +18 -2
  71. data/features/step_definations/text_field_steps.rb +9 -1
  72. data/features/step_definations/unordered_list_steps.rb +11 -3
  73. data/features/support/env.rb +0 -15
  74. data/features/support/hooks.rb +7 -0
  75. data/features/support/page.rb +98 -1
  76. data/features/support/persistent_browser.rb +15 -0
  77. data/features/support/url_helper.rb +24 -1
  78. data/features/table.feature +7 -0
  79. data/features/table_cell.feature +6 -0
  80. data/features/text_area.feature +11 -0
  81. data/features/text_field.feature +6 -1
  82. data/features/unordered_list.feature +6 -0
  83. data/lib/druid.rb +251 -3
  84. data/lib/druid/accessors.rb +446 -158
  85. data/lib/druid/assist.rb +394 -0
  86. data/lib/druid/core_ext/string.rb +5 -0
  87. data/lib/druid/element_locators.rb +405 -0
  88. data/lib/druid/elements.rb +28 -0
  89. data/lib/druid/elements/button.rb +6 -1
  90. data/lib/druid/elements/check_box.rb +26 -0
  91. data/lib/druid/elements/div.rb +3 -1
  92. data/lib/druid/elements/element.rb +170 -5
  93. data/lib/druid/elements/file_field.rb +18 -0
  94. data/lib/druid/elements/form.rb +11 -0
  95. data/lib/druid/elements/heading.rb +14 -0
  96. data/lib/druid/elements/hidden_field.rb +12 -2
  97. data/lib/druid/elements/image.rb +13 -0
  98. data/lib/druid/elements/link.rb +2 -0
  99. data/lib/druid/elements/list_item.rb +3 -1
  100. data/lib/druid/elements/option.rb +9 -0
  101. data/lib/druid/elements/ordered_list.rb +4 -5
  102. data/lib/druid/elements/paragraph.rb +9 -0
  103. data/lib/druid/elements/radio_button.rb +25 -0
  104. data/lib/druid/elements/select_list.rb +10 -1
  105. data/lib/druid/elements/span.rb +3 -1
  106. data/lib/druid/elements/table.rb +20 -1
  107. data/lib/druid/elements/table_cell.rb +7 -0
  108. data/lib/druid/elements/table_row.rb +5 -1
  109. data/lib/druid/elements/text_area.rb +15 -1
  110. data/lib/druid/elements/text_field.rb +11 -1
  111. data/lib/druid/elements/unordered_list.rb +5 -5
  112. data/lib/druid/nested_elements.rb +103 -0
  113. data/lib/druid/page_factory.rb +4 -4
  114. data/lib/druid/page_populator.rb +71 -0
  115. data/spec/druid/accessors_spec.rb +789 -0
  116. data/spec/druid/druid_spec.rb +130 -7
  117. data/spec/druid/element_locators_spec.rb +160 -0
  118. data/spec/druid/elements/button_spec.rb +31 -0
  119. data/spec/druid/elements/check_box_spec.rb +38 -0
  120. data/spec/druid/elements/div_spec.rb +19 -0
  121. data/spec/druid/elements/element_spec.rb +150 -0
  122. data/spec/druid/elements/file_field_spec.rb +27 -0
  123. data/spec/druid/elements/form_spec.rb +27 -0
  124. data/spec/druid/elements/heading_spec.rb +39 -0
  125. data/spec/druid/elements/hidden_field_spec.rb +24 -0
  126. data/spec/druid/elements/image_spec.rb +32 -0
  127. data/spec/druid/elements/link_spec.rb +26 -0
  128. data/spec/druid/elements/list_item_spec.rb +19 -0
  129. data/spec/druid/elements/option_spec.rb +10 -0
  130. data/spec/druid/elements/ordered_list_spec.rb +42 -0
  131. data/spec/druid/elements/page_factory_spec.rb +40 -0
  132. data/spec/druid/elements/paragraph_spec.rb +21 -0
  133. data/spec/druid/elements/radio_button_spec.rb +38 -0
  134. data/spec/druid/elements/select_list_spec.rb +37 -0
  135. data/spec/druid/elements/span_spec.rb +19 -0
  136. data/spec/druid/elements/table_cell_spec.rb +23 -0
  137. data/spec/druid/elements/table_row_spec.rb +41 -0
  138. data/spec/druid/elements/table_spec.rb +52 -0
  139. data/spec/druid/elements/text_area_spec.rb +31 -0
  140. data/spec/druid/elements/text_field_spec.rb +31 -0
  141. data/spec/druid/elements/unordered_list_spec.rb +42 -0
  142. data/spec/druid/nested_element_spec.rb +128 -0
  143. data/spec/druid/page_populator_spec.rb +92 -0
  144. data/spec/spec_helper.rb +2 -1
  145. metadata +147 -27
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::FileField do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath, :title].each do |t|
8
+ identifier = Druid::Elements::FileField.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ let(:element) { double 'element' }
16
+ let(:file_field) { Druid::Elements::FileField.new(element) }
17
+
18
+ it "should set its' value" do
19
+ expect(element).to receive(:set).with('a file')
20
+ file_field.value = 'a file'
21
+ end
22
+
23
+ it "should register as type :file" do
24
+ expect(Druid::Elements.element_class_for(:input, :file)).to be Druid::Elements::FileField
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Form do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath, :action].each do |t|
8
+ identifier = Druid::Elements::Form.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ let(:element) { double 'element' }
16
+ let(:form) { Druid::Elements::Form.new(element) }
17
+
18
+ it "should submit a form" do
19
+ expect(element).to receive(:submit)
20
+ form.submit
21
+ end
22
+
23
+ it "should register with tag_name :form" do
24
+ expect(Druid::Elements.element_class_for(:form)).to be Druid::Elements::Form
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Heading do
5
+ describe "When mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath].each do |t|
8
+ identifier = Druid::Elements::Heading.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ it "should register with tag :h1" do
16
+ expect(Druid::Elements.element_class_for(:h1)).to be Druid::Elements::Heading
17
+ end
18
+
19
+ it "should register with tag :h2" do
20
+ expect(Druid::Elements.element_class_for(:h2)).to be Druid::Elements::Heading
21
+ end
22
+
23
+ it "should register with tag :h3" do
24
+ expect(Druid::Elements.element_class_for(:h3)).to be Druid::Elements::Heading
25
+ end
26
+
27
+ it "should register with tag :h4" do
28
+ expect(Druid::Elements.element_class_for(:h4)).to be Druid::Elements::Heading
29
+ end
30
+
31
+ it "should register with tag :h5" do
32
+ expect(Druid::Elements.element_class_for(:h5)).to be Druid::Elements::Heading
33
+ end
34
+
35
+ it "should register with tag :h6" do
36
+ expect(Druid::Elements.element_class_for(:h6)).to be Druid::Elements::Heading
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::HiddenField do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath, :value].each do |t|
8
+ identifier = Druid::Elements::HiddenField.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+
13
+ it "should map selenium types to watir" do
14
+ identifier = Druid::Elements::HiddenField.identifier_for :css => 'value'
15
+ expect(identifier.keys.first).to eql :tag_name
16
+ end
17
+ end
18
+
19
+ describe "interface" do
20
+ it "should register with type :hidden" do
21
+ expect(Druid::Elements.element_class_for(:input, :hidden)).to be Druid::Elements::HiddenField
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Image do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath, :alt].each do |t|
8
+ identifier = Druid::Elements::Image.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ let(:element) { 'element' }
16
+ let(:image) { Druid::Elements::Image.new(element) }
17
+
18
+ it "should know the image width" do
19
+ expect(element).to receive(:width).and_return(100)
20
+ expect(image.width).to eql 100
21
+ end
22
+
23
+ it "should know the image height" do
24
+ expect(element).to receive(:height).and_return(120)
25
+ expect(image.height).to eql 120
26
+ end
27
+
28
+ it "should register with tag_name :img" do
29
+ expect(Druid::Elements.element_class_for(:img)).to be Druid::Elements::Image
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Link do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :href, :id, :name, :text, :xpath].each do |t|
8
+ identifier = Druid::Elements::Link.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+
13
+ it "should map selenium types to watir" do
14
+ [:link, :link_text].each do |t|
15
+ identifier = Druid::Elements::Link.identifier_for t => 'value'
16
+ expect(identifier.keys.first).to eql :text
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "interface" do
22
+ it "should register with tag :a" do
23
+ expect(Druid::Elements.element_class_for(:a)).to be Druid::Elements::Link
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::ListItem do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath].each do |t|
8
+ identifier = Druid::Elements::ListItem.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ it "should register as tag_name :li" do
16
+ expect(Druid::Elements.element_class_for(:li)).to be Druid::Elements::ListItem
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Option do
5
+ describe "interface" do
6
+ it "should register as tag_name :option" do
7
+ expect(Druid::Elements.element_class_for(:option)).to be Druid::Elements::Option
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::OrderedList do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :xpath].each do |t|
8
+ identifier = Druid::Elements::OrderedList.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ let(:element) { double 'element' }
16
+ let(:ol) { Druid::Elements::OrderedList.new(element) }
17
+
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
21
+ end
22
+
23
+ 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
26
+ end
27
+
28
+ it "should iterate over the list items" do
29
+ expect(ol).to receive(:items).and_return(2)
30
+ allow(ol).to receive(:[])
31
+ count = 0
32
+ ol.each do
33
+ count += 1
34
+ end
35
+ expect(count).to eql 2
36
+ end
37
+
38
+ it "should register as tag_name :ol" do
39
+ expect(Druid::Elements.element_class_for(:ol)).to be Druid::Elements::OrderedList
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'druid/page_factory'
3
+
4
+ class FactoryTestDruid
5
+ include Druid
6
+ page_url "http://www.baidu.com"
7
+ end
8
+
9
+ class TestWorld
10
+ include Druid::PageFactory
11
+
12
+ attr_accessor :driver
13
+ end
14
+
15
+ describe Druid::PageFactory do
16
+ before(:each) do
17
+ @world = TestWorld.new
18
+ @world.driver = mock_driver
19
+ end
20
+
21
+ it "should create and visit a new page" do
22
+ expect(@world.driver).to receive(:goto)
23
+ @world.visit_page FactoryTestDruid do |page|
24
+ expect(page).to be_instance_of FactoryTestDruid
25
+ end
26
+ end
27
+
28
+ it "should create a new page object and execute a block" do
29
+ expect(@world.driver).not_to receive(:goto)
30
+ @world.on_page FactoryTestDruid do |page|
31
+ expect(page).to be_instance_of FactoryTestDruid
32
+ end
33
+ end
34
+
35
+ it "should set an instance variable that can be used outside of the block" do
36
+ page = @world.on_page FactoryTestDruid
37
+ current_page = @world.instance_variable_get "@current_page"
38
+ expect(current_page).to eq page
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Paragraph do
5
+ let(:paragraph) { Druid::Elements::Paragraph }
6
+
7
+ describe "when mapping how to find an element" do
8
+ it "should map watir types to same" do
9
+ [:class, :id, :index, :name, :xpath].each do |t|
10
+ identifier = paragraph.identifier_for t => 'value'
11
+ expect(identifier.keys.first).to eql t
12
+ end
13
+ end
14
+ end
15
+
16
+ describe "interface" do
17
+ it "should register with type :checkbox" do
18
+ expect(Druid::Elements.element_class_for(:p)).to be Druid::Elements::Paragraph
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::RadioButton do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath, :value].each do |t|
8
+ identifier = Druid::Elements::RadioButton.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ let(:element) { double("element") }
16
+ let(:driver) { double("driver") }
17
+ let(:radio) { Druid::Elements::RadioButton.new(element)}
18
+
19
+ it "should select" do
20
+ expect(element).to receive(:set)
21
+ radio.select
22
+ end
23
+
24
+ it "should clear" do
25
+ expect(element).to receive(:clear)
26
+ radio.clear
27
+ end
28
+
29
+ it "should know if it is selected" do
30
+ expect(element).to receive(:set?)
31
+ radio.selected?
32
+ end
33
+
34
+ it "should register as type :radio" do
35
+ expect(Druid::Elements.element_class_for(:input, :radio)).to be Druid::Elements::RadioButton
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::SelectList do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :name, :xpath, :text, :value].each do |t|
8
+ identifier = Druid::Elements::SelectList.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ let(:element) { double 'element' }
16
+ let(:select_list) { Druid::Elements::SelectList.new(element) }
17
+
18
+ it "should return an option when indexed" do
19
+ expect(element).to receive_message_chain(:options, :[]).with(1)
20
+ expect(select_list[1]).to be_instance_of Druid::Elements::Option
21
+ end
22
+
23
+ it "should retrieve all values of select_list" do
24
+ expect(element).to receive(:options).and_return(['val1','val2'])
25
+ expect(select_list.options).to eql ['val1','val2']
26
+ end
27
+
28
+ it "should select an element" do
29
+ expect(element).to receive(:select).with('test')
30
+ select_list.select('test')
31
+ end
32
+
33
+ it "should register with tag_name :select" do
34
+ expect(Druid::Elements.element_class_for(:select)).to be Druid::Elements::SelectList
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::Span do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :xpath, :text].each do |t|
8
+ identifier = Druid::Elements::Span.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ it "should register with tag_name :span" do
16
+ expect(Druid::Elements.element_class_for(:span)).to be Druid::Elements::Span
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'druid/elements'
3
+
4
+ describe Druid::Elements::TableCell do
5
+ describe "when mapping how to find an element" do
6
+ it "should map watir types to same" do
7
+ [:class, :id, :index, :xpath, :name, :text].each do |t|
8
+ identifier = Druid::Elements::TableCell.identifier_for t => 'value'
9
+ expect(identifier.keys.first).to eql t
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "interface" do
15
+ it "should register with tag_name :td" do
16
+ expect(Druid::Elements.element_class_for(:td)).to be Druid::Elements::TableCell
17
+ end
18
+
19
+ it "should register with tag_name :th" do
20
+ expect(Druid::Elements.element_class_for(:th)).to be Druid::Elements::TableCell
21
+ end
22
+ end
23
+ end