operawatir 0.3-jruby

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.
Files changed (171) hide show
  1. data/.gitmodules +3 -0
  2. data/.yardopts +5 -0
  3. data/AUTHORS +7 -0
  4. data/Gemfile +9 -0
  5. data/LICENSE +30 -0
  6. data/README.md +158 -0
  7. data/Rakefile +59 -0
  8. data/VERSION +1 -0
  9. data/bin/desktopwatir +106 -0
  10. data/bin/operawatir +95 -0
  11. data/lib/operadriver/APACHE_2.0_LICENSE.txt +204 -0
  12. data/lib/operadriver/NEW_BSD_LICENSE.txt +36 -0
  13. data/lib/operadriver/commons-jxpath-1.3.jar +0 -0
  14. data/lib/operadriver/protobuf-java-2.3.0.jar +0 -0
  15. data/lib/operadriver/selenium-common.jar +0 -0
  16. data/lib/operadriver/webdriver-opera.jar +0 -0
  17. data/lib/operawatir.rb +46 -0
  18. data/lib/operawatir/browser.rb +181 -0
  19. data/lib/operawatir/collection.rb +133 -0
  20. data/lib/operawatir/compat.rb +25 -0
  21. data/lib/operawatir/compat/browser.rb +20 -0
  22. data/lib/operawatir/compat/collection.rb +99 -0
  23. data/lib/operawatir/compat/deprecation.rb +46 -0
  24. data/lib/operawatir/compat/element.rb +165 -0
  25. data/lib/operawatir/compat/element_finders.rb +159 -0
  26. data/lib/operawatir/compat/window.rb +27 -0
  27. data/lib/operawatir/element.rb +228 -0
  28. data/lib/operawatir/exceptions.rb +38 -0
  29. data/lib/operawatir/helper.rb +53 -0
  30. data/lib/operawatir/selector.rb +111 -0
  31. data/lib/operawatir/version.rb +15 -0
  32. data/lib/operawatir/window.rb +174 -0
  33. data/spec/fire_event/fire_event.rb +268 -0
  34. data/spec/fire_event/interactive/onBlur.html +45 -0
  35. data/spec/fire_event/interactive/onChange.html +47 -0
  36. data/spec/fire_event/interactive/onClick.html +45 -0
  37. data/spec/fire_event/interactive/onDblClick.html +45 -0
  38. data/spec/fire_event/interactive/onFocus.html +45 -0
  39. data/spec/fire_event/interactive/onMouseDown.html +45 -0
  40. data/spec/fire_event/interactive/onMouseMove.html +45 -0
  41. data/spec/fire_event/interactive/onMouseOut.html +45 -0
  42. data/spec/fire_event/interactive/onMouseOver.html +45 -0
  43. data/spec/fire_event/interactive/onMouseUp.html +45 -0
  44. data/spec/fire_event/interactive/onScroll.html +14 -0
  45. data/spec/legacy_watirspec/area_spec.rb +106 -0
  46. data/spec/legacy_watirspec/areas_spec.rb +38 -0
  47. data/spec/legacy_watirspec/browser_spec.rb +297 -0
  48. data/spec/legacy_watirspec/button_spec.rb +260 -0
  49. data/spec/legacy_watirspec/buttons_spec.rb +54 -0
  50. data/spec/legacy_watirspec/checkbox_spec.rb +280 -0
  51. data/spec/legacy_watirspec/checkboxes_spec.rb +38 -0
  52. data/spec/legacy_watirspec/collections_spec.rb +18 -0
  53. data/spec/legacy_watirspec/dd_spec.rb +140 -0
  54. data/spec/legacy_watirspec/dds_spec.rb +38 -0
  55. data/spec/legacy_watirspec/del_spec.rb +181 -0
  56. data/spec/legacy_watirspec/dels_spec.rb +62 -0
  57. data/spec/legacy_watirspec/div_spec.rb +244 -0
  58. data/spec/legacy_watirspec/divs_spec.rb +38 -0
  59. data/spec/legacy_watirspec/dl_spec.rb +140 -0
  60. data/spec/legacy_watirspec/dls_spec.rb +38 -0
  61. data/spec/legacy_watirspec/dt_spec.rb +140 -0
  62. data/spec/legacy_watirspec/dts_spec.rb +38 -0
  63. data/spec/legacy_watirspec/element_spec.rb +86 -0
  64. data/spec/legacy_watirspec/em_spec.rb +114 -0
  65. data/spec/legacy_watirspec/ems_spec.rb +38 -0
  66. data/spec/legacy_watirspec/filefield_spec.rb +127 -0
  67. data/spec/legacy_watirspec/filefields_spec.rb +38 -0
  68. data/spec/legacy_watirspec/fixtures/2000_spans.html +2009 -0
  69. data/spec/legacy_watirspec/fixtures/bug_duplicate_attributes.html +14 -0
  70. data/spec/legacy_watirspec/fixtures/bug_javascript_001.html +11 -0
  71. data/spec/legacy_watirspec/fixtures/buttons_with_duplicate_ids.html +18 -0
  72. data/spec/legacy_watirspec/fixtures/collections.html +15 -0
  73. data/spec/legacy_watirspec/fixtures/definition_lists.html +48 -0
  74. data/spec/legacy_watirspec/fixtures/euc-jp_text.html +17 -0
  75. data/spec/legacy_watirspec/fixtures/forms_with_input_elements.html +126 -0
  76. data/spec/legacy_watirspec/fixtures/frame_1.html +18 -0
  77. data/spec/legacy_watirspec/fixtures/frame_2.html +16 -0
  78. data/spec/legacy_watirspec/fixtures/frames.html +11 -0
  79. data/spec/legacy_watirspec/fixtures/iframes.html +12 -0
  80. data/spec/legacy_watirspec/fixtures/images.html +27 -0
  81. data/spec/legacy_watirspec/fixtures/images/1.gif +0 -0
  82. data/spec/legacy_watirspec/fixtures/images/2.gif +0 -0
  83. data/spec/legacy_watirspec/fixtures/images/3.gif +0 -0
  84. data/spec/legacy_watirspec/fixtures/images/button.jpg +0 -0
  85. data/spec/legacy_watirspec/fixtures/images/circle.jpg +0 -0
  86. data/spec/legacy_watirspec/fixtures/images/map.gif +0 -0
  87. data/spec/legacy_watirspec/fixtures/images/map2.gif +0 -0
  88. data/spec/legacy_watirspec/fixtures/images/minus.gif +0 -0
  89. data/spec/legacy_watirspec/fixtures/images/originaltriangle.jpg +0 -0
  90. data/spec/legacy_watirspec/fixtures/images/plus.gif +0 -0
  91. data/spec/legacy_watirspec/fixtures/images/square.jpg +0 -0
  92. data/spec/legacy_watirspec/fixtures/images/triangle.jpg +0 -0
  93. data/spec/legacy_watirspec/fixtures/iso-2022-jp_text.html +17 -0
  94. data/spec/legacy_watirspec/fixtures/javascript/helpers.js +16 -0
  95. data/spec/legacy_watirspec/fixtures/jquery.html +28 -0
  96. data/spec/legacy_watirspec/fixtures/latin1_text.html +17 -0
  97. data/spec/legacy_watirspec/fixtures/multiple_ids.html +14 -0
  98. data/spec/legacy_watirspec/fixtures/non_control_elements.html +135 -0
  99. data/spec/legacy_watirspec/fixtures/parser_bug_001.html +12 -0
  100. data/spec/legacy_watirspec/fixtures/prevent_form_submit.html +20 -0
  101. data/spec/legacy_watirspec/fixtures/right_click.html +11 -0
  102. data/spec/legacy_watirspec/fixtures/shift_jis_text.html +17 -0
  103. data/spec/legacy_watirspec/fixtures/tables.html +121 -0
  104. data/spec/legacy_watirspec/fixtures/timeout.html +16 -0
  105. data/spec/legacy_watirspec/fixtures/timeout_window_location.html +19 -0
  106. data/spec/legacy_watirspec/fixtures/tiny_mce.html +27 -0
  107. data/spec/legacy_watirspec/fixtures/utf8_text.html +15 -0
  108. data/spec/legacy_watirspec/fixtures/watirspec.css +0 -0
  109. data/spec/legacy_watirspec/form_spec.rb +73 -0
  110. data/spec/legacy_watirspec/forms_spec.rb +39 -0
  111. data/spec/legacy_watirspec/frame_spec.rb +161 -0
  112. data/spec/legacy_watirspec/frames_spec.rb +75 -0
  113. data/spec/legacy_watirspec/guards.rb +38 -0
  114. data/spec/legacy_watirspec/hidden_spec.rb +120 -0
  115. data/spec/legacy_watirspec/hiddens_spec.rb +38 -0
  116. data/spec/legacy_watirspec/hn_spec.rb +101 -0
  117. data/spec/legacy_watirspec/hns_spec.rb +39 -0
  118. data/spec/legacy_watirspec/image_spec.rb +237 -0
  119. data/spec/legacy_watirspec/images_spec.rb +38 -0
  120. data/spec/legacy_watirspec/ins_spec.rb +181 -0
  121. data/spec/legacy_watirspec/inses_spec.rb +62 -0
  122. data/spec/legacy_watirspec/label_spec.rb +85 -0
  123. data/spec/legacy_watirspec/labels_spec.rb +38 -0
  124. data/spec/legacy_watirspec/li_spec.rb +135 -0
  125. data/spec/legacy_watirspec/link_spec.rb +194 -0
  126. data/spec/legacy_watirspec/links_spec.rb +39 -0
  127. data/spec/legacy_watirspec/lis_spec.rb +38 -0
  128. data/spec/legacy_watirspec/map_spec.rb +100 -0
  129. data/spec/legacy_watirspec/maps_spec.rb +38 -0
  130. data/spec/legacy_watirspec/meta_spec.rb +26 -0
  131. data/spec/legacy_watirspec/metas_spec.rb +36 -0
  132. data/spec/legacy_watirspec/ol_spec.rb +86 -0
  133. data/spec/legacy_watirspec/ols_spec.rb +38 -0
  134. data/spec/legacy_watirspec/option_spec.rb +187 -0
  135. data/spec/legacy_watirspec/p_spec.rb +167 -0
  136. data/spec/legacy_watirspec/pre_spec.rb +133 -0
  137. data/spec/legacy_watirspec/pres_spec.rb +38 -0
  138. data/spec/legacy_watirspec/ps_spec.rb +38 -0
  139. data/spec/legacy_watirspec/radio_spec.rb +286 -0
  140. data/spec/legacy_watirspec/radios_spec.rb +35 -0
  141. data/spec/legacy_watirspec/select_list_spec.rb +326 -0
  142. data/spec/legacy_watirspec/select_lists_spec.rb +39 -0
  143. data/spec/legacy_watirspec/server.rb +91 -0
  144. data/spec/legacy_watirspec/span_spec.rb +181 -0
  145. data/spec/legacy_watirspec/spans_spec.rb +64 -0
  146. data/spec/legacy_watirspec/spec_helper.rb +12 -0
  147. data/spec/legacy_watirspec/strong_spec.rb +97 -0
  148. data/spec/legacy_watirspec/strongs_spec.rb +39 -0
  149. data/spec/legacy_watirspec/table_bodies_spec.rb +61 -0
  150. data/spec/legacy_watirspec/table_body_spec.rb +119 -0
  151. data/spec/legacy_watirspec/table_cell_spec.rb +76 -0
  152. data/spec/legacy_watirspec/table_cells_spec.rb +71 -0
  153. data/spec/legacy_watirspec/table_footer_spec.rb +94 -0
  154. data/spec/legacy_watirspec/table_footers_spec.rb +61 -0
  155. data/spec/legacy_watirspec/table_header_spec.rb +98 -0
  156. data/spec/legacy_watirspec/table_headers_spec.rb +59 -0
  157. data/spec/legacy_watirspec/table_row_spec.rb +104 -0
  158. data/spec/legacy_watirspec/table_rows_spec.rb +64 -0
  159. data/spec/legacy_watirspec/table_spec.rb +170 -0
  160. data/spec/legacy_watirspec/tables_spec.rb +40 -0
  161. data/spec/legacy_watirspec/text_field_spec.rb +315 -0
  162. data/spec/legacy_watirspec/text_fields_spec.rb +38 -0
  163. data/spec/legacy_watirspec/ul_spec.rb +84 -0
  164. data/spec/legacy_watirspec/uls_spec.rb +40 -0
  165. data/spec/legacy_watirspec/watir_compatibility_spec.rb +176 -0
  166. data/spec/legacy_watirspec/watirspec_helper.rb +57 -0
  167. data/utils/Rakefile +79 -0
  168. data/utils/launchers/launcher-linux-i686 +0 -0
  169. data/utils/launchers/launcher-linux-x86_64 +0 -0
  170. data/utils/launchers/launcher-win32-i86pc.exe +0 -0
  171. metadata +404 -0
