watir-webdriver 0.0.1.dev6 → 0.0.1.dev7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/Rakefile +1 -2
  2. data/VERSION +1 -1
  3. data/lib/watir-webdriver.rb +1 -4
  4. data/lib/watir-webdriver/base_element.rb +14 -7
  5. data/lib/watir-webdriver/browser.rb +3 -1
  6. data/lib/watir-webdriver/elements/button.rb +1 -0
  7. data/lib/watir-webdriver/elements/form.rb +1 -1
  8. data/lib/watir-webdriver/elements/frame.rb +77 -0
  9. data/lib/watir-webdriver/elements/generated.rb +536 -536
  10. data/lib/watir-webdriver/elements/option.rb +3 -0
  11. data/lib/watir-webdriver/elements/table_row.rb +1 -0
  12. data/lib/watir-webdriver/elements/text_field.rb +5 -1
  13. data/lib/watir-webdriver/xpath_support.rb +0 -1
  14. data/spec/base_element_spec.rb +16 -0
  15. data/spec/html/keylogger.html +15 -0
  16. data/spec/watirspec/area_spec.rb +78 -0
  17. data/spec/watirspec/areas_spec.rb +31 -0
  18. data/spec/watirspec/browser_spec.rb +274 -0
  19. data/spec/watirspec/button_spec.rb +242 -0
  20. data/spec/watirspec/buttons_spec.rb +48 -0
  21. data/spec/watirspec/checkbox_spec.rb +272 -0
  22. data/spec/watirspec/checkboxes_spec.rb +32 -0
  23. data/spec/watirspec/dd_spec.rb +123 -0
  24. data/spec/watirspec/dds_spec.rb +31 -0
  25. data/spec/watirspec/div_spec.rb +211 -0
  26. data/spec/watirspec/divs_spec.rb +31 -0
  27. data/spec/watirspec/dl_spec.rb +123 -0
  28. data/spec/watirspec/dls_spec.rb +32 -0
  29. data/spec/watirspec/dt_spec.rb +123 -0
  30. data/spec/watirspec/dts_spec.rb +31 -0
  31. data/spec/watirspec/element_spec.rb +89 -0
  32. data/spec/watirspec/em_spec.rb +97 -0
  33. data/spec/watirspec/ems_spec.rb +32 -0
  34. data/spec/watirspec/filefield_spec.rb +119 -0
  35. data/spec/watirspec/filefields_spec.rb +32 -0
  36. data/spec/watirspec/font_spec.rb +26 -0
  37. data/spec/watirspec/form_spec.rb +63 -0
  38. data/spec/watirspec/forms_spec.rb +33 -0
  39. data/spec/watirspec/frame_spec.rb +135 -0
  40. data/spec/watirspec/frames_spec.rb +62 -0
  41. data/spec/watirspec/hidden_spec.rb +102 -0
  42. data/spec/watirspec/hiddens_spec.rb +32 -0
  43. data/spec/watirspec/hn_spec.rb +93 -0
  44. data/spec/watirspec/hns_spec.rb +38 -0
  45. data/spec/watirspec/image_spec.rb +207 -0
  46. data/spec/watirspec/images_spec.rb +31 -0
  47. data/spec/watirspec/label_spec.rb +75 -0
  48. data/spec/watirspec/labels_spec.rb +31 -0
  49. data/spec/watirspec/li_spec.rb +112 -0
  50. data/spec/watirspec/lib/guards.rb +59 -0
  51. data/spec/watirspec/lib/server.rb +136 -0
  52. data/spec/watirspec/lib/spec_helper.rb +79 -0
  53. data/spec/watirspec/lib/watirspec.rb +72 -0
  54. data/spec/watirspec/link_spec.rb +168 -0
  55. data/spec/watirspec/links_spec.rb +35 -0
  56. data/spec/watirspec/lis_spec.rb +31 -0
  57. data/spec/watirspec/map_spec.rb +76 -0
  58. data/spec/watirspec/maps_spec.rb +32 -0
  59. data/spec/watirspec/meta_spec.rb +22 -0
  60. data/spec/watirspec/metas_spec.rb +30 -0
  61. data/spec/watirspec/ol_spec.rb +78 -0
  62. data/spec/watirspec/ols_spec.rb +31 -0
  63. data/spec/watirspec/option_spec.rb +173 -0
  64. data/spec/watirspec/p_spec.rb +128 -0
  65. data/spec/watirspec/pre_spec.rb +112 -0
  66. data/spec/watirspec/pres_spec.rb +31 -0
  67. data/spec/watirspec/ps_spec.rb +31 -0
  68. data/spec/watirspec/radio_spec.rb +255 -0
  69. data/spec/watirspec/radios_spec.rb +32 -0
  70. data/spec/watirspec/select_list_spec.rb +318 -0
  71. data/spec/watirspec/select_lists_spec.rb +35 -0
  72. data/spec/watirspec/span_spec.rb +142 -0
  73. data/spec/watirspec/spans_spec.rb +31 -0
  74. data/spec/watirspec/spec_helper.rb +17 -0
  75. data/spec/watirspec/strong_spec.rb +89 -0
  76. data/spec/watirspec/strongs_spec.rb +32 -0
  77. data/spec/watirspec/table_bodies_spec.rb +45 -0
  78. data/spec/watirspec/table_body_spec.rb +98 -0
  79. data/spec/watirspec/table_cell_spec.rb +68 -0
  80. data/spec/watirspec/table_cells_spec.rb +47 -0
  81. data/spec/watirspec/table_footer_spec.rb +85 -0
  82. data/spec/watirspec/table_footers_spec.rb +47 -0
  83. data/spec/watirspec/table_header_spec.rb +85 -0
  84. data/spec/watirspec/table_headers_spec.rb +45 -0
  85. data/spec/watirspec/table_row_spec.rb +87 -0
  86. data/spec/watirspec/table_rows_spec.rb +50 -0
  87. data/spec/watirspec/table_spec.rb +160 -0
  88. data/spec/watirspec/tables_spec.rb +33 -0
  89. data/spec/watirspec/text_field_spec.rb +276 -0
  90. data/spec/watirspec/text_fields_spec.rb +35 -0
  91. data/spec/watirspec/ul_spec.rb +76 -0
  92. data/spec/watirspec/uls_spec.rb +33 -0
  93. data/support/html5/html5.idl +1 -1
  94. metadata +181 -21
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Ps" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of ps" do
12
+ browser.ps.length.should == 5
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the p at the given index" do
18
+ browser.ps[0].id.should == "lead"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through ps correctly" do
24
+ browser.ps.each_with_index do |p, index|
25
+ p.id.should == browser.p(:index, index).id
26
+ p.value.should == browser.p(:index, index).value
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,255 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Radio" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the radio button exists" do
13
+ browser.radio(:id, "new_user_newsletter_yes").should exist
14
+ browser.radio(:id, /new_user_newsletter_yes/).should exist
15
+ browser.radio(:name, "new_user_newsletter").should exist
16
+ browser.radio(:name, /new_user_newsletter/).should exist
17
+ browser.radio(:value, "yes").should exist
18
+ browser.radio(:value, /yes/).should exist
19
+ # TODO: figure out what :text means for a radio button
20
+ # browser.radio(:text, "yes").should exist
21
+ # browser.radio(:text, /yes/).should exist
22
+ browser.radio(:class, "huge").should exist
23
+ browser.radio(:class, /huge/).should exist
24
+ browser.radio(:index, 0).should exist
25
+ browser.radio(:xpath, "//input[@id='new_user_newsletter_yes']").should exist
26
+ end
27
+
28
+ it "returns true if the radio button exists (search by name and value)" do
29
+ browser.radio(:name => "new_user_newsletter", :value => 'yes').should exist
30
+ browser.radio(:xpath, "//input[@name='new_user_newsletter' and @value='yes']").set
31
+ end
32
+
33
+ it "returns false if the radio button does not exist" do
34
+ browser.radio(:id, "no_such_id").should_not exist
35
+ browser.radio(:id, /no_such_id/).should_not exist
36
+ browser.radio(:name, "no_such_name").should_not exist
37
+ browser.radio(:name, /no_such_name/).should_not exist
38
+ browser.radio(:value, "no_such_value").should_not exist
39
+ browser.radio(:value, /no_such_value/).should_not exist
40
+ browser.radio(:text, "no_such_text").should_not exist
41
+ browser.radio(:text, /no_such_text/).should_not exist
42
+ browser.radio(:class, "no_such_class").should_not exist
43
+ browser.radio(:class, /no_such_class/).should_not exist
44
+ browser.radio(:index, 1337).should_not exist
45
+ browser.radio(:xpath, "input[@id='no_such_id']").should_not exist
46
+ end
47
+
48
+ it "returns false if the radio button does not exist (search by name and value)" do
49
+ browser.radio(:name => "new_user_newsletter", :value => 'no_such_value').should_not exist
50
+ browser.radio(:xpath, "//input[@name='new_user_newsletter' and @value='no_such_value']").should_not exist
51
+ browser.radio(:name => "no_such_name", :value => 'yes').should_not exist
52
+ browser.radio(:xpath, "//input[@name='no_such_name' and @value='yes']").should_not exist
53
+ end
54
+
55
+ it "returns true for radios with a string value" do
56
+ browser.radio(:name => 'new_user_newsletter', :value => 'yes').should exist
57
+ browser.radio(:name => 'new_user_newsletter', :value => 'no').should exist
58
+ end
59
+
60
+ it "raises TypeError when 'what' argument is invalid" do
61
+ lambda { browser.radio(:id, 3.14).exists? }.should raise_error(TypeError)
62
+ end
63
+
64
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
65
+ lambda { browser.radio(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
66
+ end
67
+ end
68
+
69
+ # Attribute methods
70
+ describe "#class_name" do
71
+ it "returns the class name if the radio exists and has an attribute" do
72
+ browser.radio(:id, "new_user_newsletter_yes").class_name.should == "huge"
73
+ end
74
+
75
+ it "returns an emptry string if the radio exists and the attribute doesn't" do
76
+ browser.radio(:id, "new_user_newsletter_no").class_name.should == ""
77
+ end
78
+
79
+ it "raises UnknownObjectException if the radio doesn't exist" do
80
+ lambda { browser.radio(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
81
+ end
82
+ end
83
+
84
+ describe "#id" do
85
+ it "returns the id attribute if the radio exists and has an attribute" do
86
+ browser.radio(:index, 0).id.should == "new_user_newsletter_yes"
87
+ end
88
+
89
+ it "returns an emptry string if the radio exists and the attribute doesn't" do
90
+ browser.radio(:index, 2).id.should == ""
91
+ end
92
+
93
+ it "raises UnknownObjectException if the radio doesn't exist" do
94
+ lambda { browser.radio(:index, 1337).id }.should raise_error(UnknownObjectException)
95
+ end
96
+ end
97
+
98
+ describe "#name" do
99
+ it "returns the name attribute if the radio exists" do
100
+ browser.radio(:id, 'new_user_newsletter_yes').name.should == "new_user_newsletter"
101
+ end
102
+
103
+ it "returns an empty string if the radio exists and the attribute doesn't" do
104
+ browser.radio(:id, 'new_user_newsletter_absolutely').name.should == ""
105
+ end
106
+
107
+ it "raises UnknownObjectException if the radio doesn't exist" do
108
+ lambda { browser.radio(:index, 1337).name }.should raise_error(UnknownObjectException)
109
+ end
110
+ end
111
+
112
+ describe "#title" do
113
+ it "returns the title attribute if the radio exists" do
114
+ browser.radio(:id, "new_user_newsletter_no").title.should == "Traitor!"
115
+ end
116
+
117
+ it "returns an emptry string if the radio exists and the attribute doesn't" do
118
+ browser.radio(:id, "new_user_newsletter_yes").title.should == ""
119
+ end
120
+
121
+ it "raises UnknownObjectException if the radio doesn't exist" do
122
+ lambda { browser.radio(:index, 1337).title }.should raise_error(UnknownObjectException)
123
+ end
124
+ end
125
+
126
+ describe "#type" do
127
+ it "returns the type attribute if the radio exists" do
128
+ browser.radio(:index, 0).type.should == "radio"
129
+ end
130
+
131
+ it "raises UnknownObjectException if the radio doesn't exist" do
132
+ lambda { browser.radio(:index, 1337).type }.should raise_error(UnknownObjectException)
133
+ end
134
+ end
135
+
136
+ describe "#value" do
137
+ it "returns the value attribute if the radio exists" do
138
+ browser.radio(:id, 'new_user_newsletter_yes').value.should == 'yes'
139
+ end
140
+
141
+ it "raises UnknownObjectException if the radio doesn't exist" do
142
+ lambda { browser.radio(:index, 1337).value}.should raise_error(UnknownObjectException)
143
+ end
144
+ end
145
+
146
+ describe "#respond_to?" do
147
+ it "returns true for all attribute methods" do
148
+ browser.radio(:index, 0).should respond_to(:class_name)
149
+ browser.radio(:index, 0).should respond_to(:id)
150
+ browser.radio(:index, 0).should respond_to(:name)
151
+ browser.radio(:index, 0).should respond_to(:title)
152
+ browser.radio(:index, 0).should respond_to(:type)
153
+ browser.radio(:index, 0).should respond_to(:value)
154
+ end
155
+ end
156
+
157
+ # Access methods
158
+ describe "#enabled?" do
159
+ it "returns true if the radio button is enabled" do
160
+ browser.radio(:id, "new_user_newsletter_yes").should be_enabled
161
+ browser.radio(:xpath, "//input[@id='new_user_newsletter_yes']").should be_enabled
162
+ end
163
+
164
+ it "returns false if the radio button is disabled" do
165
+ browser.radio(:id, "new_user_newsletter_nah").should_not be_enabled
166
+ browser.radio(:xpath,"//input[@id='new_user_newsletter_nah']").should_not be_enabled
167
+ end
168
+
169
+ it "raises UnknownObjectException if the radio button doesn't exist" do
170
+ lambda { browser.radio(:id, "no_such_id").enabled? }.should raise_error(UnknownObjectException)
171
+ lambda { browser.radio(:xpath, "//input[@id='no_such_id']").enabled? }.should raise_error(UnknownObjectException)
172
+ end
173
+ end
174
+
175
+ describe "#disabled?" do
176
+ it "returns true if the radio is disabled" do
177
+ browser.radio(:id, 'new_user_newsletter_nah').should be_disabled
178
+ end
179
+
180
+ it "returns false if the radio is enabled" do
181
+ browser.radio(:id, 'new_user_newsletter_yes').should_not be_disabled
182
+ end
183
+
184
+ it "raises UnknownObjectException if the radio doesn't exist" do
185
+ lambda { browser.radio(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
186
+ end
187
+ end
188
+
189
+ describe "#set" do
190
+ it "sets the radio button" do
191
+ browser.radio(:id, "new_user_newsletter_no").set
192
+ browser.radio(:id, "new_user_newsletter_no").should be_set
193
+ end
194
+
195
+ it "sets the radio button when found by :xpath" do
196
+ browser.radio(:xpath, "//input[@id='new_user_newsletter_no']").set
197
+ browser.radio(:xpath, "//input[@id='new_user_newsletter_no']").should be_set
198
+ end
199
+
200
+ it "fires the onclick event" do
201
+ browser.radio(:id, "new_user_newsletter_no").set
202
+ browser.radio(:id, "new_user_newsletter_yes").set
203
+ messages.should == ["clicked: new_user_newsletter_no", "clicked: new_user_newsletter_yes"]
204
+ end
205
+
206
+ bug "WTR-337", :watir do
207
+ it "fires the onchange event" do
208
+ browser.radio(:value, 'certainly').set
209
+ messages.should == ["changed: new_user_newsletter"]
210
+
211
+ browser.radio(:value, 'certainly').set
212
+ messages.should == ["changed: new_user_newsletter"] # no event fired here - didn't change
213
+
214
+ browser.radio(:value, 'yes').set
215
+ browser.radio(:value, 'certainly').set
216
+ messages.should == ["changed: new_user_newsletter", "clicked: new_user_newsletter_yes", "changed: new_user_newsletter"]
217
+ end
218
+ end
219
+
220
+ it "raises UnknownObjectException if the radio button doesn't exist" do
221
+ lambda { browser.radio(:name, "no_such_name").set }.should raise_error(UnknownObjectException)
222
+ lambda { browser.radio(:xpath, "//input[@name='no_such_name']").set }.should raise_error(UnknownObjectException)
223
+ end
224
+
225
+ it "raises ObjectDisabledException if the radio is disabled" do
226
+ lambda { browser.radio(:id, "new_user_newsletter_nah").set }.should raise_error(ObjectDisabledException)
227
+ lambda { browser.radio(:xpath, "//input[@id='new_user_newsletter_nah']").set }.should raise_error(ObjectDisabledException )
228
+ end
229
+ end
230
+
231
+ # Other
232
+ describe '#set?' do
233
+ it "returns true if the radio button is set" do
234
+ browser.radio(:id, "new_user_newsletter_yes").should be_set
235
+ end
236
+
237
+ it "returns false if the radio button unset" do
238
+ browser.radio(:id, "new_user_newsletter_no").should_not be_set
239
+ end
240
+
241
+ it "returns the state for radios with string values" do
242
+ browser.radio(:name => "new_user_newsletter", :value => 'no').should_not be_set
243
+ browser.radio(:name => "new_user_newsletter", :value => 'no').set
244
+ browser.radio(:name => "new_user_newsletter", :value => 'no').should be_set
245
+ browser.radio(:name => "new_user_newsletter", :value => 'yes').set
246
+ browser.radio(:name => "new_user_newsletter", :value => 'no').should_not be_set
247
+ end
248
+
249
+ it "raises UnknownObjectException if the radio button doesn't exist" do
250
+ lambda { browser.radio(:id, "no_such_id").set? }.should raise_error(UnknownObjectException)
251
+ lambda { browser.radio(:xpath, "//input[@id='no_such_id']").set? }.should raise_error(UnknownObjectException)
252
+ end
253
+ end
254
+
255
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Radios" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of radios" do
12
+ browser.radios.length.should == 5
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the radio button at the given index" do
18
+ browser.radios[0].id.should == "new_user_newsletter_yes"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through radio buttons correctly" do
24
+ browser.radios.each_with_index do |r, index|
25
+ r.name.should == browser.radio(:index, index).name
26
+ r.id.should == browser.radio(:index, index).id
27
+ r.value.should == browser.radio(:index, index).value
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,318 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "SelectList" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the select list exists" do
13
+ browser.select_list(:id, 'new_user_country').should exist
14
+ browser.select_list(:id, /new_user_country/).should exist
15
+ browser.select_list(:name, 'new_user_country').should exist
16
+ browser.select_list(:name, /new_user_country/).should exist
17
+ # TODO: check behaviour in Watir
18
+ # browser.select_list(:value, 'Norway').should exist
19
+ # browser.select_list(:value, /Norway/).should exist
20
+ browser.select_list(:text, 'Norway').should exist
21
+ browser.select_list(:text, /Norway/).should exist
22
+ browser.select_list(:class, 'country').should exist
23
+ browser.select_list(:class, /country/).should exist
24
+ browser.select_list(:index, 0).should exist
25
+ browser.select_list(:xpath, "//select[@id='new_user_country']").should exist
26
+ end
27
+
28
+ it "returns false if the select list doesn't exist" do
29
+ browser.select_list(:id, 'no_such_id').should_not exist
30
+ browser.select_list(:id, /no_such_id/).should_not exist
31
+ browser.select_list(:name, 'no_such_name').should_not exist
32
+ browser.select_list(:name, /no_such_name/).should_not exist
33
+ browser.select_list(:value, 'no_such_value').should_not exist
34
+ browser.select_list(:value, /no_such_value/).should_not exist
35
+ browser.select_list(:text, 'no_such_text').should_not exist
36
+ browser.select_list(:text, /no_such_text/).should_not exist
37
+ browser.select_list(:class, 'no_such_class').should_not exist
38
+ browser.select_list(:class, /no_such_class/).should_not exist
39
+ browser.select_list(:index, 1337).should_not exist
40
+ browser.select_list(:xpath, "//select[@id='no_such_id']").should_not exist
41
+ end
42
+
43
+ it "raises TypeError when 'what' argument is invalid" do
44
+ lambda { browser.select_list(:id, 3.14).exists? }.should raise_error(TypeError)
45
+ end
46
+
47
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
48
+ lambda { browser.select_list(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
49
+ end
50
+ end
51
+
52
+ # Attribute methods
53
+ describe "#class_name" do
54
+ it "returns the class name of the select list" do
55
+ browser.select_list(:name, 'new_user_country').class_name.should == 'country'
56
+ end
57
+
58
+ it "raises UnknownObjectException if the select list doesn't exist" do
59
+ lambda { browser.select_list(:name, 'no_such_name').class_name }.should raise_error(UnknownObjectException)
60
+ end
61
+ end
62
+
63
+ describe "#id" do
64
+ it "returns the id of the element" do
65
+ browser.select_list(:index, 0).id.should == "new_user_country"
66
+ end
67
+
68
+ it "raises UnknownObjectException if the select list doesn't exist" do
69
+ lambda { browser.select_list(:index, 1337).id }.should raise_error(UnknownObjectException)
70
+ end
71
+ end
72
+
73
+ describe "#name" do
74
+ it "returns the name of the element" do
75
+ browser.select_list(:index, 0).name.should == "new_user_country"
76
+ end
77
+
78
+ it "raises UnknownObjectException if the select list doesn't exist" do
79
+ lambda { browser.select_list(:index, 1337).name }.should raise_error(UnknownObjectException)
80
+ end
81
+ end
82
+
83
+ describe "#multiple?" do
84
+ it "knows whether the select list allows multiple slections" do
85
+ browser.select_list(:index, 0).should_not be_multiple
86
+ browser.select_list(:index, 1).should be_multiple
87
+ end
88
+
89
+ it "raises UnknownObjectException if the select list doesn't exist" do
90
+ lambda { browser.select_list(:index, 1337).multiple? }.should raise_error(UnknownObjectException)
91
+ end
92
+ end
93
+
94
+ describe "#value" do
95
+ it "returns the value of the selected option" do
96
+ browser.select_list(:index, 0).value.should == "2"
97
+ browser.select_list(:index, 0).select(/Sweden/)
98
+ browser.select_list(:index, 0).value.should == "3"
99
+ end
100
+
101
+ it "raises UnknownObjectException if the select list doesn't exist" do
102
+ lambda { browser.select_list(:index, 1337).value }.should raise_error(UnknownObjectException)
103
+ end
104
+ end
105
+
106
+ describe "#respond_to?" do
107
+ it "returns true for all attribute methods" do
108
+ browser.select_list(:index, 0).should respond_to(:class_name)
109
+ browser.select_list(:index, 0).should respond_to(:id)
110
+ browser.select_list(:index, 0).should respond_to(:name)
111
+ browser.select_list(:index, 0).should respond_to(:value)
112
+ end
113
+ end
114
+
115
+ # Access methods
116
+ describe "#enabled?" do
117
+ it "returns true if the select list is enabled" do
118
+ browser.select_list(:name, 'new_user_country').should be_enabled
119
+ end
120
+
121
+ it "returns false if the select list is disabled" do
122
+ browser.select_list(:name, 'new_user_role').should_not be_enabled
123
+ end
124
+
125
+ it "raises UnknownObjectException if the select_list doesn't exist" do
126
+ lambda { browser.select_list(:name, 'no_such_name').enabled? }.should raise_error(UnknownObjectException)
127
+ end
128
+ end
129
+
130
+ describe "#disabled?" do
131
+ it "returns true if the select list is disabled" do
132
+ browser.select_list(:index, 2).should be_disabled
133
+ end
134
+
135
+ it "returns false if the select list is enabled" do
136
+ browser.select_list(:index, 0).should_not be_disabled
137
+ end
138
+
139
+ it "shoulds raise UnknownObjectException when the select list does not exist" do
140
+ lambda { browser.select_list(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
141
+ end
142
+ end
143
+
144
+ # Other
145
+ describe "#option" do
146
+ it "returns an instance of Option" do
147
+ option = browser.select_list(:name, "new_user_country").option(:text, "Denmark")
148
+ option.should be_instance_of(Option)
149
+ option.value.should == "1"
150
+ end
151
+ end
152
+
153
+ describe "#options" do
154
+ it "shoulds raise UnknownObjectException if the select list doesn't exist" do
155
+ lambda { browser.select_list(:name, 'no_such_name').options }.should raise_error(UnknownObjectException)
156
+ end
157
+
158
+ bug "WTR-339", :watir do
159
+ it "returns all the options as an Array" do
160
+ browser.select_list(:name, "new_user_country").options.should == ["Denmark" ,"Norway" , "Sweden" , "United Kingdom", "USA", "Germany"]
161
+ end
162
+ end
163
+ end
164
+
165
+ describe "#selected_options" do
166
+ it "shoulds raise UnknownObjectException if the select list doesn't exist" do
167
+ lambda { browser.select_list(:name, 'no_such_name').selected_options }.should raise_error(UnknownObjectException)
168
+ end
169
+
170
+ it "gets the currently selected item(s)" do
171
+ browser.select_list(:name, "new_user_country").selected_options.should == ["Norway"]
172
+ browser.select_list(:name, "new_user_languages").selected_options.should == ["English", "Norwegian"]
173
+ end
174
+ end
175
+
176
+ describe "#clear" do
177
+ it "clears the selection when possible" do
178
+ browser.select_list(:name, "new_user_languages").clear
179
+ browser.select_list(:name, "new_user_languages").selected_options.should be_empty
180
+ end
181
+
182
+ it "does not clear selections when not possible" do
183
+ lambda { browser.select_list(:name , "new_user_country").clear }.should raise_error
184
+ browser.select_list(:name, "new_user_country").selected_options.should == ["Norway"]
185
+ end
186
+
187
+ it "raises UnknownObjectException if the select list doesn't exist" do
188
+ lambda { browser.select_list(:name, 'no_such_name').clear }.should raise_error(UnknownObjectException)
189
+ end
190
+ end
191
+
192
+ describe "#includes?" do
193
+ it "returns true if the given option exists" do
194
+ browser.select_list(:name, 'new_user_country').includes?('Denmark').should be_true
195
+ end
196
+
197
+ it "returns false if the given option doesn't exist" do
198
+ browser.select_list(:name, 'new_user_country').includes?('Ireland').should be_false
199
+ end
200
+ end
201
+
202
+ describe "#selected?" do
203
+ it "returns true if the given option is selected" do
204
+ browser.select_list(:name, 'new_user_country').select('Denmark')
205
+ browser.select_list(:name, 'new_user_country').selected?('Denmark').should be_true
206
+ end
207
+
208
+ it "returns false if the given option is not selected" do
209
+ browser.select_list(:name, 'new_user_country').selected?('Sweden').should be_false
210
+ end
211
+
212
+ it "raises UnknonwObjectException if the option doesn't exist" do
213
+ lambda { browser.select_list(:name, 'new_user_country').selected?('missing_option') }.should raise_error(UnknownObjectException)
214
+ end
215
+ end
216
+
217
+ describe "#select" do
218
+ it "selects the given item when given a String" do
219
+ browser.select_list(:name, "new_user_country").select("Denmark")
220
+ browser.select_list(:name, "new_user_country").selected_options.should == ["Denmark"]
221
+ end
222
+
223
+ it "selects options by label" do
224
+ browser.select_list(:name, "new_user_country").select("Germany")
225
+ browser.select_list(:name, "new_user_country").selected_options.should == ["Germany"]
226
+ end
227
+
228
+ it "selects the given item when given a Regexp" do
229
+ browser.select_list(:name, "new_user_country").select(/Denmark/)
230
+ browser.select_list(:name, "new_user_country").selected_options.should == ["Denmark"]
231
+ end
232
+
233
+ it "selects the given item when given an Xpath" do
234
+ browser.select_list(:xpath, "//select[@name='new_user_country']").select("Denmark")
235
+ browser.select_list(:xpath, "//select[@name='new_user_country']").selected_options.should == ["Denmark"]
236
+ end
237
+
238
+ it "selects multiple items using :name and a String" do
239
+ browser.select_list(:name, "new_user_languages").clear
240
+ browser.select_list(:name, "new_user_languages").select("Danish")
241
+ browser.select_list(:name, "new_user_languages").select("Swedish")
242
+ browser.select_list(:name, "new_user_languages").selected_options.should == ["Danish", "Swedish"]
243
+ end
244
+
245
+ bug "WTR-362", :watir do
246
+ it "selects multiple items using :name and a Regexp" do
247
+ browser.select_list(:name, "new_user_languages").clear
248
+ browser.select_list(:name, "new_user_languages").select(/ish/)
249
+ browser.select_list(:name, "new_user_languages").selected_options.should == ["Danish", "English", "Swedish"]
250
+ end
251
+
252
+ it "selects multiple items using :xpath" do
253
+ browser.select_list(:xpath, "//select[@name='new_user_languages']").clear
254
+ browser.select_list(:xpath, "//select[@name='new_user_languages']").select(/ish/)
255
+ browser.select_list(:xpath, "//select[@name='new_user_languages']").selected_options.should == ["Danish", "English", "Swedish"]
256
+ end
257
+ end
258
+
259
+ it "selects empty options" do
260
+ browser.select_list(:id, "delete_user_username").select("")
261
+ browser.select_list(:id, "delete_user_username").selected_options.should == [""]
262
+ end
263
+
264
+ bug "WTR-363", :watir do
265
+ it "returns the value selected" do
266
+ browser.select_list(:name, "new_user_languages").select("Danish").should == "Danish"
267
+ end
268
+
269
+ it "returns the first matching value if there are multiple matches" do
270
+ browser.select_list(:name, "new_user_languages").select(/ish/).should == "Danish"
271
+ end
272
+ end
273
+
274
+ it "fires onchange event when selecting an item" do
275
+ browser.select_list(:id, "new_user_languages").select("Danish")
276
+ messages.should == ['changed language']
277
+ end
278
+
279
+ bug "WTR-364", :watir do
280
+ it "doesn't fire onchange event when selecting an already selected item" do
281
+ browser.select_list(:id, "new_user_languages").clear # removes the two pre-selected options
282
+ browser.select_list(:id, "new_user_languages").select("English")
283
+ messages.size.should == 3
284
+
285
+ browser.select_list(:id, "new_user_languages").select("English")
286
+ messages.size.should == 3
287
+ end
288
+ end
289
+
290
+ it "raises NoValueFoundException if the option doesn't exist" do
291
+ lambda { browser.select_list(:name, "new_user_country").select("missing_option") }.should raise_error(NoValueFoundException)
292
+ lambda { browser.select_list(:name, "new_user_country").select(/missing_option/) }.should raise_error(NoValueFoundException)
293
+ end
294
+ end
295
+
296
+ # deprecate?
297
+ describe "#select_value" do
298
+ it "selects the item by value string" do
299
+ browser.select_list(:name, "new_user_languages").clear
300
+ browser.select_list(:name, "new_user_languages").select_value("2")
301
+ browser.select_list(:name, "new_user_languages").selected_options.should == %w[English]
302
+ end
303
+
304
+ bug "WTR-362", :watir do
305
+ it "selects the items by value regexp" do
306
+ browser.select_list(:name, "new_user_languages").clear
307
+ browser.select_list(:name, "new_user_languages").select_value(/1|3/)
308
+ browser.select_list(:name, "new_user_languages").selected_options.should == %w[Danish Norwegian]
309
+ end
310
+ end
311
+
312
+ it "raises NoValueFoundException if the option doesn't exist" do
313
+ lambda { browser.select_list(:name, "new_user_languages").select_value("no_such_option") }.should raise_error(NoValueFoundException)
314
+ lambda { browser.select_list(:name, "new_user_languages").select_value(/no_such_option/) }.should raise_error(NoValueFoundException)
315
+ end
316
+ end
317
+
318
+ end