forked from sparklemotion/mechanize
/
test_radiobutton.rb
63 lines (53 loc) · 2.21 KB
/
test_radiobutton.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
class TestRadioButtons < Test::Unit::TestCase
def setup
@agent = WWW::Mechanize.new
@page = @agent.get("http://localhost/tc_radiobuttons.html")
end
def test_select_all
form = @page.forms.first
form.radiobuttons_with(:name => 'color').each do |b|
b.check
end
form.radiobutton_with(:name => 'color', :value => 'green').check
assert_equal(true, form.radiobutton_with( :name => 'color',
:value => 'green').checked)
%w{ red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_unselect_all
form = @page.forms.first
form.radiobuttons_with(:name => 'color').each do |b|
b.uncheck
end
%w{ green red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_click_one
form = @page.forms.first
form.radiobutton_with(:name => 'color', :value => 'green').click
assert form.radiobutton_with(:name => 'color', :value => 'green').checked
%w{ red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_click_twice
form = @page.forms.first
form.radiobutton_with(:name => 'color', :value => 'green').click
assert form.radiobutton_with(:name => 'color', :value => 'green').checked
form.radiobutton_with(:name => 'color', :value => 'green').click
%w{ green red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
end