honey-do 0.5.0

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.
@@ -0,0 +1,155 @@
1
+ require 'test_master'
2
+
3
+ class TestSelectFeatures < Test::Unit::TestCase
4
+
5
+ def test_select_from_droplist_by_visible_text
6
+ text_value = "Light Grey"
7
+
8
+ browser.set_form_values(:color => text_value)
9
+ assert_equal(text_value, browser.get_form_values[:color], "exact match")
10
+
11
+ reset_then_set(:color => "lIGhT gReY")
12
+ assert_equal(text_value, browser.get_form_values[:color], "case insensitive")
13
+ end
14
+
15
+ def test_select_from_droplist_by_value
16
+ option_value_property = "flat eggshell white"
17
+ option_text_property = "Off White"
18
+
19
+ browser.set_form_values(:color => option_value_property)
20
+ value_set_by_value_property = browser.get_form_values[:color]
21
+
22
+ reset_then_set(:color => option_text_property)
23
+ value_set_by_visible_text_label = browser.get_form_values[:color]
24
+
25
+ test_intent = "same item set by text or value"
26
+ assert_equal(value_set_by_value_property, value_set_by_visible_text_label, test_intent)
27
+ assert_equal(value_set_by_value_property, option_text_property, test_intent)
28
+
29
+ reset_then_set(:color => option_value_property.upcase)
30
+ assert_equal(option_text_property, browser.get_form_values[:color], "case insensitive")
31
+ end
32
+
33
+ # substring match - anchored to ^ (beginning of string); *, ? and + are just text (not wildcards)
34
+ def test_select_from_droplist_by_substring_match_on_visible_text
35
+ default_selection = browser.get_form_values[:color]
36
+
37
+ test_intent = "substring: anchored to beginning of string '^'"
38
+ browser.set_form_values(:color => "ligh")
39
+ assert_equal("Light Grey", browser.get_form_values[:color], test_intent)
40
+
41
+ assert_raise(RuntimeError, test_intent) do
42
+ reset_then_set_without_retry(:color => "ight Grey")
43
+ end
44
+ assert_equal(default_selection, browser.get_form_values[:color], test_intent)
45
+
46
+ test_intent = "substring: no wildcards"
47
+ assert_raise(RuntimeError, test_intent) do
48
+ reset_then_set_without_retry(:color => "Light*")
49
+ end
50
+ assert_equal(default_selection, browser.get_form_values[:color], test_intent)
51
+ end
52
+
53
+ def test_select_from_droplist_by_substring_match_on_value
54
+ default_selection = browser.get_form_values[:color]
55
+
56
+ option_value_property = "flat eggshell white"
57
+ option_text_property = "Off White"
58
+
59
+ test_intent = "substring: anchored to beginning of string '^'"
60
+ browser.set_form_values(:color => "Flat Egg")
61
+ assert_equal(option_text_property, browser.get_form_values[:color], test_intent)
62
+
63
+ assert_raise(RuntimeError, test_intent) do
64
+ reset_then_set_without_retry(:color => "hell white")
65
+ end
66
+ assert_equal(default_selection, browser.get_form_values[:color], test_intent)
67
+
68
+ test_intent = "substring: no wildcards"
69
+ assert_raise(RuntimeError, test_intent) do
70
+ reset_then_set_without_retry(:color => "flat egg*")
71
+ end
72
+ assert_equal(default_selection, browser.get_form_values[:color], test_intent)
73
+ end
74
+
75
+ def test_select_from_droplist_by_index
76
+ test_intent = "selection made by index"
77
+ default_selection = browser.get_form_values[:color]
78
+
79
+ browser.set_form_values(:color => 2)
80
+ assert_equal("Orange", browser.get_form_values[:color], test_intent )
81
+
82
+ browser.set_form_values(:color => 7)
83
+ assert_equal("Violet", browser.get_form_values[:color], test_intent)
84
+
85
+ browser.set_form_values(:color => 0)
86
+ assert_equal(default_selection, browser.get_form_values[:color], test_intent)
87
+ end
88
+
89
+ def test_select_from_multi_select_by_index
90
+ assert_nil(browser.get_form_values[:hobbies], "this multi-select has no default")
91
+
92
+ test_intent = "selection made by index"
93
+
94
+ browser.set_form_values(:hobbies => 1)
95
+ assert_equal("Surfing the Web", browser.get_form_values[:hobbies], test_intent )
96
+
97
+ reset_then_set(:hobbies => 3)
98
+ assert_equal("Annoying my friends", browser.get_form_values[:hobbies], test_intent)
99
+
100
+ reset_then_set(:hobbies => 0)
101
+ assert_equal("Hacking JavaScript", browser.get_form_values[:hobbies], test_intent)
102
+ end
103
+
104
+ def test_select_multiple_from_multi_select
105
+ browser.set_form_values([[:hobbies, :last], [:hobbies, "Surfing"], [:hobbies, 0]])
106
+
107
+ values_read_from_screen = browser.get_form_values
108
+
109
+ assert_equal("Hacking JavaScript|Surfing the Web|Zipping around on my scooter", values_read_from_screen[:hobbies])
110
+
111
+ compound_values = values_read_from_screen.split_compound_values
112
+
113
+ assert_equal("Hacking JavaScript", compound_values[:hobbies])
114
+ assert_equal("Surfing the Web", compound_values[:hobbies_1])
115
+ assert_equal("Zipping around on my scooter", compound_values[:hobbies_2])
116
+ end
117
+
118
+ # <tt>last</tt> is a keyword for listboxes and droplists (<tt>select-multiple</tt> and <tt>select-one</tt>)
119
+ def test_select_last
120
+ browser.set_form_values(:color => "last", :hobbies => :last)
121
+ values_as_set = browser.get_form_values
122
+
123
+ assert_equal("Zinc", values_as_set[:color], "last item happens to be 'Zinc'")
124
+ assert_match("Zipping", values_as_set[:hobbies], "last item happens to be 'Zipping around on my scooter'")
125
+ end
126
+
127
+ # <tt>random</tt> is a keyword for listboxes and droplists (<tt>select-multiple</tt> and <tt>select-one</tt>)
128
+ def test_select_random_from_droplist_stays_in_range
129
+ assert_nothing_raised(RuntimeError, SeleniumCommandError) do
130
+ 80.times {browser.set_form_values(:color => :random)}
131
+ end
132
+ end
133
+
134
+ def test_select_random_from_multi_select_stays_in_range
135
+ assert_nothing_raised(RuntimeError, SeleniumCommandError) do
136
+ 30.times {reset_then_set(:hobbies => "random")}
137
+ end
138
+ end
139
+
140
+ protected
141
+
142
+ def setup
143
+ super
144
+ browser.open("everything.html")
145
+ end
146
+
147
+ # prepend :resetButton
148
+ def reset_then_set(input_hash)
149
+ browser.set_form_values(input_hash.to_a.unshift(:resetButton) )
150
+ end
151
+
152
+ def reset_then_set_without_retry(input_hash)
153
+ browser.set_form_values(input_hash.to_a.unshift(:resetButton), :retry_max => 0 )
154
+ end
155
+ end
@@ -0,0 +1,82 @@
1
+ require 'test_master'
2
+
3
+ class TestSubmitForm < Test::Unit::TestCase
4
+
5
+ def test_submit_with_array_to_guarantee_order
6
+ form_input = [
7
+ [:hobbies, "Drinking Coffee"],
8
+ [:color, 3],
9
+ [:extras, "card"],
10
+ [:username, @method_name],
11
+ [:browser, "ie"],
12
+ [:event_reports_area, "Put the submit button at the end, or it may get clicked before all our other values are set."],
13
+ :submitButton # name with no value can stand alone: no need to nest it in another array
14
+ ]
15
+
16
+ browser.set_form_values(form_input)
17
+ verify_page_loaded
18
+
19
+ # we'll verify an interesting subset of what got submitted
20
+ expected_values = {:hobbies => "caffeine", :username => @method_name, :event_reports_area => form_input[5][1], :browser => "ie"}
21
+ verify_subset_of_values_persist_on_display_page(expected_values)
22
+ end
23
+
24
+ # input as hash: we have no control of order, so we submit after having set all the values
25
+ def test_submit_with_button_name_in_separate_call
26
+ one_of_each = {:username => @method_name,
27
+ :password => "crypto",
28
+ :extras => "printer",
29
+ :browser => 1,
30
+ :hobbies => "Drinking Coffee",
31
+ :color => "gold",
32
+ :event_reports_area => "blah blah yakkity yak " * 38,
33
+ :hackzall => true}
34
+
35
+ browser.set_form_values(one_of_each)
36
+
37
+ submitted_values = browser.get_form_values
38
+
39
+ assert_not_equal(one_of_each, submitted_values, "we didn't supply literal text for all of the fields")
40
+
41
+ browser.set_form_values(:submitButton)
42
+
43
+ verify_page_loaded
44
+
45
+ # prepare expected values to exactly match POST request data (web servlet reports everything in the body of the POST request)
46
+ submitted_values[:submitButton] = "Submit" # Normally we wouldn't care about the buttons but only 'data' fields.
47
+
48
+ submitted_values[:hobbies] = "caffeine" # Reader 'browser.get_form_values()' deals in visible 'text' property,
49
+ submitted_values[:color].downcase! # not the value property of the element
50
+
51
+ # Reader 'browser.get_form_values()' ignores hidden elements, but they do get posted
52
+ submitted_values[:justHiding] = "you can't see this unless you're looking at the source"
53
+
54
+ verify_all_values_persist_on_display_page(submitted_values)
55
+ end
56
+
57
+ protected
58
+
59
+ def setup
60
+ super
61
+ browser.open("everything.html")
62
+ end
63
+
64
+ def verify_page_loaded
65
+ page_load_wait
66
+ assert(browser.is_element_present("id=form_values_table"), "display table is present on loaded page")
67
+ assert_match(/\/display/, browser.get_location, "url")
68
+ end
69
+
70
+ # the web servlet makes a page using the POSTED form names as cell (td) id's, so we have no extra mapping work to do
71
+ def verify_all_values_persist_on_display_page(expected)
72
+ assert_equal(expected, browser.get_cell_ids_and_text("form_values_table"), "what we submitted appears on display page")
73
+ end
74
+
75
+ def verify_subset_of_values_persist_on_display_page(expected)
76
+ actual_display_values = browser.get_cell_ids_and_text #("form_values_table") # only 1 table on the page, so we can accept the default of index == 0
77
+ expected.each do |key, value|
78
+ assert_equal(value, actual_display_values[key], "value of #{key}")
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,18 @@
1
+ unless $0.include?("/rake/") # to run tests without rake
2
+ $LOAD_PATH.unshift( File.expand_path('../lib'), File.expand_path('../functional_testcase') )
3
+ end
4
+
5
+ require 'honey_do'
6
+ require 'functional_testcase'
7
+
8
+ def page_load_wait
9
+ browser.wait_for_page_to_load(2000)
10
+ end
11
+
12
+ def reset
13
+ browser.set_form_values(:resetButton)
14
+ end
15
+
16
+ def verify_event_trace(expected, field_name)
17
+ assert_match(expected, browser.get_form_values[:event_reports_area], "'#{field_name}' events in the trace")
18
+ end
@@ -0,0 +1,92 @@
1
+ require 'test_master'
2
+
3
+ class TestTextareaInput < Test::Unit::TestCase
4
+
5
+ # escape them!
6
+ # \\n
7
+ # \\'
8
+ def test_newlines_and_apostrophes_in_input
9
+ #RuntimeError: ERROR: Threw an exception: unterminated string literal
10
+ assert_raise(RuntimeError) do
11
+ browser.set_form_values({:event_reports_area => "What should we do?\nI think we should get a puppy."},{ :retry_max => 0})
12
+ end
13
+
14
+ #RuntimeError: ERROR: Threw an exception: missing ) after argument list
15
+ assert_raise(RuntimeError) do
16
+ browser.set_form_values({:event_reports_area => "I'm sure they'd love a puppy!"}, { :retry_max => 0})
17
+ end
18
+
19
+ text_area_input = "What should we do?\\nI think we should get a puppy.\\nI\\'m sure they\\'d love a puppy!"
20
+ assert_nothing_raised(RuntimeError, SeleniumCommandError) do
21
+ browser.set_form_values(:event_reports_area => text_area_input)
22
+ end
23
+
24
+ assert_equal(text_area_input.gsub("\\n","\n").gsub("\\'", "'"), get_textarea_value)
25
+ end
26
+
27
+ def test_commas_in_input
28
+ stanza_1_of_pearl = %Q{Perle, plesaunte to prynces paye
29
+ To clanly clos in golde so clere,
30
+ Oute of oryent, I hardyly saye,
31
+ Ne proued I neuer her precious pere.
32
+ So rounde, so reken in vche araye,
33
+ So smal, so smothe her sydes were,
34
+ Quere-so-euer I jugged gemmez gaye,
35
+ I sette hyr sengeley in synglere.
36
+ Allas! I leste hyr in on erbere;
37
+ Thurgh gresse to grounde hit fro me yot.
38
+ I dewyne, fordolked of luf-daungere
39
+ Of that pryuy perle wythouten spot.}
40
+
41
+ browser.set_form_values(:event_reports_area => stanza_1_of_pearl.gsub("\n","\\n"))
42
+ textarea_value = get_textarea_value
43
+
44
+ test_intent = "entire string put in, including commas and all clauses"
45
+ assert_equal(stanza_1_of_pearl, textarea_value, test_intent)
46
+ assert_equal(stanza_1_of_pearl.split(','), textarea_value.split(','), test_intent)
47
+ assert_equal(stanza_1_of_pearl.size, textarea_value.size, test_intent)
48
+ end
49
+
50
+ TRIPLE_COLON_STRING = "Who in their right mind would ever include::: in any kind of text input?:::That would be crazy!"
51
+ # ":::" is used to delimit fields (names or name/value pairs) in input to js <tt>Form_.prototype.set_values()</tt>
52
+ def test_triple_colon_is_input_delimiter_with_mulitiple_fields
53
+ triple_colon_is_input_delimiter(:event_reports_area => TRIPLE_COLON_STRING, :username => "Mr. Red Herring", :extras => "printer", :browser => "ff")
54
+ end
55
+
56
+ def test_triple_colon_is_input_delimiter_with_single_field
57
+ triple_colon_is_input_delimiter(:event_reports_area => TRIPLE_COLON_STRING)
58
+ end
59
+
60
+ protected
61
+
62
+ def setup
63
+ super
64
+ browser.open("everything.html")
65
+ end
66
+
67
+ # strip IE carriage return
68
+ def get_textarea_value
69
+ browser.get_form_values[:event_reports_area].gsub(/\r/,"")
70
+ end
71
+
72
+ def triple_colon_is_input_delimiter(input_values)
73
+ browser.set_form_values(input_values)
74
+
75
+ text_area_input = input_values[:event_reports_area]
76
+ value_as_set = browser.get_form_values[:event_reports_area]
77
+
78
+ test_intent = "input string was truncated at first ':::' delimiter"
79
+ assert(value_as_set.size < text_area_input.size, test_intent)
80
+ assert_equal(value_as_set, text_area_input.split(':::')[0], test_intent)
81
+ assert_not_equal(value_as_set, text_area_input, test_intent)
82
+
83
+ # remove the delimiter
84
+ input_values[:event_reports_area] = text_area_input.gsub(/:::/, " a triple colon ")
85
+
86
+ browser.set_form_values(input_values)
87
+ value_as_set = browser.get_form_values[:event_reports_area]
88
+
89
+ assert_equal(value_as_set, input_values[:event_reports_area], "entire string put in, now that we have removed ':::'")
90
+ end
91
+
92
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honey-do
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Camper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-26 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: Selenium
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.1
24
+ version:
25
+ description: collection driven, commandless form handling for Selenium
26
+ email: twcamper@thoughtworks.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - COPYING
34
+ - js/user-extensions.js
35
+ - doc/INSTALLATION
36
+ - doc/running_the_tests.rdoc
37
+ - test/checkbox_test.rb
38
+ - test/events_test.rb
39
+ - test/fast_and_pretty_test.rb
40
+ - test/file_upload_test.rb
41
+ - test/general_form_test.rb
42
+ - test/hidden_and_disabled_field_test.rb
43
+ - test/radio_button_test.rb
44
+ - test/select_list_test.rb
45
+ - test/submit_test.rb
46
+ - test/test_master.rb
47
+ - test/textarea_test.rb
48
+ - functional_testcase/functional_testcase.rb
49
+ - demo/webrick-servlet.rb
50
+ files:
51
+ - COPYING
52
+ - README
53
+ - Rakefile
54
+ - lib/hash.rb
55
+ - lib/honey_do.rb
56
+ - lib/symbol.rb
57
+ - test/checkbox_test.rb
58
+ - test/events_test.rb
59
+ - test/fast_and_pretty_test.rb
60
+ - test/file_upload_test.rb
61
+ - test/general_form_test.rb
62
+ - test/hidden_and_disabled_field_test.rb
63
+ - test/radio_button_test.rb
64
+ - test/select_list_test.rb
65
+ - test/submit_test.rb
66
+ - test/test_master.rb
67
+ - test/textarea_test.rb
68
+ - demo/display
69
+ - demo/display/webrick_servlet_needs_this_folder.txt
70
+ - demo/page
71
+ - demo/page/everything.html
72
+ - demo/page/everything.js
73
+ - demo/webrick-servlet.rb
74
+ - functional_testcase/functional_testcase.rb
75
+ - bin/start_selenium_proxy.bat
76
+ - bin/start_selenium_proxy.sh
77
+ - js/user-extensions.js
78
+ - doc/INSTALLATION
79
+ - doc/running_the_tests.rdoc
80
+ has_rdoc: true
81
+ homepage: http://honey-do.rubyforge.org/
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --all
85
+ - --quiet
86
+ - --line-numbers
87
+ - --inline-source
88
+ - --main
89
+ - README
90
+ - --title
91
+ - "Honey-Do: Just give it a list!"
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.8.2
99
+ version:
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ requirements: []
107
+
108
+ rubyforge_project: honey-do
109
+ rubygems_version: 1.3.1
110
+ signing_key:
111
+ specification_version: 2
112
+ summary: collection driven, commandless form handling for Selenium
113
+ test_files: []
114
+