druid-ts 1.1.8 → 1.2.0

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +27 -0
  3. data/features/bold.feature +21 -0
  4. data/features/element.feature +7 -0
  5. data/features/frames.feature +15 -0
  6. data/features/html/frames.html +3 -3
  7. data/features/html/iframes.html +2 -2
  8. data/features/html/multi_elements.html +1 -0
  9. data/features/html/static_elements.html +25 -8
  10. data/features/javascript.feature +10 -1
  11. data/features/link.feature +4 -0
  12. data/features/multi_elements.feature +6 -0
  13. data/features/radio_button_group.feature +28 -0
  14. data/features/section.feature +128 -0
  15. data/features/select_list.feature +4 -0
  16. data/features/step_definations/bold_steps.rb +11 -0
  17. data/features/step_definations/element_steps.rb +8 -0
  18. data/features/step_definations/frame_steps.rb +53 -11
  19. data/features/step_definations/javasript_steps.rb +9 -0
  20. data/features/step_definations/link_steps.rb +8 -0
  21. data/features/step_definations/multi_elements_steps.rb +13 -0
  22. data/features/step_definations/radio_button_group_steps.rb +32 -0
  23. data/features/step_definations/section_steps.rb +262 -0
  24. data/features/step_definations/table_steps.rb +9 -0
  25. data/features/support/env.rb +1 -0
  26. data/features/support/page.rb +16 -5
  27. data/features/table.feature +18 -14
  28. data/lib/druid.rb +42 -30
  29. data/lib/druid/accessors.rb +188 -55
  30. data/lib/druid/assist.rb +46 -4
  31. data/lib/druid/elements.rb +1 -0
  32. data/lib/druid/elements/bold.rb +8 -0
  33. data/lib/druid/elements/element.rb +16 -3
  34. data/lib/druid/elements/link.rb +7 -0
  35. data/lib/druid/elements/radio_button.rb +0 -7
  36. data/lib/druid/elements/select_list.rb +2 -2
  37. data/lib/druid/elements/table.rb +7 -0
  38. data/lib/druid/javascript/angularjs.rb +12 -0
  39. data/lib/druid/javascript_framework_facade.rb +5 -3
  40. data/lib/druid/locator_generator.rb +1 -0
  41. data/lib/druid/page_factory.rb +1 -0
  42. data/lib/druid/page_populator.rb +10 -1
  43. data/lib/druid/sections.rb +29 -0
  44. data/lib/druid/version.rb +1 -1
  45. data/spec/druid/accessors_spec.rb +79 -13
  46. data/spec/druid/druid_spec.rb +2 -1
  47. data/spec/druid/element_locators_spec.rb +26 -4
  48. data/spec/druid/elements/bold_spec.rb +21 -0
  49. data/spec/druid/elements/link_spec.rb +1 -1
  50. data/spec/druid/elements/page_factory_spec.rb +2 -2
  51. data/spec/druid/elements/radio_button_spec.rb +0 -5
  52. data/spec/druid/elements/select_list_spec.rb +3 -3
  53. data/spec/druid/page_factory_spec.rb +15 -15
  54. data/spec/druid/page_populator_spec.rb +4 -4
  55. data/spec/druid/page_section_spec.rb +61 -0
  56. data/spec/spec_helper.rb +1 -0
  57. metadata +20 -1
@@ -41,3 +41,12 @@ end
41
41
  Then(/^I should get the answer "([^"]*)"$/) do |answer|
42
42
  expect(@answer).to eql answer.to_i
43
43
  end
44
+
45
+ When(/^I execute the javascript "([^"]*)" with an argument of "([^"]*)"$/) do |script, arg|
46
+ @answer = @page.execute_script script, arg
47
+ end
48
+
49
+ When(/^I execute the javascript "([^"]*)" with a text field argument$/) do |script|
50
+ text_field = @page.text_field_element(:id => 'text_field_id')
51
+ @page.execute_script(script, text_field)
52
+ end
@@ -32,3 +32,11 @@ When(/^I select a link while the script is executing$/) do
32
32
  link = @page.link_element(:id => 'link_id')
