honey-do 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +11 -0
- data/README +120 -0
- data/Rakefile +76 -0
- data/bin/start_selenium_proxy.bat +4 -0
- data/bin/start_selenium_proxy.sh +3 -0
- data/demo/display/webrick_servlet_needs_this_folder.txt +0 -0
- data/demo/page/everything.html +112 -0
- data/demo/page/everything.js +55 -0
- data/demo/webrick-servlet.rb +58 -0
- data/doc/INSTALLATION +20 -0
- data/doc/running_the_tests.rdoc +81 -0
- data/functional_testcase/functional_testcase.rb +99 -0
- data/js/user-extensions.js +359 -0
- data/lib/hash.rb +28 -0
- data/lib/honey_do.rb +257 -0
- data/lib/symbol.rb +6 -0
- data/test/checkbox_test.rb +118 -0
- data/test/events_test.rb +75 -0
- data/test/fast_and_pretty_test.rb +66 -0
- data/test/file_upload_test.rb +34 -0
- data/test/general_form_test.rb +205 -0
- data/test/hidden_and_disabled_field_test.rb +51 -0
- data/test/radio_button_test.rb +42 -0
- data/test/select_list_test.rb +155 -0
- data/test/submit_test.rb +82 -0
- data/test/test_master.rb +18 -0
- data/test/textarea_test.rb +92 -0
- metadata +114 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
|
3
|
+
class TestCheckboxFeatures < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# elements with no value are clicked
|
6
|
+
def test_checkbox_name_without_value_toggles
|
7
|
+
browser.set_form_values(:hackzall)
|
8
|
+
assert_equal("on", browser.get_form_values[:hackzall], "clicked: toggled 'on'")
|
9
|
+
|
10
|
+
browser.set_form_values(:hackzall)
|
11
|
+
assert_nil(browser.get_form_values[:hackzall], "clicked: toggled off")
|
12
|
+
end
|
13
|
+
|
14
|
+
# elements with no value are clicked
|
15
|
+
def test_checkbox_name_with_nil_value_toggles
|
16
|
+
browser.set_form_values(:hackzall => nil)
|
17
|
+
assert_equal("on", browser.get_form_values[:hackzall], "clicked: toggled 'on'")
|
18
|
+
|
19
|
+
browser.set_form_values(:hackzall => nil)
|
20
|
+
assert_nil(browser.get_form_values[:hackzall], "clicked: toggled off")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_checkbox_in_group_needs_value
|
24
|
+
assert_raise(RuntimeError) do
|
25
|
+
browser.set_form_values(:extras, :retry_max => 0)
|
26
|
+
end
|
27
|
+
|
28
|
+
browser.set_form_values(:extras => "printer")
|
29
|
+
assert(browser.get_form_values.has_key?(:extras), "grouped checkbox is set")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_nil_group_checkbox_value_is_first_item
|
33
|
+
test_input = "nil value sets first checkbox in group"
|
34
|
+
assert_nothing_raised(RuntimeError) do
|
35
|
+
browser.set_form_values(:extras => nil)
|
36
|
+
end
|
37
|
+
value_set_by_nil_input = browser.get_form_values[:extras]
|
38
|
+
assert_equal("burner", value_set_by_nil_input, test_input)
|
39
|
+
|
40
|
+
browser.set_form_values([:resetButton, [:extras, 0]])
|
41
|
+
|
42
|
+
assert_equal(value_set_by_nil_input, browser.get_form_values[:extras], test_input)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_checkbox_in_group_can_be_set_by_index
|
46
|
+
assert_nothing_raised(RuntimeError) do
|
47
|
+
browser.set_form_values(:extras => 1)
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal("printer", browser.get_form_values[:extras])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_true_false
|
54
|
+
browser.set_form_values(:hackzall => "true", "disk manager" => true)
|
55
|
+
verify_checked(["hackzall", "disk manager"], "'true' turns on 'checked'")
|
56
|
+
|
57
|
+
browser.set_form_values(:hackzall => false, "a-clock.exe" => :true)
|
58
|
+
verify_checked(["a-clock.exe", "disk manager"], "'false' turns off 'checked'")
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_check_uncheck
|
62
|
+
browser.set_form_values(:hackzall => :check, "disk manager" => "check")
|
63
|
+
verify_checked(["hackzall", "disk manager"], "'check' turns on 'checked'")
|
64
|
+
|
65
|
+
browser.set_form_values(:hackzall => :uncheck, "a-clock.exe" => :check)
|
66
|
+
verify_checked(["a-clock.exe", "disk manager"], "'uncheck' turns off 'checked'")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_on_off
|
70
|
+
browser.set_form_values(:hackzall => :on, "disk manager" => :on)
|
71
|
+
verify_checked(["hackzall", "disk manager"], "'on' turns on 'checked'")
|
72
|
+
|
73
|
+
browser.set_form_values(:hackzall => :off, "a-clock.exe" => :on)
|
74
|
+
verify_checked(["a-clock.exe", "disk manager"], "'off' turns off 'checked'")
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_checkbox_set_all_clear_all
|
78
|
+
browser.set_all_checkboxes
|
79
|
+
|
80
|
+
verify_checked(["extras", "extras", "extras", "disk manager", "hackzall", "a-clock.exe", "version control client"], "all set")
|
81
|
+
|
82
|
+
browser.clear_checkboxes
|
83
|
+
verify_checked([], "none set")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_check_multiple_in_group
|
87
|
+
browser.set_form_values([[:extras, "burner"], [:extras, "printer"]])
|
88
|
+
|
89
|
+
values_read_from_screen = browser.get_form_values
|
90
|
+
compound_values = values_read_from_screen.split_compound_values
|
91
|
+
|
92
|
+
assert_equal("burner|printer", values_read_from_screen[:extras])
|
93
|
+
assert_equal("burner", compound_values[:extras])
|
94
|
+
assert_equal("printer", compound_values[:extras_1])
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_check_multiple_independents
|
98
|
+
checkboxes = ["hackzall", "a-clock.exe"]
|
99
|
+
browser.set_form_values(checkboxes)
|
100
|
+
|
101
|
+
test_intent = "submitted same as checked"
|
102
|
+
verify_checked(checkboxes, test_intent)
|
103
|
+
assert_equal("on", browser.get_form_values[:hackzall], test_intent)
|
104
|
+
assert_equal("on", browser.get_form_values[:"a-clock.exe"], test_intent)
|
105
|
+
end
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
def setup
|
110
|
+
super
|
111
|
+
browser.open("everything.html")
|
112
|
+
end
|
113
|
+
|
114
|
+
def verify_checked(expected_checkboxes, test_intent)
|
115
|
+
assert_equal(expected_checkboxes.sort, browser.get_all_checked.sort, test_intent)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
data/test/events_test.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
|
3
|
+
class TestEvents < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_any_element_and_reset_events
|
6
|
+
# click or set a value on one of the elements
|
7
|
+
element_count = browser.get_form_elements.split(',').size
|
8
|
+
any_old_element_index = rand(element_count)
|
9
|
+
|
10
|
+
# clickable and checkable types will ignore the value
|
11
|
+
browser.set_form_values(any_old_element_index => 1)
|
12
|
+
|
13
|
+
assert_not_nil(browser.get_form_values[:event_reports_area], "element index: #{any_old_element_index}\nsomething was captured in the trace in the event log textarea")
|
14
|
+
|
15
|
+
browser.set_form_values(:resetButton)
|
16
|
+
assert_match(":resetButton (Reset)", browser.get_form_values[:event_reports_area], "only 'Reset' events in the trace")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_clear_and_submit_events
|
20
|
+
browser.set_form_values(:username => @method_name)
|
21
|
+
verify_event_trace(":username (#@method_name)", :username)
|
22
|
+
|
23
|
+
browser.set_form_values(:clearButton)
|
24
|
+
verify_event_trace(':clearButton (Clear)', :clearButton)
|
25
|
+
|
26
|
+
browser.set_form_values(:submitButton)
|
27
|
+
verify_event_trace(':submitButton (Submit)',:submitButton)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_single_select_events
|
31
|
+
# select by option text
|
32
|
+
browser.set_form_values(:color => "Blue" )
|
33
|
+
verify_event_trace(":color (blue )", :color)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_multi_select_events
|
37
|
+
# input by array: allow repeated 'name' for multi-select
|
38
|
+
browser.set_form_values([[:hobbies, 0], # option index
|
39
|
+
[:hobbies, "Surfing the"], # displayed label text (pattern anchored to ^)
|
40
|
+
[:hobbies, "Annoying my friends"]])
|
41
|
+
|
42
|
+
verify_event_trace(/:hobbies \(programming \)[\w\W]*:hobbies \(programming surfing \)[\w\W]*:hobbies \(programming surfing annoying \)/, :hobbies)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_checkbox_events
|
46
|
+
# independent checkbox
|
47
|
+
browser.set_form_values("version control client" )
|
48
|
+
verify_event_trace("version control client (on)", "version control client")
|
49
|
+
|
50
|
+
# group item -- use a hash if you just want one
|
51
|
+
browser.set_form_values(:extras => "printer" )
|
52
|
+
verify_event_trace(":extras (printer)", :extras)
|
53
|
+
|
54
|
+
# group item -- use an array if you just want more than one; also, the order will guaranteed
|
55
|
+
browser.set_form_values([[:extras, "burner"], [:extras, "card"]])
|
56
|
+
|
57
|
+
verify_event_trace(/:extras \(burner\)[\w\W]*:extras \(card\)/, :extras)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_radio_button_events
|
61
|
+
browser.set_form_values(:browser => "ff")
|
62
|
+
verify_event_trace(":browser (ff)",:browser)
|
63
|
+
|
64
|
+
browser.set_form_values(:browser => "ie")
|
65
|
+
verify_event_trace(":browser (ie)", :browser)
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def setup
|
71
|
+
super
|
72
|
+
browser.open("everything.html")
|
73
|
+
browser.set_form_values(:enableEventsButton, :form_name_or_index => "events_button_form")
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
class TestFastAndPretty < Test::Unit::TestCase
|
5
|
+
include Benchmark
|
6
|
+
|
7
|
+
def test_one_field_at_a_time_honey_do_time
|
8
|
+
report_time(:one_field_at_a_time_input)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_honey_do_time
|
12
|
+
report_time(:honey_do_input)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_selenium_time
|
16
|
+
report_time(:selenium_input)
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def report_time(input_method_name)
|
22
|
+
n = 10
|
23
|
+
time = realtime() do
|
24
|
+
n.times do
|
25
|
+
browser.set_form_values(:resetButton)
|
26
|
+
send(input_method_name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@@print_buffer << "*** *** #{@method_name.upcase} *** ***"
|
30
|
+
@@print_buffer << "#{input_method_name}, setting whole form #{n} times: #{time}\n\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
INPUT_DATA = {:username => "yes_dear",
|
34
|
+
:password => "crypto",
|
35
|
+
:extras => "printer",
|
36
|
+
:browser => "ff",
|
37
|
+
:hobbies => "Surfing the Web",
|
38
|
+
:color => "Yellow",
|
39
|
+
:event_reports_area => "blah " * 400,
|
40
|
+
:hackzall => "on"}
|
41
|
+
|
42
|
+
def honey_do_input
|
43
|
+
browser.set_form_values(INPUT_DATA)
|
44
|
+
end
|
45
|
+
|
46
|
+
def one_field_at_a_time_input
|
47
|
+
browser.set_form_values(INPUT_DATA, :one_field_at_a_time => true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def selenium_input
|
51
|
+
browser.type("dom=document.everything.username", INPUT_DATA[:username])
|
52
|
+
browser.type("dom=document.everything.password", INPUT_DATA[:password])
|
53
|
+
browser.check("name=extras #{INPUT_DATA[:extras]}")
|
54
|
+
browser.check("name=browser #{INPUT_DATA[:browser]}")
|
55
|
+
browser.select("dom=document.everything.hobbies", INPUT_DATA[:hobbies])
|
56
|
+
browser.select("dom=document.everything.color", INPUT_DATA[:color])
|
57
|
+
browser.type("dom=document.everything.event_reports_area", INPUT_DATA[:event_reports_area])
|
58
|
+
browser.check("dom=document.everything.hackzall")
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup
|
62
|
+
super
|
63
|
+
browser.open("everything.html")
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
|
3
|
+
class TestFileUpload < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# due to "same origin" policy, probably
|
6
|
+
def test_file_upload_by_selenium_not_permitted_by_firefox
|
7
|
+
return if ie?
|
8
|
+
navigate
|
9
|
+
assert_raise(SeleniumCommandError) do
|
10
|
+
browser.type("dom=document.everything.file", "foo.txt")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_file_upload_not_implemented
|
15
|
+
navigate
|
16
|
+
assert_nothing_raised(RuntimeError) do
|
17
|
+
# no error because nothing happens
|
18
|
+
browser.set_form_values(:file => "foo.txt")
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_nil(browser.get_form_values[:file])
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def ie?
|
27
|
+
browser.inspect.include?("explore")
|
28
|
+
end
|
29
|
+
|
30
|
+
def navigate
|
31
|
+
browser.open("everything.html")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
|
3
|
+
#====There are 50+ tests
|
4
|
+
#in the classes starting "<tt>Test</tt>" (files ending <i>_test.rb</i>)
|
5
|
+
class TestGeneralInputOptions < Test::Unit::TestCase
|
6
|
+
|
7
|
+
ONE_OF_EACH = {:username => "yes_dear",
|
8
|
+
:password => "crypto",
|
9
|
+
:extras => "printer",
|
10
|
+
:browser => "ff",
|
11
|
+
:hobbies => "Surfing the Web",
|
12
|
+
:color => "Yellow",
|
13
|
+
:event_reports_area => "You call this a textarea?",
|
14
|
+
:hackzall => "on"}
|
15
|
+
|
16
|
+
# The "*_normal_*" way?
|
17
|
+
#
|
18
|
+
# use this when input order doesn't matter but readability does.
|
19
|
+
#
|
20
|
+
# see also #TestSubmitForm
|
21
|
+
def test_input_list_can_be_hash
|
22
|
+
browser.set_form_values(ONE_OF_EACH)
|
23
|
+
|
24
|
+
values_that_were_set = browser.get_form_values
|
25
|
+
|
26
|
+
assert_equal(ONE_OF_EACH, values_that_were_set, "input values are same as those read")
|
27
|
+
|
28
|
+
assert_nothing_raised(RuntimeError, "hash items as method arguments are fine, too") do
|
29
|
+
browser.set_form_values(:color => 8, # see also select_list_test.rb
|
30
|
+
:hobbies => "hacking", # see also select_list_test.rb
|
31
|
+
:username => "ernie",
|
32
|
+
:password => "bert",
|
33
|
+
:event_reports_area => "blah " * 4, # see also textarea_test.rb
|
34
|
+
:extras => 1, # see also checkbox_test.rb
|
35
|
+
:hackzall => true, # see also checkbox_test.rb
|
36
|
+
:browser => "safari") # see also radio_button_test.rb
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_input_list_can_have_single_item
|
41
|
+
assert_nothing_raised(RuntimeError, "item can be a symbol, array, or string") do
|
42
|
+
browser.set_form_values(:clearButton)
|
43
|
+
browser.set_form_values([:hackzall])
|
44
|
+
browser.set_form_values("resetButton")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# see also #TestSubmitForm
|
49
|
+
def test_input_list_can_be_array
|
50
|
+
assert_nothing_raised(RuntimeError, "array list of names without values") do
|
51
|
+
browser.set_form_values([:clearButton, :hackzall, "resetButton", "a-clock.exe"])
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_equal("on", browser.get_form_values[:"a-clock.exe"])
|
55
|
+
|
56
|
+
reset
|
57
|
+
|
58
|
+
input_array = [[:username, @method_name], [:password, "snooks"], :hackzall, [:color, "Green"]]
|
59
|
+
assert_nothing_raised(RuntimeError, "array list of names with values, or just names") do
|
60
|
+
browser.set_form_values(input_array)
|
61
|
+
end
|
62
|
+
|
63
|
+
hashmap_from_screen = browser.get_form_values
|
64
|
+
assert_equal(input_array.size, hashmap_from_screen.size)
|
65
|
+
assert_equal(@method_name, hashmap_from_screen[:username])
|
66
|
+
assert_equal("snooks", hashmap_from_screen[:password])
|
67
|
+
assert_equal("on", hashmap_from_screen[:hackzall])
|
68
|
+
assert_equal("Green", hashmap_from_screen[:color])
|
69
|
+
end
|
70
|
+
|
71
|
+
# see also #TestTextareaInput
|
72
|
+
#
|
73
|
+
# If we allow this, we can't allow punctuation in text or textarea input without a lot of extra code.
|
74
|
+
# A nice implementation could be done, but only at the cost of further complexity.
|
75
|
+
#
|
76
|
+
# There are already plenty of options with hashes and arrays
|
77
|
+
def test_input_list_as_delimited_string_is_not_supported
|
78
|
+
assert_raise(RuntimeError, "comma delimited string treated as one big string") do
|
79
|
+
browser.set_form_values("clearButton,hackzall,resetButton,a-clock.exe", :retry_max => 0)
|
80
|
+
end
|
81
|
+
|
82
|
+
pair_delimiter = HoneyDo::PAIR_DELIMITER
|
83
|
+
assert_nothing_raised(RuntimeError, SeleniumCommandError, "this works but is so ugly that you wouldn't bother") do
|
84
|
+
browser.set_form_values("clearButton#{pair_delimiter}hackzall#{pair_delimiter}resetButton#{pair_delimiter}a-clock.exe")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# this a 'test' test, not a demo test: there were issues with the listbox
|
89
|
+
def test_ok_to_read_form_values_with_nothing_set
|
90
|
+
assert_nothing_raised(RuntimeError) do
|
91
|
+
browser.get_form_values
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_read_element_info_from_multiple_forms
|
96
|
+
test_name_header = "*** *** #{@method_name.upcase} *** ***"
|
97
|
+
@@print_buffer << "\n#{test_name_header}"
|
98
|
+
|
99
|
+
read_element_info(0)
|
100
|
+
|
101
|
+
@@print_buffer << "\n"
|
102
|
+
|
103
|
+
read_element_info(1)
|
104
|
+
|
105
|
+
@@print_buffer << "#{test_name_header}\n\n"
|
106
|
+
end
|
107
|
+
|
108
|
+
# by default we raise an error when the element name isn't found, but you can override that with '<tt>:ok_if_not_found => true</tt>'
|
109
|
+
def test_element_not_found
|
110
|
+
bad_input = ONE_OF_EACH.merge(:foo => "bar")
|
111
|
+
assert_raise(RuntimeError, "element name 'foo' not found, so we get an error") do
|
112
|
+
browser.set_form_values(bad_input, :retry_max => 0)
|
113
|
+
end
|
114
|
+
|
115
|
+
reset
|
116
|
+
|
117
|
+
assert_nothing_raised(RuntimeError, "bad element 'foo' ignored") do
|
118
|
+
browser.set_form_values(bad_input, :ok_if_not_found => true)
|
119
|
+
end
|
120
|
+
|
121
|
+
assert_equal(ONE_OF_EACH, browser.get_form_values, "input values besides the bad one were actually set")
|
122
|
+
end
|
123
|
+
|
124
|
+
# sometimes the form element name is not unique.
|
125
|
+
# js 'elements' collection is a js associative array, and so can use names or indices for keys
|
126
|
+
def test_identify_element_by_index_or_name
|
127
|
+
field_name_1 = "color"
|
128
|
+
field_name_2 = "hobbies"
|
129
|
+
field_index_1 = field_index_2 = ""
|
130
|
+
|
131
|
+
browser.get_form_element_indexes.each do |item|
|
132
|
+
field_index_1 = item[1].to_i if item[0] == field_name_1
|
133
|
+
field_index_2 = item[1] if item[0] == field_name_2
|
134
|
+
end
|
135
|
+
|
136
|
+
assert_kind_of(Integer, field_index_1)
|
137
|
+
assert_nothing_raised(RuntimeError, SeleniumCommandError, "index as Ruby int") do
|
138
|
+
browser.set_form_values( field_index_1 => :last)
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_kind_of(String, field_index_2)
|
142
|
+
assert_nothing_raised(RuntimeError, SeleniumCommandError, "index as Ruby string") do
|
143
|
+
browser.set_form_values( field_index_2 => :last)
|
144
|
+
end
|
145
|
+
|
146
|
+
values_as_set_with_indexes = browser.get_form_values
|
147
|
+
|
148
|
+
reset
|
149
|
+
|
150
|
+
browser.set_form_values( field_name_1 => :last, field_name_2 => :last)
|
151
|
+
values_as_set_with_names = browser.get_form_values
|
152
|
+
assert_equal(values_as_set_with_indexes, values_as_set_with_names)
|
153
|
+
end
|
154
|
+
|
155
|
+
# A contrived example to show a technique which is handy when you need a generic solution to always click the first (or whatever-eth) thing without knowing its name.
|
156
|
+
# An example would be when 2 or more different warning screens are possible in a given context, each with a differently named 'dismiss' button
|
157
|
+
#
|
158
|
+
# *Note* that value-less names are only clicked if they are of a "<i>clickable</i>" type (button, radio, checkbox)
|
159
|
+
def test_input_list_can_be_lone_integer
|
160
|
+
# click 'Enable Handlers' (events_button_form.enableEventsButton) by index
|
161
|
+
input_list = 0
|
162
|
+
processing_params = {:form_name_or_index => :events_button_form}
|
163
|
+
assert_nothing_raised(RuntimeError, SeleniumCommandError, "element '0' is clicked without incident") do
|
164
|
+
browser.set_form_values(input_list, processing_params)
|
165
|
+
end
|
166
|
+
|
167
|
+
# processing_params[:form_name_or_index] arg included for demo purposes: it would default to 0 anyway
|
168
|
+
browser.set_form_values({:color => "Blue"}, :form_name_or_index => :everything )
|
169
|
+
verify_event_trace(":color (blue )", :color)
|
170
|
+
|
171
|
+
# click 'Disable Handlers' (events_button_form.disableEventsButton) by index
|
172
|
+
browser.set_form_values(1, :form_name_or_index => 1)
|
173
|
+
|
174
|
+
# clear out everything, including the textarea "event_reports_area"
|
175
|
+
reset
|
176
|
+
|
177
|
+
browser.set_form_values({:hobbies => 1})
|
178
|
+
assert_nil(browser.get_form_values[:event_reports_area], "no longer firing events")
|
179
|
+
end
|
180
|
+
|
181
|
+
protected
|
182
|
+
|
183
|
+
def setup
|
184
|
+
super
|
185
|
+
browser.open("everything.html")
|
186
|
+
end
|
187
|
+
|
188
|
+
# demonstrates some of the form reading capability and addressing a form by its index within the <tt>forms</tt> collection
|
189
|
+
def read_element_info(form_index)
|
190
|
+
@@print_buffer << "Reading Form:\n'#{browser.get_all_form_names.split(',')[form_index]}'"
|
191
|
+
|
192
|
+
@@print_buffer << "\nAll Element Names:"
|
193
|
+
@@print_buffer << browser.get_form_elements(form_index).split(',')
|
194
|
+
|
195
|
+
@@print_buffer << "\nAll Element Indices:"
|
196
|
+
@@print_buffer << browser.get_form_element_indexes(form_index).inspect
|
197
|
+
|
198
|
+
@@print_buffer << "\nAll Checkbox Names:"
|
199
|
+
@@print_buffer << browser.get_all_checkbox_names(form_index).inspect
|
200
|
+
|
201
|
+
@@print_buffer << "\nAll Button Names:"
|
202
|
+
@@print_buffer << browser.get_all_button_names(form_index)
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
|
3
|
+
class TestHiddenAndDisabled < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# setting hidden values hasn't proved necessary
|
6
|
+
def test_set_hidden_not_implemented
|
7
|
+
new_hidden_value = "whatever!"
|
8
|
+
assert_nothing_raised(RuntimeError, SeleniumCommandError) do
|
9
|
+
browser.set_form_values({:justHiding => new_hidden_value}.to_a.push(:submitButton))
|
10
|
+
end
|
11
|
+
|
12
|
+
page_load_wait
|
13
|
+
|
14
|
+
value_displayed_on_next_page = browser.get_cell_ids_and_text[:justHiding]
|
15
|
+
|
16
|
+
assert(value_displayed_on_next_page, "hidden value got submitted")
|
17
|
+
assert_not_equal(new_hidden_value, value_displayed_on_next_page, "default hidden value was submitted, not the one we tried to set")
|
18
|
+
end
|
19
|
+
|
20
|
+
HIDDEN_FIELD = "justHiding"
|
21
|
+
|
22
|
+
# reading hidden values hasn't proved necessary
|
23
|
+
def test_read_hidden_not_implemented
|
24
|
+
assert_equal(false, browser.get_form_elements.split(',').include?(HIDDEN_FIELD), "hidden elements ignored by get_form_elements()")
|
25
|
+
assert_equal(false, browser.get_enabled_form_elements.split(',').include?(HIDDEN_FIELD), "hidden elements ignored by get_enabled_form_elements()")
|
26
|
+
assert_nil(browser.get_form_values[:justHiding], "hidden elements ignored by browser.get_form_values()")
|
27
|
+
end
|
28
|
+
|
29
|
+
# we need to include all fields to have an accurate mapping of names to indexes
|
30
|
+
def test_hidden_fields_included_with_indexes
|
31
|
+
hidden_field = browser.get_form_element_indexes.select {|item| item[0] == HIDDEN_FIELD}.flatten
|
32
|
+
assert(hidden_field[1].to_i > -1, "hidden field index is present")
|
33
|
+
end
|
34
|
+
|
35
|
+
# this is good for verifying form state
|
36
|
+
def test_can_exclude_disabled_fields
|
37
|
+
field_name = "hobbies"
|
38
|
+
assert(browser.get_enabled_form_elements.split(',').include?(field_name), "enabled elements returned by get_enabled_form_elements()")
|
39
|
+
|
40
|
+
browser.get_eval("dom=new Form_(this).form.#{field_name}.disabled = true;")
|
41
|
+
|
42
|
+
assert_equal(false, browser.get_enabled_form_elements.split(',').include?(field_name), "disabled elements ignored by get_enabled_form_elements()")
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def setup
|
48
|
+
super
|
49
|
+
browser.open("everything.html")
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_master'
|
2
|
+
|
3
|
+
class TestRadioButtonFeatures < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_set_radio_button_by_value_property
|
6
|
+
browser.set_form_values(:browser => "ff")
|
7
|
+
assert_equal("ff", browser.get_form_values[:browser])
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_value_is_read_not_label_text
|
11
|
+
browser.set_form_values(:browser => "ie")
|
12
|
+
assert_not_equal("Internet Explorer", browser.get_form_values[:browser])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_set_radio_button_by_index
|
16
|
+
browser.set_form_values(:browser => 0)
|
17
|
+
assert_equal("ff", browser.get_form_values[:browser])
|
18
|
+
|
19
|
+
browser.set_form_values(:browser => 3)
|
20
|
+
assert_equal("opera", browser.get_form_values[:browser])
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_spaces_ok_in_radio_button_value
|
24
|
+
radio_button_value = "other browser"
|
25
|
+
assert_nothing_raised(RuntimeError, SeleniumCommandError) do
|
26
|
+
browser.set_form_values(:browser => radio_button_value)
|
27
|
+
end
|
28
|
+
assert_equal(radio_button_value, browser.get_form_values[:browser])
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_only_one_radio_button_remains_selected
|
32
|
+
browser.set_form_values([[:browser, 0], [:browser, "ff"],[:browser,"safari"],[:browser,"ie"]])
|
33
|
+
assert_equal("ie", browser.get_form_values[:browser])
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def setup
|
39
|
+
super
|
40
|
+
browser.open("everything.html")
|
41
|
+
end
|
42
|
+
end
|