Skip to content
Newer
Older
100644 485 lines (399 sloc) 13.2 KB
456b93a @Stuk Added watirspec_helper to all
Stuk authored Nov 17, 2010
1 # encoding: utf-8
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
2 require File.expand_path('../watirspec_helper', __FILE__)
456b93a @Stuk Added watirspec_helper to all
Stuk authored Nov 17, 2010
3
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
4 describe 'Element' do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
5 # Direct attribute access
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
6 before :each do
efb9c88 Using official url=() method, goto() might be deprecated
Andreas Tolf Tolfsen authored Nov 22, 2010
7 browser.url = fixture('non_control_elements.html')
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
8
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
9 @element = window.find_by_id('descartes').first
10 @list = window.find_by_id('navbar').first
11 @leaf = window.find_by_id('link_2').first
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
12 end
2c0bd07 @jarib Initial commit
jarib authored Aug 6, 2009
13
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
14 # parent
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
15 describe '#parent' do
16 it 'is the parent element of an element' do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
17 # Two .parent to get to an IDed element
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
18 @element.parent.parent.attr(:id).should == 'promo'
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
19 end
20
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
21 it 'is nil for the root element' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
22 window.find_by_tag(:html).first.parent.should == nil
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
23 end
24 end
25
215688a @Stuk Added assignment to attr, text and html
Stuk authored Nov 18, 2010
26 # attr(what, value=nil)
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
27 describe '#attr' do
28 it 'gets the value of the given attribute' do
29 @element.attr(:class).should == 'descartes'
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
30 end
31
1294f2f @Stuk Attribute access now uses underscores to be consistant with the sugar
Stuk authored Nov 23, 2010
32 it 'uses underscores instead of dashes' do
33 @leaf.attr(:data_fixture).should == 'leaf'
2292649 @Stuk Added test for attributes with dashes, and ability to set multiple at…
Stuk authored Nov 23, 2010
34 end
35
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
36 it 'is nil when the attribute does not exist' do
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
37 @element.attr(:hoobaflooba).should == nil
38 end
39 end
40
3447308 @Stuk Elements are now sweetened with sugar
Stuk authored Nov 23, 2010
41 describe 'sugar' do
42 it 'provides direct access to the element\'s attributes' do
43 @element.id.should == @element.attr(:id)
55824ad @Stuk Updated Element sugar tests to use class_name rather than class
Stuk authored Dec 10, 2010
44 @element.class_name.should == @element.attr(:class)
45 @element.title.should == @element.attr(:title)
3447308 @Stuk Elements are now sweetened with sugar
Stuk authored Nov 23, 2010
46 end
47
48 it 'uses underscores instead of dashes' do
49 @leaf.data_fixture.should == 'leaf'
50 end
51
52 it 'is nil when the attribute does not exist' do
53 @element.hoobaflooba.should be_nil
54 end
55 end
56
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
57 # text
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
58 describe '#text' do
59 it 'is the text contained by the element' do
60 @element.text.should == 'Dubito, ergo cogito, ergo sum.'
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
61 end
62
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
63 it 'is an empty string when there is no text' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
64 window.find_by_tag(:div).first.text.should == ''
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
65 end
66 end
67
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
68 describe '#text=' do
69 it 'sets the text content of the element' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
70 window.find_by_tag(:em).first.text = 'test'
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
71 @element.text.should == 'Dubito, test, ergo sum.'
215688a @Stuk Added assignment to attr, text and html
Stuk authored Nov 18, 2010
72 end
73
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
74 it 'overwrites child elements' do
75 @element.text = 'test'
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
76 window.find_by_tag(:em).should be_empty
215688a @Stuk Added assignment to attr, text and html
Stuk authored Nov 18, 2010
77 end
78 end
79
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
80 # html
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
81 describe '#html' do
82 it 'is the outer HTML of the element' do
83 @element.html.should == "<strong id='descartes' class='descartes'>Dubito, <em class='important-class' id='important-id' title='ergo cogito'>ergo cogito</em>, ergo sum.</strong>"
c3f76e1 @Stuk Added #html
Stuk authored Nov 17, 2010
84 end
85
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
86 it 'is an empty string if the element contains no text or html' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
87 window.find_by_tag(:body).div.first.html.should == ''
c3f76e1 @Stuk Added #html
Stuk authored Nov 17, 2010
88 end
89 end
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
90
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
91 describe '#html=' do
92 it 'sets the outer HTML of the element' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
93 @element.em.first.html = '<b>test</b>'
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
94 @element.html.should == "<strong id='descartes' class='descartes'>Dubito, <b>test</b>, ergo sum.</strong>"
215688a @Stuk Added assignment to attr, text and html
Stuk authored Nov 18, 2010
95 end
96
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
97 it 'creates child elements' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
98 @element.em.first.html = "<b>one</b> <b class='test'>two</b>"
99 @element.em.length.should == 2
100 @element.em[1].attr(:class).should == 'test'
215688a @Stuk Added assignment to attr, text and html
Stuk authored Nov 18, 2010
101 end
102 end
103
719029f @Stuk added tag_name
Stuk authored Nov 17, 2010
104 # tag_name
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
105 describe '#tag_name' do
106 it 'is the tag name of an element' do
68aae09 @Stuk Changed == to match for testing tag_name case insensitively
Stuk authored Nov 22, 2010
107 @element.tag_name.should match /strong/i
108 @list.tag_name.should match /ul/i
719029f @Stuk added tag_name
Stuk authored Nov 17, 2010
109 end
110 end
111
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
112 # states
113 # ------
114
115 # checked?
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
116 describe '#checked?' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
117 before :each do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
118 browser.url = fixture('forms_with_input_elements.html')
119
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
120 @textbox = window.find_by_id('new_user_username').first
121 @checkbox_checked = window.find_by_id('new_user_interests_books').first
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
122 @checkbox_unchecked = window.find_by_id('new_user_interests_cars').first
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
123 @radio_checked = window.find_by_id('new_user_newsletter_yes').first
124 @radio_unchecked = window.find_by_id('new_user_newsletter_no').first
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
125 end
126
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
127 # TODO 'checked' is available for all <input> and <command>. Change this
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
128 # test?
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
129 it 'exists on radio button elements' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
130 @radio_checked.should respond_to :checked?
131 end
132
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
133 it 'exists on checkbox elements' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
134 @checkbox_checked.should respond_to :checked?
135 end
136
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
137 it 'does not exist on non-checkbox or radio button elements' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
138 @textbox.should_not respond_to :checked?
139 @element.should_not respond_to :checked?
140 end
141
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
142 it 'is true if a checkbox is checked' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
143 @checkbox_checked.checked?.should be_true
144 end
145
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
146 it 'is false if a checkbox is not checked' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
147 @checkbox_unchecked.checked?.should be_false
148 end
149
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
150 it 'is true if a radio button is checked' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
151 @radio_checked.checked?.should be_true
152 end
153
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
154 it 'is false if a radio button is not checked' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
155 @radio_unchecked.checked?.should be_false
156 end
157 end
158
cce19f7 @Stuk Added selected?
Stuk authored Dec 9, 2010
159 describe '#selected?' do
160 before :each do
161 browser.url = fixture('forms_with_input_elements.html')
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
162 @options = window.find_by_id('new_user_country').option
cce19f7 @Stuk Added selected?
Stuk authored Dec 9, 2010
163 end
164
165 it 'is true if an option is selected' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
166 @options[1].selected?.should be_true
cce19f7 @Stuk Added selected?
Stuk authored Dec 9, 2010
167 end
168
169 it 'is false is an option is not selected' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
170 @options[5].selected?.should be_false
cce19f7 @Stuk Added selected?
Stuk authored Dec 9, 2010
171 end
172
173 it 'is true for multiple selected options' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
174 multi = window.find_by_id('new_user_languages').option
cce19f7 @Stuk Added selected?
Stuk authored Dec 9, 2010
175 multi[1].selected?.should be_true
176 multi[2].selected?.should be_true
177 end
178
179 it 'is false for unselected in a multiple select' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
180 multi = window.find_by_id('new_user_languages').option
cce19f7 @Stuk Added selected?
Stuk authored Dec 9, 2010
181 multi[0].selected?.should be_false
182 multi[3].selected?.should be_false
183 end
184
185 it 'is nil on non-option elements' do
186 @element.selected?.should be_nil
187 end
188 end
189
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
190 # enabled?
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
191 describe '#enabled?' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
192 before :each do
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
193 browser.url = fixture('forms_with_input_elements.html')
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
194 @inputs = window.find_by_tag(:input)
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
195 end
196
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
197 # 'disabled' attribute is available on quite a few obscure
198 # elements. Toss up between limiting to common ones, all html5,
199 # all elements that have a .disabled property in Javascript, or
200 # all elements
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
201 it 'exists on input elements' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
202 @inputs.all? do |input|
203 input.respond_to? :enabled?
204 end.should be_true
205 end
206 end
207
208 # visible?
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
209 describe '#visible?' do
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
210 before :each do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
211 browser.url = fixture('visible.html')
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
212 end
213
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
214 it 'is true for a visible element' do
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
215 window.find_by_tag(:h1).first.visible?.should be_true
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
216 end
217
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
218 it 'is false for an element with style attribute “display:none”' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
219 window.find_by_id('parent').first.visible?.should be_false
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
220 end
221
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
222 it 'is false a child of an element with style attribute “display:none”' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
223 window.find_by_id('child').first.visible?.should be_false
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
224 end
225
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
226 it 'is false for an element hidden by CSS' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
227 window.find_by_id('hidden_by_css').first.visible?.should be_false
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
228 end
229
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
230 it 'is true for an element with visibility:hidden' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
231 window.find_by_id('invisible').first.visible?.should be_true
a4401a6 @Stuk Spec'd that visible? is true for visibility:hidden
Stuk authored Nov 22, 2010
232 end
233
71d0acf @Stuk Added checked?, enabled? and visible?
Stuk authored Nov 17, 2010
234 end
235
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
236 # actions
237 # -------
238
d682c23 @Stuk Added focus! to element
Stuk authored Nov 22, 2010
239 # focus!
2292649 @Stuk Added test for attributes with dashes, and ability to set multiple at…
Stuk authored Nov 23, 2010
240 describe '#focus!' do
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
241 before :each do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
242 browser.url = fixture('forms_with_input_elements.html')
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
243 end
244
245 it 'focuses the element' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
246 input = window.find_by_id('new_user_email').first
d682c23 @Stuk Added focus! to element
Stuk authored Nov 22, 2010
247 input.focus!
248 window.type('test')
249 input.attr(:value).should == 'test'
250 end
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
251
252 it 'returns false if the element is disabled' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
253 input = window.find_by_id('new_user_species').first
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
254 input.focus!.should be_false
255 end
d682c23 @Stuk Added focus! to element
Stuk authored Nov 22, 2010
256 end
257
0ab3e66 Removing action mutations
Andreas Tolf Tolfsen authored Feb 3, 2011
258 # click([x, y]) , x,y relative to element top left
259 describe '#click' do
adb266f @Stuk Added click!
Stuk authored Nov 22, 2010
260 it 'follows links' do
0ab3e66 Removing action mutations
Andreas Tolf Tolfsen authored Feb 3, 2011
261 window.find_by_id('link_3').first.click
adb266f @Stuk Added click!
Stuk authored Nov 22, 2010
262 window.url.should match /forms_with_input_elements\.html$/
263 end
264
265 it 'triggers onclick handlers' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
266 div = window.find_by_id('best_language').first
0ab3e66 Removing action mutations
Andreas Tolf Tolfsen authored Feb 3, 2011
267 div.click
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
268 div.text.should == 'Ruby!'
adb266f @Stuk Added click!
Stuk authored Nov 22, 2010
269 end
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
270
271 it 'toggles checkboxes' do
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
272 browser.url = fixture('forms_with_input_elements.html')
273 checkbox = window.find_by_id('new_user_interests_cars').first
274 checkbox.checked?.should be_false
0ab3e66 Removing action mutations
Andreas Tolf Tolfsen authored Feb 3, 2011
275 checkbox.click
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
276 checkbox.checked?.should be_true
0ab3e66 Removing action mutations
Andreas Tolf Tolfsen authored Feb 3, 2011
277 checkbox.click
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
278 checkbox.checked?.should be_false
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
279 end
280
281 # TODO work out whether #selected? exists, and whether it replaces
282 # #checked?
283 it 'can click option elements' do
284 browser.url = fixture('forms_with_input_elements.html')
285
286 select = window.find_by_id('new_user_country')
0ab3e66 Removing action mutations
Andreas Tolf Tolfsen authored Feb 3, 2011
287 select.click
288 select.option[0].click
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
289 select.option[0].selected?.should be_true
290 end
fd2abb0 Adding testcase for WTR-354 concerning coordinates for clicking
Andreas Tolf Tolfsen authored May 25, 2011
291
292 it 'submits form when clicking a LABEL element tied to form submission' do
293 browser.url = fixture('label_submit.html')
294 window.find_by_tag('label').click
295 window.text.should include 'PASS'
296 end
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
297 end
298
299 describe '#mouse_down!' do
300 it 'triggers a mousedown event' do
301 browser.url = fixture('mouse.html')
302 log = window.find_by_id('log').first
303 log.mouse_down! 0, 0
304 log.text.should include 'down'
305 log.mouse_up! 0, 0
306 end
307 end
308
309 describe '#mouse_up' do
310 it 'triggers a mouseup event' do
311 browser.url = fixture('mouse.html')
312 log = window.find_by_id('log').first
313 log.mouse_down! 0, 0
314 log.mouse_up! 0, 0
315 log.text.should include 'up'
316 end
317 end
318
319 describe '#mouse_move' do
320 it 'triggers a mousemove event' do
321 browser.url = fixture('mouse.html')
322 log = window.find_by_id('log').first
323 log.mouse_move! 0, 0
324 log.text.should include 'move'
325 end
326
327 it 'moves the mouse' do
328 browser.url = fixture('mouse.html')
329 log = window.find_by_id('log').first
330 h1 = window.find_by_tag('h1').first
331
332 h1.mouse_down! 0, 0
333 h1.mouse_move! 25, 25
334 h1.mouse_up! 50, 50
335
336 window.eval_js('!!document.getSelection()').should be_true
337 end
adb266f @Stuk Added click!
Stuk authored Nov 22, 2010
338 end
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
339
340 # check!
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
341 describe '#check!' do
342 before :each do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
343 browser.url = fixture('forms_with_input_elements.html')
bb0b139 @Stuk hash -> visual hash, small fixes
Stuk authored Dec 10, 2010
344 @checkbox_unchecked = window.find_by_id('new_user_interests_cars').first
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
345 @radio_unchecked = window.find_by_id('new_user_newsletter_no').first
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
346 end
347
348 it 'checks a checkbox' do
349 @checkbox_unchecked.check!
350 @checkbox_unchecked.checked?.should be_true
351 end
352
353 it 'checks a radio button' do
354 @radio_unchecked.check!
355 @radio_unchecked.checked?.should be_true
356 end
357 end
260b3c5 Merged
Andreas Tolf Tolfsen authored Mar 7, 2011
358
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
359 # uncheck!
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
360 describe '#uncheck!' do
361 before :each do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
362 browser.url = fixture('forms_with_input_elements.html')
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
363 @checkbox_checked = window.find_by_id('new_user_interests_books').first
364 @radio_checked = window.find_by_id('new_user_newsletter_yes').first
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
365 end
366
367 it 'unchecks a checkbox' do
368 @checkbox_checked.uncheck!
369 @checkbox_checked.checked?.should be_false
370 end
371
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
372 it 'cannot uncheck a radio button' do
373 @radio_checked.uncheck!.should raise_error
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
374 end
375 end
376
c202989 Fixed fire_event tests, commented out some parts of the spec that mig…
Andreas Tolf Tolfsen authored Mar 7, 2011
377 =begin
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
378 # toggle_check!
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
379 describe '#toggle_check!' do
380 before :each do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
381 browser.url = fixture('forms_with_input_elements.html')
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
382 @checkbox_checked = window.find_by_id('new_user_interests_books').first
383 @radio_checked = window.find_by_id('new_user_newsletter_yes').first
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
384 end
385
386 it 'toggles a checkbox' do
387 @checkbox_checked.toggle_check!
388 @checkbox_checked.checked?.should be_false
389 @checkbox_checked.toggle_check!
390 @checkbox_checked.checked?.should be_true
391 end
392
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
393 it 'does not appear on a radio button' do
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
394 @radio_checked.should_not respond_to :toggle_check!
395 end
396 end
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
397
398 # enable!
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
399 describe '#enable!' do
400 it 'enables a form element' do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
401 window.url = fixture('forms_with_input_elements.html')
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
402 disabled = window.find_by_id('new_user_species').first
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
403 disabled.enabled?.should be_false
404 disabled.enable!
405 disabled.enabled?.should be_true
406 end
407 end
c202989 Fixed fire_event tests, commented out some parts of the spec that mig…
Andreas Tolf Tolfsen authored Mar 7, 2011
408
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
409 # disable!
92d0ce3 @Stuk Corrected second #enable! to #disable!
Stuk authored Dec 9, 2010
410 describe '#disable!' do
411 it 'disables a form element' do
680e968 Formtting
Andreas Tolf Tolfsen authored Nov 22, 2010
412 window.url = fixture('forms_with_input_elements.html')
2ec3456 @Stuk A few small fixes
Stuk authored Dec 10, 2010
413 disabled = window.find_by_id('new_user_email').first
1a792db @Stuk Added enable! and disable! and extra focused? test
Stuk authored Nov 22, 2010
414 disabled.enabled?.should be_true
415 disabled.disable!
416 disabled.enabled?.should be_false
417 end
418 end
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
419
420 # show!
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
421 describe '#show!' do
422 it 'makes the element visible' do
933278d @Stuk Eliminated all of the children
Stuk authored Dec 6, 2010
423 hidden = window.find_by_id('hidden').first
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
424 hidden.visible?.should be_false
425 hidden.show!
426 hidden.visible?.should be_true
427 end
428 end
429
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
430 # hide!
b4c7449 Using single quotes
Andreas Tolf Tolfsen authored Nov 22, 2010
431 describe '#hide!' do
e8b9381 @Stuk Added check!, uncheck!, toggle_check!, show! and hide!
Stuk authored Nov 22, 2010
432 it 'sets the element to display:none' do
433 @element.visible?.should be_true
434 hidden.hide!
435 hidden.visible?.should be_false
436 end
437 end
c202989 Fixed fire_event tests, commented out some parts of the spec that mig…
Andreas Tolf Tolfsen authored Mar 7, 2011
438 =end
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
439
a1ef8c0 trigger! → fire_event
Wilhelm Joys Andersen authored Feb 21, 2011
440 describe '#fire_event' do
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
441 it 'fires the given event on the element' do
a1ef8c0 trigger! → fire_event
Wilhelm Joys Andersen authored Feb 21, 2011
442 window.find_by_id('link_3').fire_event :click
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
443 browser.url.should include 'forms_with_input_elements.html'
444 end
445
446 it 'fires event handlers' do
a1ef8c0 trigger! → fire_event
Wilhelm Joys Andersen authored Feb 21, 2011
447 window.find_by_id('html_test').first.fire_event :dblclick
4251dc6 @Stuk Added hash, extra click! test, mouse_down!, mouse_up!, mouse_move! an…
Stuk authored Dec 8, 2010
448 window.find_by_id('messages').first.text.should include 'double clicked'
449 end
450 end
451
118edf0 @Stuk Changed html() to return outer rather than inner HTML, to match Watir…
Stuk authored Nov 17, 2010
452 # attributes
8a81968 @Stuk Started tests/spec for the element class
Stuk authored Nov 16, 2010
453 # ----------
454
455 # style
2c0bd07 @jarib Initial commit
jarib authored Aug 6, 2009
456
f6b4b6f Added tests for drag and drop.
Wilhelm Joys Andersen authored Feb 15, 2011
457
458
459 # drag and drop
460 # -------------
461
462 describe '#drag_and_drop_by' do
463 it 'drags an element 100 pixels right and down' do
464 browser.url = fixture('draggable.html')
465 @draggable = window.find_by_id('draggable')
466
467 @draggable.location.to_s.should == 'x100y100'
468 @draggable.drag_and_drop_by(100,100)
469 @draggable.location.to_s.should == 'x200y200'
470 end
471 end
472
473 describe '#drag_and_drop_on' do
474 it 'drags one element onto another, triggering the correct events' do
475 browser.url = fixture('draggable.html')
476 @draggable = window.find_by_id('draggable')
477 @droppable = window.find_by_id('droppable')
478
479 @draggable.drag_and_drop_on(@droppable)
480 @droppable.text.should include 'Om nom nom!'
481 end
482 end
483
2c0bd07 @jarib Initial commit
jarib authored Aug 6, 2009
484 end
Something went wrong with that request. Please try again.