33
33
  link.click
34
34
  end
35
+
36
+ When(/^I get the href for the link$/) do
37
+ @href = @page.google_search_id_element.href
38
+ end
39
+
40
+ Then(/^I should know it was "([^"]*)"$/) do |href|
41
+ expect(@href).to include href
42
+ end
@@ -31,6 +31,7 @@ class MultiElementsPage
31
31
  divs(:block_divs) do |page|
32
32
  page.div_elements(:class => 'div')
33
33
  end
34
+ b(:bs)
34
35
  end
35
36
 
36
37
  Given(/^I am on the multi elements page$/) do
@@ -525,3 +526,15 @@ end
525
526
  When(/^I select the multiple elements with a tag label$/) do
526
527
  @elements = @page.generic_label_elements
527
528
  end
529
+
530
+ When(/^I select the bs$/) do
531
+ @elements = @page.b_elements
532
+ end
533
+
534
+ Then(/^I should have (\d+) bs$/) do |num_bs|
535
+ expect(@elements.size).to eql num_bs.to_i
536
+ end
537
+
538
+ Then(/^the text for b (\d+) should be "([^"]*)"$/) do |b_num, text|
539
+ expect(@elements[b_num.to_i - 1].text).to eql text
540
+ end
@@ -0,0 +1,32 @@
1
+ Then(/^I should see that the radio button group exists$/) do
2
+ expect(@page.favorite_cheese?).to be true
3
+ end
4
+
5
+ Then(/^no radio buttons should be selected in the group$/) do
6
+ expect(@page.favorite_cheese_selected?).to be false
7
+ end
8
+
9
+ When(/^I select the "([^"]*)" radio button in the group$/) do |how|
10
+ @page.select_favorite_cheese("#{how}")
11
+ end
12
+
13
+ Then(/^the "([^"]*)" radio button should be selected in the group$/) do |how|
14
+ expect(@page.favorite_cheese_selected?).to eql how
15
+ end
16
+
17
+ Then(/^the "([^"]*)" radio button should not be selected$/) do |how|
18
+ expect(@page.favorite_cheese_selected?).not_to eql how
19
+ end
20
+
21
+ When(/^I ask for the elements of a radio button group$/) do
22
+ @elements = @page.favorite_cheese_elements
23
+ end
24
+
25
+ Then(/^I should have an array with elements for each radio button$/) do
26
+ expect(@elements.length).to eql 3
27
+ end
28
+
29
+ Then(/^the radio button element values should be "([^"]*)", "([^"]*)", "([^"]*)"$/) do |val1, val2, val3|
30
+ expect(@page.favorite_cheese_values).to eql [val1, val2, val3]
31
+
32
+ end
@@ -0,0 +1,262 @@
1
+ class Container
2
+ include Druid
3
+
4
+ link(:section_link)
5
+ button(:section_button)
6
+ text_field(:section_text_field)
7
+ hidden_field(:section_hidden_field)
8
+ text_area(:section_text_area)
9
+ select_list(:section_select_list)
10
+ file_field(:section_file_field)
11
+ checkbox(:section_checkbox)
12
+ radio_button(:section_radio_button)
13
+ div(:section_div)
14
+ span(:section_span)
15
+ table(:section_table)
16
+ cell(:section_cell) { |page| page.section_table_element.cell_element(:index => 1) }
17
+ image(:section_image)
18
+ form(:section_form)
19
+ ordered_list(:section_ordered_list)
20
+ unordered_list(:section_unordered_list)
21
+ list_item(:section_list_item) { |page| page.section_ordered_list_element.list_item_element }
22
+ h1(:section_h1)
23
+ h2(:section_h2)
24
+ h3(:section_h3)
25
+ h4(:section_h4)
26
+ h5(:section_h5)
27
+ h6(:section_h6)
28
+ paragraph(:section_paragraph)
29
+
30
+ unordered_list(:outside_section, :id => 'outer')
31
+ end
32
+
33
+ class InputSection
34
+ include Druid
35
+
36
+ def value
37
+ root.value
38
+ end
39
+ end
40
+
41
+ class SectionElementsPage
42
+ include Druid
43
+
44
+ page_section(:container, Container, :id => 'div_id')
45
+ page_sections(:page_inputs, InputSection, :tag_name => 'input')
46
+
47
+ end
48
+ Given(/^I am on the section elements page$/) do
49
+ @page = SectionElementsPage.new(@driver)
50
+ @page.navigate_to(UrlHelper.nested_elements)
51
+ end
52
+
53
+ When(/^I get the text from the section$/) do
54
+ @text = @page.container.text
55
+ end
56
+
57
+ Then(/^the text should include "([^"]*)"$/) do |expected_text|
58
+ expect(@text).to include expected_text
59
+ end
60
+
61
+ When(/^I access an element that is outside of the section$/) do
62
+ @element = @page.container.outside_section_element
63
+ end
64
+
65
+ Then(/^I should see that is doesn't exist in the section$/) do
66
+ expect(@element).not_to exist
67
+ end
68
+
69
+ When(/^I search for a link located in a section$/) do
70
+ @link = @page.container.section_link_element
71
+ end
72
+
73
+ Then(/^I should be able to click the section link$/) do
74
+ @link.click
75
+ end
76
+
77
+ When(/^I search for a button located in a section$/) do
78
+ @button = @page.container.section_button_element
79
+ end
80
+
81
+ Then(/^I should be able to click the section button$/) do
82
+ @button.click
83
+ end
84
+
85
+ When(/^I search for a text field located in a section$/) do
86
+ @text_field = @page.container.section_text_field_element
87
+ end
88
+
89
+ Then(/^I should be able to type "([^"]*)" in the section text field$/) do |value|
90
+ @text_field.value = value
91
+ end
92
+
93
+ When(/^I search for a hidden field located in a section$/) do
94
+ @hidden_field = @page.container.section_hidden_field_element
95
+ end
96
+
97
+ Then(/^I should be able to see that the section hidden field contains "([^"]*)"$/) do |value|
98
+ expect(@hidden_field.value).to eql value
99
+ end
100
+
101
+ When(/^I search for a text area located in a section$/) do
102
+ @text_area = @page.container.section_text_area_element
103
+ end
104
+
105
+ Then(/^I should be able to type "([^"]*)" in the section text area$/) do |value|
106
+ @text_area.value = value
107
+ end
108
+
109
+ When(/^I search for a select list located in a section$/) do
110
+ @select_list = @page.container.section_select_list_element
111
+ end
112
+
113
+ Then(/^I should be able to select "([^"]*)" in the section select list$/) do |value|
114
+ @select_list.select value
115
+ end
116
+
117
+ When(/^I search for a file field located in a section$/) do
118
+ @ff = @page.container.section_file_field_element
119
+ end
120
+
121
+ Then(/^I should be able to set the section file field$/) do
122
+ @ff.value = __FILE__
123
+ end
124
+
125
+ When(/^I search for a checkbox located in a section$/) do
126
+ @checkbox = @page.container.section_checkbox_element
127
+ end
128
+
129
+ Then(/^I should be able to check the section checkbox$/) do
130
+ @checkbox.check
131
+ end
132
+
133
+ When(/^I search for a radio button located in a section$/) do
134
+ @radio = @page.container.section_radio_button_element
135
+ end
136
+
137
+ Then(/^I should be able to select the section radio button$/) do
138
+ @radio.select
139
+ end
140
+
141
+ When(/^I search for a div located in a section$/) do
142
+ @div = @page.container.section_div_element
143
+ end
144
+
145
+ Then(/^I should see the text "([^"]*)" in the section div$/) do |value|
146
+ expect(@div.text).to eql value
147
+ end
148
+
149
+ When(/^I search for a span located in a section$/) do
150
+ @span = @page.container.section_span_element
151
+ end
152
+
153
+ Then(/^I should see the text "([^"]*)" in the section span$/) do |value|
154
+ expect(@span.text).to eql value
155
+ end
156
+
157
+ When(/^I search for a table located in a section$/) do
158
+ @table = @page.container.section_table_element
159
+ end
160
+
161
+ Then(/^the data for row "([^"]*)" of the section table should be "([^"]*)" and "([^"]*)"$/) do |row, col1, col2|
162
+ table_row = @table[row.to_i - 1]
163
+ expect(table_row[0].text).to eql col1
164
+ expect(table_row[1].text).to eql col2
165
+ end
166
+
167
+ When(/^I search the second table cell located in a table in a section$/) do
168
+ @cell = @page.container.section_cell_element
169
+ end
170
+
171
+ Then(/^the section table cell should contain "([^"]*)"$/) do |value|
172
+ expect(@cell.text).to eql value
173
+ end
174
+
175
+ When(/^I search for an image located in a section$/) do
176
+ @image = @page.container.section_image_element
177
+ end
178
+
179
+ Then(/^the section image should be "([^"]*)" pixels wide$/) do |width|
180
+ expect(@image.width).to eql width.to_i
181
+ end
182
+
183
+ Then(/^the section image should be "([^"]*)" pixels tall$/) do |height|
184
+ expect(@image.height).to eql height.to_i
185
+ end
186
+
187
+ When(/^I search for a form located in a section$/) do
188
+ @form = @page.container.section_form_element
189
+ end
190
+
191
+ Then(/^I should be able to submit the section form$/) do
192
+ @form.submit
193
+ end
194
+
195
+ When(/^I search for an ordered list located in a section$/) do
196
+ @list = @page.container.section_ordered_list_element
197
+ end
198
+
199
+ Then(/^the first section list items text should be "([^"]*)"$/) do |value|
200
+ expect(@list[0].text).to eql value
201
+ end
202
+
203
+ When(/^I search for an unordered list located in a section$/) do
204
+ @list = @page.container.section_unordered_list_element
205
+ end
206
+
207
+ When(/^I search for a list item section in an ordered list in a section$/) do
208
+ @li = @page.container.section_list_item_element
209
+ end
210
+
211
+ Then(/^I should see the section list items text should be "([^"]*)"$/) do |value|
212
+ expect(@li.text).to eql value
213
+ end
214
+
215
+ When(/^I search for a h(\d+) located in a section$/) do |num|
216
+ @header = @page.container.send "section_h#{num}_element"
217
+ end
218
+
219
+ Then(/^I should see the section h(\d+)s text should be "([^"]*)"$/) do |num, value|
220
+ expect(@header.text).to eql value
221
+ end
222
+
223
+ When(/^I search for a paragraph located in a section$/) do
224
+ @paragraph = @page.container.section_paragraph_element
225
+ end
226
+
227
+ Then(/^I should see the section paragraphs text should be "([^"]*)"$/) do |value|
228
+ expect(@paragraph.text).to eql value
229
+ end
230
+
231
+ When(/^I select multiple sections$/) do
232
+ @sections = @page.page_inputs
233
+ end
234
+
235
+ Then(/^I should have a section collection containing the sections$/) do
236
+ expect(@sections).to be_instance_of Druid::SectionCollection
237
+ end
238
+
239
+ Then(/^I can access any index of that collection of sections$/) do
240
+ expect(@sections[0]).to be_a(Druid)
241
+ expect(@sections[-1]).to be_a(Druid)
242
+ end
243
+
244
+ When(/^I search by a specific value of the section$/) do
245
+ @element = @sections.find_by(:value => 'LeanDog')
246
+ end
247
+
248
+ Then(/^I will find the first section with that value$/) do
249
+ expect(@element).to be_a(Druid)
250
+ expect(@element.value). to eq 'LeanDog'
251
+ end
252
+
253
+ When(/^I filter by a specific value of the sections$/) do
254
+ @elements = @sections.select_by(:value => /\w+/)
255
+ end
256
+
257
+ Then(/^I will find all sections with that value$/) do
258
+ expect(@elements).to be_a Druid::SectionCollection
259
+ @elements.map(&:value).each do |element|
260
+ expect(element).to match(/\w+/)
261
+ end
262
+ end
@@ -79,3 +79,12 @@ end
79
79
  Then(/^I should see the text includes "([^"]*)" when I retrieve it by "([^"]*)"$/) do |text, how|
80
80
  expect(@page.send("table_#{how}")).to include text
81
81
  end
82
+
83
+ Then(/^the data for the second row should be "([^"]*)" and "([^"]*)"$/) do |col1, col2|
84
+ expect(@element[1][0].text).to eql col1
85
+ expect(@element[1][1].text).to eql col2
86
+ end
87
+
88
+ Then(/^the table should be like the expected one$/) do |expected_table|
89
+ expect(expected_table.diff!@element.hashes).to be_nil
90
+ end
@@ -1,3 +1,4 @@
1
+ require 'rspec'
1
2
  require 'watir-webdriver'
2
3
  require 'druid'
3
4
 
@@ -72,6 +72,8 @@ class Page
72
72
  radio_button(:milk_class_index, :class => "milk_class", :index => 0)
73
73
  radio_button(:milk_name_index, :name => "milk_name", :index => 0)
74
74
 
75
+ radio_button_group(:favorite_cheese, name: 'fav_cheese')
76
+
75
77
  button(:button_id, :id => 'button_id')
76
78
  button(:button_name, :name => 'button_name')
77
79
  button(:button_class, :class => 'button_class')
@@ -81,7 +83,7 @@ class Page
81
83
  button(:button_value, :value => 'Click Me')
82
84
  button(:button_class_index, :class => "button_class", :index => 0)
83
85
  button(:button_name_index, :name => "button_name", :index => 0)
84
- button(:button_css, :css => "input[type='submit']")
86
+ button(:button_css, :css => ".button_class")
85
87
 
86
88
  button(:button_image_id, :id => 'button_image_id')
87
89
  button(:button_image_src, :src => 'images/submit.gif')
@@ -145,8 +147,8 @@ class Page
145
147
  label(:label_name, :name => "label_name")
146
148
  label(:label_class, :class => "label_class")
147
149
  label(:label_text, :text => "page-object is the best!")
148
- label(:label_index, :index => 5)
149
- label(:label_xpath, :xpath => "//label[6]")
150
+ label(:label_index, :index => 6)
151
+ label(:label_xpath, :xpath => "//label[7]")
150
152
  label(:label_css, :css => '.label_class')
151
153
  label(:label_class_index, :class => "label_class", :index => 0)
152
154
  label(:label_name_index, :name => "label_name", :index => 0)
@@ -176,7 +178,7 @@ class Page
176
178
  hidden_field(:hidden_field_class, :class => "hidden_field_class")
177
179
  hidden_field(:hidden_field_name, :name => "hidden_field_name")
178
180
  hidden_field(:hidden_field_xpath, :xpath => "//input[@type='hidden']")
179
- hidden_field(:hidden_field_css, :css => "input[type='hidden']")
181
+ hidden_field(:hidden_field_css, :css => ".hidden_field_class")
180
182
  hidden_field(:hidden_field_tag_name, :tag_name => "input[type='hidden']")
181
183
  hidden_field(:hidden_field_index, :index => 0)
182
184
  hidden_field(:hidden_field_text, :text => "")
@@ -207,7 +209,7 @@ class Page
207
209
  text_area(:text_area_class, :class => "text_area_class")
208
210
  text_area(:text_area_name, :name => "text_area_name")
209
211
  text_area(:text_area_xpath, :xpath => "//textarea")
210
- text_area(:text_area_css, :css => "textarea")
212
+ text_area(:text_area_css, :css => ".text_area_class")
211
213
  text_area(:text_area_tag_name, :tag_name => "textarea")
212
214
  text_area(:text_area_index, :index => 0)
213
215
  text_area(:text_area_text, :text => "")
@@ -354,4 +356,13 @@ class Page
354
356
 
355
357
  figure(:figure_id, :id => 'figure_id')
356
358
  svg(:svg_id, :id => 'the_svg')
359
+
360
+ b(:b_id, :id => 'b_id')
361
+ b(:b_class, :class => 'b_class')
362
+ b(:b_css, :css => '.b_class')
363
+ b(:b_name, :name => 'b_name')
364
+ b(:b_index, :index => 0)
365
+ b(:b_xpath, :xpath => '//b')
366
+ b(:b_class_index, :class => 'b_class', :index => 0)
367
+ b(:b_name_index, :name => 'b_name', :index => 0)
357
368
  end
@@ -28,15 +28,15 @@ Feature: Table
28
28
 
29
29
  Scenario: Retrieve data from a table using a column header
30
30
  When I retrieve a table element
31
- Then the data for column "Data2" and row "2" should be "Data4"
31
+ Then the data for column "Header" and row "3" should be "Data4"
32
32
 
33
33
  Scenario: Retrieve data from a table using a partial column header
34
34
  When I retrieve a table element
35
- Then the data for column "ata2" and row "2" should be "Data4"
35
+ Then the data for column "eader" and row "3" should be "Data4"
36
36
 
37
37
  Scenario: Retrieve data from a table using both headers
38
38
  When I retrieve a table element
39
- Then the data for row "Data3" and column "Data2" should be "Data4"
39
+ Then the data for row "Data3" and column "eader" should be "Data4"
40
40
 
41
41
  Scenario: Retrieve data from a table with an incorrect row header
42
42
  When I retrieve a table element
@@ -53,7 +53,7 @@ Feature: Table
53
53
  @name
54
54
  Scenario Outline: Locating table cells on the Page
55
55
  When I retrieve a table element by "<locate_by>"
56
- Then the data for row "1" should be "Data1" and "Data2"
56
+ Then the data for row "2" should be "Data1" and "Data2"
57
57
 
58
58
  Examples:
59
59
  | locate_by |
@@ -66,19 +66,16 @@ Feature: Table
66
66
 
67
67
  Scenario: Retrieve the data from a table
68
68
  When I retrieve a table element
69
- Then the data for row "1" should be "Data1" and "Data2"
70
- And the data for row "2" should be "Data3" and "Data4"
71
- And the table should have "2" rows
72
- And each row should contain "Data"
73
- And row "1" should have "2" columns
74
- And each column should contain "Data"
75
- And the data for the first row should be "Data1" and "Data2"
76
- And the data for the last row should be "Data3" and "Data4"
69
+ Then the data for row "2" should be "Data1" and "Data2"
70
+ And the data for row "3" should be "Data3" and "Data4"
71
+ And the table should have "3" rows
72
+ And row "2" should have "2" columns
73
+ And the data for the second row should be "Data1" and "Data2"
77
74
 
78
75
  @multi
79
76
  Scenario Outline: Locating table using multiple parameters
80
77
  When I retrieve a table element bys "<param1>" and "<param2>"
81
- Then the data for row "1" should be "Data1" and "Data2"
78
+ Then the data for row "2" should be "Data1" and "Data2"
82
79
 
83
80
  Examples:
84
81
  | param1 | param2 |
@@ -89,7 +86,7 @@ Feature: Table
89
86
  Scenario: Finding a table dynamically
90
87
  When I retrieve a table element while the script is executing
91
88
  Then I should see that the table exists
92
- And the data for row "1" should be "Data1" and "Data2"
89
+ And the data for row "2" should be "Data1" and "Data2"
93
90
 
94
91
  Scenario: Retrieve data from a table with a thead using a column header
95
92
  When I retrieve a table with thead element
@@ -102,3 +99,10 @@ Feature: Table
102
99
  Scenario: Getting the text from a table
103
100
  Then I should see the text includes "Data1" when I retrieve it by "id"
104
101
  And I should see the text includes "Data2" when I retrieve it by "id"
102
+
103
+ Scenario: Matching the expected table with the table on the Page
104
+ When I retrieve a table element
105
+ Then the table should be like the expected one
106
+ | Table | Header |
107
+ | Data1 | Data2 |
108
+ | Data3 | Data4 |