@@ -0,0 +1,260 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Button" do
5
+ before :each do
6
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
7
+ end
8
+
9
+ # Exists method
10
+ describe "#exists?" do
11
+ it "returns true if the button exists" do
12
+ browser.button(:id, "new_user_submit").should exist
13
+ browser.button(:id, /new_user_submit/).should exist
14
+ browser.button(:name, "new_user_reset").should exist
15
+ browser.button(:name, /new_user_reset/).should exist
16
+ browser.button(:value, "Button 2").should exist
17
+ browser.button(:value, /Button 2/).should exist
18
+ browser.button(:src, "images/button.jpg").should exist
19
+ browser.button(:src, /button.jpg/).should exist
20
+ browser.button(:text, "Button 2").should exist
21
+ browser.button(:text, /Button 2/).should exist
22
+ browser.button(:class, "image").should exist
23
+ browser.button(:class, /image/).should exist
24
+ browser.button(:index, 1).should exist
25
+ browser.button(:xpath, "//input[@id='new_user_submit']").should exist
26
+ browser.button(:alt, "Create a new user").should exist
27
+ browser.button(:alt, /Create a/).should exist
28
+ end
29
+
30
+ it "returns true if the button exists (how = :caption)" do
31
+ browser.button(:caption, "Button 2").should exist
32
+ browser.button(:caption, /Button 2/).should exist
33
+ end
34
+
35
+ it "returns true if the button exists (default how = :value)" do
36
+ browser.button("Submit").should exist
37
+ end
38
+
39
+ it "returns the first button if given no args" do
40
+ browser.button.should exist
41
+ end
42
+
43
+ it "returns false if the button doesn't exist" do
44
+ browser.button(:id, "no_such_id").should_not exist
45
+ browser.button(:id, /no_such_id/).should_not exist
46
+ browser.button(:name, "no_such_name").should_not exist
47
+ browser.button(:name, /no_such_name/).should_not exist
48
+ browser.button(:value, "no_such_value").should_not exist
49
+ browser.button(:value, /no_such_value/).should_not exist
50
+ browser.button(:src, "no_such_src").should_not exist
51
+ browser.button(:src, /no_such_src/).should_not exist
52
+ browser.button(:text, "no_such_text").should_not exist
53
+ browser.button(:text, /no_such_text/).should_not exist
54
+ browser.button(:class, "no_such_class").should_not exist
55
+ browser.button(:class, /no_such_class/).should_not exist
56
+ browser.button(:index, 1337).should_not exist
57
+ browser.button(:xpath, "//input[@id='no_such_id']").should_not exist
58
+ end
59
+
60
+ it "checks the tag name and type attribute when locating by xpath" do
61
+ browser.button(:xpath, "//input[@type='text']").should_not exist
62
+ browser.button(:xpath, "//input[@type='button']").should exist
63
+ end
64
+
65
+ it "raises TypeError when 'what' argument is invalid" do
66
+ lambda { browser.button(:id, 3.14).exists? }.should raise_error TypeError
67
+ end
68
+
69
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
70
+ lambda { browser.button(:no_such_how, 'some_value').exists? }.should raise_error MissingWayOfFindingObjectException
71
+ end
72
+ end
73
+
74
+ # Attribute methods
75
+ describe "#class_name" do
76
+ it "returns the class name of the button" do
77
+ browser.button(:name, "new_user_image").class_name.should == "image"
78
+ end
79
+
80
+ it "returns an empty string if the button has no class name" do
81
+ browser.button(:name, "new_user_submit").class_name.should == ""
82
+ end
83
+ end
84
+
85
+ describe "#id" do
86
+ it "returns the id if the button exists" do
87
+ browser.button(:index, 1).id.should == 'new_user_submit'
88
+ browser.button(:index, 2).id.should == 'new_user_reset'
89
+ browser.button(:index, 3).id.should == 'new_user_button'
90
+ end
91
+
92
+ it "raises UnknownObjectException if button does not exist" do
93
+ lambda { browser.button(:index, 1337).id }.should raise_error UnknownObjectException
94
+ end
95
+ end
96
+
97
+ describe "#name" do
98
+ it "returns the name if button exists" do
99
+ browser.button(:index, 1).name.should == 'new_user_submit'
100
+ browser.button(:index, 2).name.should == 'new_user_reset'
101
+ browser.button(:index, 3).name.should == 'new_user_button'
102
+ end
103
+
104
+ it "raises UnknownObjectException if the button does not exist" do
105
+ lambda { browser.button(:name, "no_such_name").name }.should raise_error UnknownObjectException
106
+ end
107
+ end
108
+
109
+ describe "#src" do
110
+ not_compliant_on :watir do
111
+ it "returns the src attribute for the button image" do
112
+ browser.button(:name, "new_user_image").src.should == "images/button.jpg"
113
+ end
114
+ end
115
+
116
+ deviates_on :watir do
117
+ it "returns the full url for the button image" do
118
+ browser.button(:name, "new_user_image").src.should == "images/button.jpg"
119
+ end
120
+ end
121
+
122
+ it "raises UnknownObjectException if the button does not exist" do
123
+ lambda { browser.button(:name, "no_such_name").src }.should raise_error UnknownObjectException
124
+ end
125
+ end
126
+
127
+ describe "#style" do
128
+ deviates_on :watir do
129
+ it "returns the style attribute if the button exists" do
130
+ browser.button(:id, 'delete_user_submit').style.should == "border-right: red 4px solid; border-top: red 4px solid; border-left: red 4px solid; border-bottom: red 4px solid"
131
+ end
132
+ end
133
+
134
+ not_compliant_on :watir do
135
+ it "returns the style attribute if the button exists" do
136
+ browser.button(:id, 'delete_user_submit').style.should == "border: 4px solid red;"
137
+ end
138
+ end
139
+
140
+ it "returns an empty string if the element exists and the attribute doesn't exist" do
141
+ browser.button(:id, 'new_user_submit').style.should == ""
142
+ end
143
+
144
+ it "raises UnknownObjectException if the button does not exist" do
145
+ lambda { browser.button(:name, "no_such_name").style }.should raise_error UnknownObjectException
146
+ end
147
+ end
148
+
149
+ describe "#title" do
150
+ it "returns the title of the button" do
151
+ browser.button(:index, 1).title.should == 'Submit the form'
152
+ end
153
+
154
+ it "returns an empty string for button without title" do
155
+ browser.button(:index, 2).title.should == ''
156
+ end
157
+ end
158
+
159
+ describe "#type" do
160
+ it "returns the type if button exists" do
161
+ browser.button(:index, 1).type.should == 'submit'
162
+ browser.button(:index, 2).type.should == 'reset'
163
+ browser.button(:index, 3).type.should == 'button'
164
+ end
165
+
166
+ it "raises UnknownObjectException if button does not exist" do
167
+ lambda { browser.button(:name, "no_such_name").type }.should raise_error UnknownObjectException
168
+ end
169
+ end
170
+
171
+ describe "#value" do
172
+ it "returns the value if button exists" do
173
+ browser.button(:index, 1).value.should == 'Submit'
174
+ browser.button(:index, 2).value.should == 'Reset'
175
+ browser.button(:index, 3).value.should == 'Button'
176
+ end
177
+
178
+ it "raises UnknownObjectException if button does not exist" do
179
+ lambda { browser.button(:name, "no_such_name").value }.should raise_error UnknownObjectException
180
+ end
181
+ end
182
+
183
+ describe "#text" do
184
+ it "returns the text of the button" do
185
+ browser.button(:index, 1).text.should == 'Submit'
186
+ browser.button(:index, 2).text.should == 'Reset'
187
+ browser.button(:index, 3).text.should == 'Button'
188
+ browser.button(:index, 4).text.should == "Button 2"
189
+ end
190
+
191
+ it "raises UnknownObjectException if the element does not exist" do
192
+ lambda { browser.button(:id, "no_such_id").text }.should raise_error UnknownObjectException
193
+ end
194
+ end
195
+
196
+ describe "#respond_to?" do
197
+ it "returns true for all attribute methods" do
198
+ browser.button(:index, 1).should respond_to(:class_name)
199
+ browser.button(:index, 1).should respond_to(:id)
200
+ browser.button(:index, 1).should respond_to(:name)
201
+ browser.button(:index, 1).should respond_to(:src)
202
+ browser.button(:index, 1).should respond_to(:style)
203
+ browser.button(:index, 1).should respond_to(:title)
204
+ browser.button(:index, 1).should respond_to(:type)
205
+ browser.button(:index, 1).should respond_to(:value)
206
+ end
207
+ end
208
+
209
+ # Access methods
210
+ describe "#enabled?" do
211
+ it "returns true if the button is enabled" do
212
+ browser.button(:name, 'new_user_submit').should be_enabled
213
+ end
214
+
215
+ it "returns false if the button is disabled" do
216
+ browser.button(:name, 'new_user_submit_disabled').should_not be_enabled
217
+ end
218
+
219
+ it "raises UnknownObjectException if the button doesn't exist" do
220
+ lambda { browser.button(:name, "no_such_name").enabled? }.should raise_error UnknownObjectException
221
+ end
222
+ end
223
+
224
+ describe "#disabled?" do
225
+ it "returns false when button is enabled" do
226
+ browser.button(:name, 'new_user_submit').should_not be_disabled
227
+ end
228
+
229
+ it "returns true when button is disabled" do
230
+ browser.button(:name, 'new_user_submit_disabled').should be_disabled
231
+ end
232
+
233
+ it "raises UnknownObjectException if button does not exist" do
234
+ lambda { browser.button(:name, "no_such_name").disabled? }.should raise_error UnknownObjectException
235
+ end
236
+ end
237
+
238
+ # Manipulation methods
239
+ describe "#click" do
240
+ it "clicks the button if it exists" do
241
+ browser.goto(WatirSpec.host + "/forms_with_input_elements.html")
242
+ browser.button(:id, 'new_user_submit').click
243
+ browser.text.should include("You posted the following content:")
244
+ end
245
+
246
+ it "fires events" do
247
+ browser.button(:id, 'new_user_button').click
248
+ browser.button(:id, 'new_user_button').value.should == 'new_value_set_by_onclick_event'
249
+ end
250
+
251
+ it "raises UnknownObjectException when clicking a button that doesn't exist" do
252
+ lambda { browser.button(:value, "no_such_value").click }.should raise_error UnknownObjectException
253
+ lambda { browser.button(:id, "no_such_id").click }.should raise_error UnknownObjectException
254
+ end
255
+
256
+ it "raises ObjectDisabledException when clicking a disabled button" do
257
+ lambda { browser.button(:value, "Disabled").click }.should raise_error ObjectDisabledException
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Buttons" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ bug "WTR-349", :watir do
12
+ it "returns the number of buttons" do
13
+ browser.buttons.length.should == 8
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "#[]" do
19
+ it "returns the button at the given index" do
20
+ browser.buttons[1].title.should == "Submit the form"
21
+ end
22
+ end
23
+
24
+ describe "#first" do
25
+ it "returns the first element in the collection" do
26
+ browser.buttons.first.value.should == browser.buttons[1].value
27
+ end
28
+ end
29
+
30
+ describe "#last" do
31
+ bug "WTR-349", :watir do
32
+ it "returns the last element in the collection" do
33
+ browser.buttons.last.value.should == browser.buttons[0].value
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#each" do
39
+ it "iterates through buttons correctly" do
40
+ count = 0
41
+
42
+ browser.buttons.each_with_index do |b, index|
43
+ b.name.should == browser.button(:index, index+1).name
44
+ b.id.should == browser.button(:index, index+1).id
45
+ b.value.should == browser.button(:index, index+1).value
46
+
47
+ count += 1
48
+ end
49
+
50
+ count.should > 0
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,280 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "CheckBox" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+
12
+ describe "#exists?" do
13
+ it "returns true if the checkbox button exists" do
14
+ browser.checkbox(:id, "new_user_interests_books").should exist
15
+ browser.checkbox(:id, /new_user_interests_books/).should exist
16
+ browser.checkbox(:name, "new_user_interests").should exist
17
+ browser.checkbox(:name, /new_user_interests/).should exist
18
+ browser.checkbox(:value, "books").should exist
19
+ browser.checkbox(:value, /books/).should exist
20
+ # not sure what :text is supposed to represent here
21
+ # browser.checkbox(:text, "books").should exist
22
+ # browser.checkbox(:text, /books/).should exist
23
+ browser.checkbox(:class, "fun").should exist
24
+ browser.checkbox(:class, /fun/).should exist
25
+ browser.checkbox(:index, 1).should exist
26
+ browser.checkbox(:xpath, "//input[@id='new_user_interests_books']").should exist
27
+ end
28
+
29
+ it "returns true if the element exists (default how = :name)" do
30
+ browser.checkbox("new_user_interests").should exist
31
+ end
32
+
33
+ it "returns true if the checkbox button exists (search by name and value)" do
34
+ browser.checkbox(:name, "new_user_interests", 'cars').should exist
35
+ browser.checkbox(:xpath, "//input[@name='new_user_interests' and @value='cars']").set
36
+ end
37
+
38
+ it "returns the first checkbox if given no args" do
39
+ browser.checkbox.should exist
40
+ end
41
+
42
+ it "returns false if the checkbox button does not exist" do
43
+ browser.checkbox(:id, "no_such_id").should_not exist
44
+ browser.checkbox(:id, /no_such_id/).should_not exist
45
+ browser.checkbox(:name, "no_such_name").should_not exist
46
+ browser.checkbox(:name, /no_such_name/).should_not exist
47
+ browser.checkbox(:value, "no_such_value").should_not exist
48
+ browser.checkbox(:value, /no_such_value/).should_not exist
49
+ browser.checkbox(:text, "no_such_text").should_not exist
50
+ browser.checkbox(:text, /no_such_text/).should_not exist
51
+ browser.checkbox(:class, "no_such_class").should_not exist
52
+ browser.checkbox(:class, /no_such_class/).should_not exist
53
+ browser.checkbox(:index, 1337).should_not exist
54
+ browser.checkbox(:xpath, "//input[@id='no_such_id']").should_not exist
55
+ end
56
+
57
+ it "returns false if the checkbox button does not exist (search by name and value)" do
58
+ browser.checkbox(:name, "new_user_interests", 'no_such_value').should_not exist
59
+ browser.checkbox(:xpath, "//input[@name='new_user_interests' and @value='no_such_value']").should_not exist
60
+ browser.checkbox(:name, "no_such_name", 'cars').should_not exist
61
+ browser.checkbox(:xpath, "//input[@name='no_such_name' and @value='cars']").should_not exist
62
+ end
63
+
64
+ it "returns true for checkboxs with a string value" do
65
+ browser.checkbox(:name, 'new_user_interests', 'books').should exist
66
+ browser.checkbox(:name, 'new_user_interests', 'cars').should exist
67
+ end
68
+
69
+ it "raises TypeError when 'what' argument is invalid" do
70
+ lambda { browser.checkbox(:id, 3.14).exists? }.should raise_error(TypeError)
71
+ end
72
+
73
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
74
+ lambda { browser.checkbox(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
75
+ end
76
+ end
77
+
78
+ # Attribute methods
79
+
80
+ describe "#class_name" do
81
+ it "returns the class name if the checkbox exists and has an attribute" do
82
+ browser.checkbox(:id, "new_user_interests_dancing").class_name.should == "fun"
83
+ end
84
+
85
+ it "returns an emptry string if the checkbox exists and the attribute doesn't" do
86
+ browser.checkbox(:id, "new_user_interests_books").class_name.should == ""
87
+ end
88
+
89
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
90
+ lambda { browser.checkbox(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
91
+ end
92
+ end
93
+
94
+ describe "#id" do
95
+ it "returns the id attribute if the checkbox exists and has an attribute" do
96
+ browser.checkbox(:index, 1).id.should == "new_user_interests_books"
97
+ end
98
+
99
+ it "returns an emptry string if the checkbox exists and the attribute doesn't" do
100
+ browser.checkbox(:index, 2).id.should == ""
101
+ end
102
+
103
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
104
+ lambda { browser.checkbox(:index, 1337).id }.should raise_error(UnknownObjectException)
105
+ end
106
+ end
107
+
108
+ describe "#name" do
109
+ it "returns the name attribute if the checkbox exists" do
110
+ browser.checkbox(:id, 'new_user_interests_books').name.should == "new_user_interests"
111
+ end
112
+
113
+ it "returns an empty string if the checkbox exists and the attribute doesn't" do
114
+ browser.checkbox(:id, 'new_user_interests_food').name.should == ""
115
+ end
116
+
117
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
118
+ lambda { browser.checkbox(:index, 1337).name }.should raise_error(UnknownObjectException)
119
+ end
120
+ end
121
+
122
+ describe "#title" do
123
+ it "returns the title attribute if the checkbox exists" do
124
+ browser.checkbox(:id, "new_user_interests_dancing").title.should == "Dancing is fun!"
125
+ end
126
+
127
+ it "returns an emptry string if the checkbox exists and the attribute doesn't" do
128
+ browser.checkbox(:id, "new_user_interests_books").title.should == ""
129
+ end
130
+
131
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
132
+ lambda { browser.checkbox(:index, 1337).title }.should raise_error(UnknownObjectException)
133
+ end
134
+ end
135
+
136
+ describe "#type" do
137
+ it "returns the type attribute if the checkbox exists" do
138
+ browser.checkbox(:index, 1).type.should == "checkbox"
139
+ end
140
+
141
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
142
+ lambda { browser.checkbox(:index, 1337).type }.should raise_error(UnknownObjectException)
143
+ end
144
+ end
145
+
146
+ describe "#value" do
147
+ it "returns the value attribute if the checkbox exists" do
148
+ browser.checkbox(:id, 'new_user_interests_books').value.should == 'books'
149
+ end
150
+
151
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
152
+ lambda { browser.checkbox(:index, 1337).value}.should raise_error(UnknownObjectException)
153
+ end
154
+ end
155
+
156
+ describe "#respond_to?" do
157
+ it "returns true for all attribute methods" do
158
+ browser.checkbox(:index, 1).should respond_to(:class_name)
159
+ browser.checkbox(:index, 1).should respond_to(:id)
160
+ browser.checkbox(:index, 1).should respond_to(:name)
161
+ browser.checkbox(:index, 1).should respond_to(:title)
162
+ browser.checkbox(:index, 1).should respond_to(:type)
163
+ browser.checkbox(:index, 1).should respond_to(:value)
164
+ end
165
+ end
166
+
167
+ # Access methods
168
+
169
+ describe "#enabled?" do
170
+ it "returns true if the checkbox button is enabled" do
171
+ browser.checkbox(:id, "new_user_interests_books").should be_enabled
172
+ browser.checkbox(:xpath, "//input[@id='new_user_interests_books']").should be_enabled
173
+ end
174
+
175
+ it "returns false if the checkbox button is disabled" do
176
+ browser.checkbox(:id, "new_user_interests_dentistry").should_not be_enabled
177
+ browser.checkbox(:xpath,"//input[@id='new_user_interests_dentistry']").should_not be_enabled
178
+ end
179
+
180
+ it "raises UnknownObjectException if the checkbox button doesn't exist" do
181
+ lambda { browser.checkbox(:id, "no_such_id").enabled? }.should raise_error(UnknownObjectException)
182
+ lambda { browser.checkbox(:xpath, "//input[@id='no_such_id']").enabled? }.should raise_error(UnknownObjectException)
183
+ end
184
+ end
185
+
186
+ describe "#disabled?" do
187
+ it "returns true if the checkbox is disabled" do
188
+ browser.checkbox(:id, 'new_user_interests_dentistry').should be_disabled
189
+ end
190
+
191
+ it "returns false if the checkbox is enabled" do
192
+ browser.checkbox(:id, 'new_user_interests_books').should_not be_disabled
193
+ end
194
+
195
+ it "raises UnknownObjectException if the checkbox doesn't exist" do
196
+ lambda { browser.checkbox(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
197
+ end
198
+ end
199
+
200
+ # Manipulation methods
201
+
202
+ describe "#clear" do
203
+ it "raises ObjectDisabledException if the checkbox is disabled" do
204
+ browser.checkbox(:id, "new_user_interests_dentistry").should_not be_set
205
+ lambda { browser.checkbox(:id, "new_user_interests_dentistry").clear }.should raise_error(ObjectDisabledException)
206
+ lambda { browser.checkbox(:xpath, "//input[@id='new_user_interests_dentistry']").clear }.should raise_error(ObjectDisabledException)
207
+ end
208
+
209
+ it "clears the checkbox button if it is set" do
210
+ browser.checkbox(:id, "new_user_interests_books").clear
211
+ browser.checkbox(:id, "new_user_interests_books").should_not be_set
212
+ end
213
+
214
+ it "clears the checkbox button when found by :xpath" do
215
+ browser.checkbox(:xpath, "//input[@id='new_user_interests_books']").clear
216
+ browser.checkbox(:xpath, "//input[@id='new_user_interests_books']").should_not be_set
217
+ end
218
+
219
+ it "raises UnknownObjectException if the checkbox button doesn't exist" do
220
+ lambda { browser.checkbox(:name, "no_such_id").clear }.should raise_error(UnknownObjectException)
221
+ lambda { browser.checkbox(:xpath, "//input[@id='no_such_id']").clear }.should raise_error(UnknownObjectException)
222
+ end
223
+ end
224
+
225
+ describe "#set" do
226
+ it "sets the checkbox button" do
227
+ browser.checkbox(:id, "new_user_interests_cars").set
228
+ browser.checkbox(:id, "new_user_interests_cars").should be_set
229
+ end
230
+
231
+ it "sets the checkbox button when found by :xpath" do
232
+ browser.checkbox(:xpath, "//input[@id='new_user_interests_cars']").set
233
+ browser.checkbox(:xpath, "//input[@id='new_user_interests_cars']").should be_set
234
+ end
235
+
236
+ it "fires the onclick event" do
237
+ browser.button(:id, "disabled_button").should be_disabled
238
+ browser.checkbox(:id, "toggle_button_checkbox").set
239
+ browser.button(:id, "disabled_button").should_not be_disabled
240
+ browser.checkbox(:id, "toggle_button_checkbox").clear
241
+ browser.button(:id, "disabled_button").should be_disabled
242
+ end
243
+
244
+ it "raises UnknownObjectException if the checkbox button doesn't exist" do
245
+ lambda { browser.checkbox(:name, "no_such_name").set }.should raise_error(UnknownObjectException)
246
+ lambda { browser.checkbox(:xpath, "//input[@name='no_such_name']").set }.should raise_error(UnknownObjectException)
247
+ end
248
+
249
+ it "raises ObjectDisabledException if the checkbox is disabled" do
250
+ lambda { browser.checkbox(:id, "new_user_interests_dentistry").set }.should raise_error(ObjectDisabledException)
251
+ lambda { browser.checkbox(:xpath, "//input[@id='new_user_interests_dentistry']").set }.should raise_error(ObjectDisabledException )
252
+ end
253
+ end
254
+
255
+ # Other
256
+
257
+ describe '#set?' do
258
+ it "returns true if the checkbox button is set" do
259
+ browser.checkbox(:id, "new_user_interests_books").should be_set
260
+ end
261
+
262
+ it "returns false if the checkbox button unset" do
263
+ browser.checkbox(:id, "new_user_interests_cars").should_not be_set
264
+ end
265
+
266
+ it "returns the state for checkboxs with string values" do
267
+ browser.checkbox(:name, "new_user_interests", 'cars').should_not be_set
268
+ browser.checkbox(:name, "new_user_interests", 'cars').set
269
+ browser.checkbox(:name, "new_user_interests", 'cars').should be_set
270
+ browser.checkbox(:name, "new_user_interests", 'cars').clear
271
+ browser.checkbox(:name, "new_user_interests", 'cars').should_not be_set
272
+ end
273
+
274
+ it "raises UnknownObjectException if the checkbox button doesn't exist" do
275
+ lambda { browser.checkbox(:id, "no_such_id").set? }.should raise_error(UnknownObjectException)
276
+ lambda { browser.checkbox(:xpath, "//input[@id='no_such_id']").set? }.should raise_error(UnknownObjectException)
277
+ end
278
+ end
279
+
280
+ end