watir-webdriver 0.0.1.dev
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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/.gitmodules +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +107 -0
- data/TODO +15 -0
- data/VERSION +1 -0
- data/lib/watir-webdriver.rb +74 -0
- data/lib/watir-webdriver/base_element.rb +347 -0
- data/lib/watir-webdriver/browser.rb +130 -0
- data/lib/watir-webdriver/browserbot.js +34 -0
- data/lib/watir-webdriver/collections/buttons_collection.rb +13 -0
- data/lib/watir-webdriver/collections/element_collection.rb +45 -0
- data/lib/watir-webdriver/collections/table_rows_collection.rb +14 -0
- data/lib/watir-webdriver/collections/text_fields_collection.rb +13 -0
- data/lib/watir-webdriver/container.rb +24 -0
- data/lib/watir-webdriver/core_ext/string.rb +22 -0
- data/lib/watir-webdriver/elements/button.rb +27 -0
- data/lib/watir-webdriver/elements/checkbox.rb +23 -0
- data/lib/watir-webdriver/elements/file_field.rb +20 -0
- data/lib/watir-webdriver/elements/form.rb +11 -0
- data/lib/watir-webdriver/elements/generated.rb +941 -0
- data/lib/watir-webdriver/elements/headings.rb +48 -0
- data/lib/watir-webdriver/elements/hidden.rb +18 -0
- data/lib/watir-webdriver/elements/image.rb +33 -0
- data/lib/watir-webdriver/elements/input.rb +39 -0
- data/lib/watir-webdriver/elements/link.rb +13 -0
- data/lib/watir-webdriver/elements/option.rb +36 -0
- data/lib/watir-webdriver/elements/radio.rb +23 -0
- data/lib/watir-webdriver/elements/select_list.rb +73 -0
- data/lib/watir-webdriver/elements/shared_radio_checkbox.rb +13 -0
- data/lib/watir-webdriver/elements/table.rb +18 -0
- data/lib/watir-webdriver/elements/table_row.rb +17 -0
- data/lib/watir-webdriver/elements/text_field.rb +60 -0
- data/lib/watir-webdriver/exception.rb +20 -0
- data/lib/watir-webdriver/locators/button_locator.rb +57 -0
- data/lib/watir-webdriver/locators/element_locator.rb +269 -0
- data/lib/watir-webdriver/locators/table_row_locator.rb +25 -0
- data/lib/watir-webdriver/locators/text_field_locator.rb +61 -0
- data/lib/watir-webdriver/xpath_support.rb +23 -0
- data/spec/element_locator_spec.rb +11 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/watirspec/area_spec.rb +78 -0
- data/spec/watirspec/areas_spec.rb +31 -0
- data/spec/watirspec/browser_spec.rb +262 -0
- data/spec/watirspec/button_spec.rb +242 -0
- data/spec/watirspec/buttons_spec.rb +48 -0
- data/spec/watirspec/checkbox_spec.rb +272 -0
- data/spec/watirspec/checkboxes_spec.rb +32 -0
- data/spec/watirspec/dd_spec.rb +136 -0
- data/spec/watirspec/dds_spec.rb +31 -0
- data/spec/watirspec/div_spec.rb +222 -0
- data/spec/watirspec/divs_spec.rb +31 -0
- data/spec/watirspec/dl_spec.rb +136 -0
- data/spec/watirspec/dls_spec.rb +32 -0
- data/spec/watirspec/dt_spec.rb +136 -0
- data/spec/watirspec/dts_spec.rb +31 -0
- data/spec/watirspec/element_spec.rb +87 -0
- data/spec/watirspec/em_spec.rb +110 -0
- data/spec/watirspec/ems_spec.rb +32 -0
- data/spec/watirspec/filefield_spec.rb +119 -0
- data/spec/watirspec/filefields_spec.rb +32 -0
- data/spec/watirspec/form_spec.rb +63 -0
- data/spec/watirspec/forms_spec.rb +33 -0
- data/spec/watirspec/frame_spec.rb +140 -0
- data/spec/watirspec/frames_spec.rb +62 -0
- data/spec/watirspec/hidden_spec.rb +102 -0
- data/spec/watirspec/hiddens_spec.rb +32 -0
- data/spec/watirspec/hn_spec.rb +93 -0
- data/spec/watirspec/hns_spec.rb +38 -0
- data/spec/watirspec/image_spec.rb +207 -0
- data/spec/watirspec/images_spec.rb +31 -0
- data/spec/watirspec/label_spec.rb +75 -0
- data/spec/watirspec/labels_spec.rb +31 -0
- data/spec/watirspec/li_spec.rb +127 -0
- data/spec/watirspec/lib/guards.rb +59 -0
- data/spec/watirspec/lib/server.rb +127 -0
- data/spec/watirspec/lib/spec_helper.rb +79 -0
- data/spec/watirspec/lib/watirspec.rb +72 -0
- data/spec/watirspec/link_spec.rb +165 -0
- data/spec/watirspec/links_spec.rb +35 -0
- data/spec/watirspec/lis_spec.rb +31 -0
- data/spec/watirspec/map_spec.rb +92 -0
- data/spec/watirspec/maps_spec.rb +32 -0
- data/spec/watirspec/meta_spec.rb +22 -0
- data/spec/watirspec/metas_spec.rb +30 -0
- data/spec/watirspec/ol_spec.rb +78 -0
- data/spec/watirspec/ols_spec.rb +31 -0
- data/spec/watirspec/option_spec.rb +173 -0
- data/spec/watirspec/p_spec.rb +143 -0
- data/spec/watirspec/pre_spec.rb +125 -0
- data/spec/watirspec/pres_spec.rb +31 -0
- data/spec/watirspec/ps_spec.rb +31 -0
- data/spec/watirspec/radio_spec.rb +278 -0
- data/spec/watirspec/radios_spec.rb +32 -0
- data/spec/watirspec/select_list_spec.rb +318 -0
- data/spec/watirspec/select_lists_spec.rb +35 -0
- data/spec/watirspec/span_spec.rb +157 -0
- data/spec/watirspec/spans_spec.rb +57 -0
- data/spec/watirspec/spec_helper.rb +17 -0
- data/spec/watirspec/strong_spec.rb +89 -0
- data/spec/watirspec/strongs_spec.rb +32 -0
- data/spec/watirspec/table_bodies_spec.rb +45 -0
- data/spec/watirspec/table_body_spec.rb +98 -0
- data/spec/watirspec/table_cell_spec.rb +68 -0
- data/spec/watirspec/table_cells_spec.rb +47 -0
- data/spec/watirspec/table_footer_spec.rb +85 -0
- data/spec/watirspec/table_footers_spec.rb +47 -0
- data/spec/watirspec/table_header_spec.rb +85 -0
- data/spec/watirspec/table_headers_spec.rb +45 -0
- data/spec/watirspec/table_row_spec.rb +87 -0
- data/spec/watirspec/table_rows_spec.rb +50 -0
- data/spec/watirspec/table_spec.rb +166 -0
- data/spec/watirspec/tables_spec.rb +33 -0
- data/spec/watirspec/text_field_spec.rb +276 -0
- data/spec/watirspec/text_fields_spec.rb +35 -0
- data/spec/watirspec/ul_spec.rb +76 -0
- data/spec/watirspec/uls_spec.rb +33 -0
- data/spec/xpath_builder_spec.rb +49 -0
- data/support/html5/html5.idl +815 -0
- data/support/html5/html5_extras.idl +147 -0
- data/support/html5/idl_extractor.rb +73 -0
- data/support/html5/watir_visitor.rb +169 -0
- metadata +220 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
describe "Pres" 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 pres" do
|
12
|
+
browser.pres.length.should == 7
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#[]" do
|
17
|
+
it "returns the pre at the given index" do
|
18
|
+
browser.pres[1].id.should == "rspec"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#each" do
|
23
|
+
it "iterates through pres correctly" do
|
24
|
+
browser.pres.each_with_index do |p, index|
|
25
|
+
p.id.should == browser.pre(:index, index).id
|
26
|
+
p.value.should == browser.pre(:index, index).value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -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,278 @@
|
|
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
|
+
# Manipulation methods
|
190
|
+
describe "#clear" do
|
191
|
+
it "clears the radio button if it is set" do
|
192
|
+
browser.radio(:id, "new_user_newsletter_yes").clear
|
193
|
+
browser.radio(:id, "new_user_newsletter_yes").should_not be_set
|
194
|
+
end
|
195
|
+
|
196
|
+
it "clears the radio button when found by :xpath" do
|
197
|
+
browser.radio(:xpath, "//input[@id='new_user_newsletter_yes']").clear
|
198
|
+
browser.radio(:xpath, "//input[@id='new_user_newsletter_yes']").should_not be_set
|
199
|
+
end
|
200
|
+
|
201
|
+
it "raises UnknownObjectException if the radio button doesn't exist" do
|
202
|
+
lambda { browser.radio(:name, "no_such_id").clear }.should raise_error(UnknownObjectException)
|
203
|
+
lambda { browser.radio(:xpath, "//input[@id='no_such_id']").clear }.should raise_error(UnknownObjectException)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "raises ObjectDisabledException if the radio is disabled" do
|
207
|
+
browser.radio(:id, "new_user_newsletter_nah").should_not be_set
|
208
|
+
lambda { browser.radio(:id, "new_user_newsletter_nah").clear }.should raise_error(ObjectDisabledException)
|
209
|
+
lambda { browser.radio(:xpath, "//input[@id='new_user_newsletter_nah']").clear }.should raise_error(ObjectDisabledException)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#set" do
|
214
|
+
it "sets the radio button" do
|
215
|
+
browser.radio(:id, "new_user_newsletter_no").set
|
216
|
+
browser.radio(:id, "new_user_newsletter_no").should be_set
|
217
|
+
end
|
218
|
+
|
219
|
+
it "sets the radio button when found by :xpath" do
|
220
|
+
browser.radio(:xpath, "//input[@id='new_user_newsletter_no']").set
|
221
|
+
browser.radio(:xpath, "//input[@id='new_user_newsletter_no']").should be_set
|
222
|
+
end
|
223
|
+
|
224
|
+
it "fires the onclick event" do
|
225
|
+
browser.radio(:id, "new_user_newsletter_no").set
|
226
|
+
browser.radio(:id, "new_user_newsletter_yes").set
|
227
|
+
messages.should == ["clicked: new_user_newsletter_no", "clicked: new_user_newsletter_yes"]
|
228
|
+
end
|
229
|
+
|
230
|
+
bug "WTR-337", :watir do
|
231
|
+
it "fires the onchange event" do
|
232
|
+
browser.radio(:value, 'certainly').set
|
233
|
+
messages.should == ["changed: new_user_newsletter"]
|
234
|
+
|
235
|
+
browser.radio(:value, 'certainly').set
|
236
|
+
messages.should == ["changed: new_user_newsletter"] # no event fired here - didn't change
|
237
|
+
|
238
|
+
browser.radio(:value, 'certainly').clear
|
239
|
+
messages.should == ["changed: new_user_newsletter", "changed: new_user_newsletter"]
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it "raises UnknownObjectException if the radio button doesn't exist" do
|
244
|
+
lambda { browser.radio(:name, "no_such_name").set }.should raise_error(UnknownObjectException)
|
245
|
+
lambda { browser.radio(:xpath, "//input[@name='no_such_name']").set }.should raise_error(UnknownObjectException)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "raises ObjectDisabledException if the radio is disabled" do
|
249
|
+
lambda { browser.radio(:id, "new_user_newsletter_nah").set }.should raise_error(ObjectDisabledException)
|
250
|
+
lambda { browser.radio(:xpath, "//input[@id='new_user_newsletter_nah']").set }.should raise_error(ObjectDisabledException )
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
# Other
|
255
|
+
describe '#set?' do
|
256
|
+
it "returns true if the radio button is set" do
|
257
|
+
browser.radio(:id, "new_user_newsletter_yes").should be_set
|
258
|
+
end
|
259
|
+
|
260
|
+
it "returns false if the radio button unset" do
|
261
|
+
browser.radio(:id, "new_user_newsletter_no").should_not be_set
|
262
|
+
end
|
263
|
+
|
264
|
+
it "returns the state for radios with string values" do
|
265
|
+
browser.radio(:name => "new_user_newsletter", :value => 'no').should_not be_set
|
266
|
+
browser.radio(:name => "new_user_newsletter", :value => 'no').set
|
267
|
+
browser.radio(:name => "new_user_newsletter", :value => 'no').should be_set
|
268
|
+
browser.radio(:name => "new_user_newsletter", :value => 'no').clear
|
269
|
+
browser.radio(:name => "new_user_newsletter", :value => 'no').should_not be_set
|
270
|
+
end
|
271
|
+
|
272
|
+
it "raises UnknownObjectException if the radio button doesn't exist" do
|
273
|
+
lambda { browser.radio(:id, "no_such_id").set? }.should raise_error(UnknownObjectException)
|
274
|
+
lambda { browser.radio(:xpath, "//input[@id='no_such_id']").set? }.should raise_error(UnknownObjectException)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
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
|