watir-webdriver 0.0.1.dev

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 (125) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/.gitmodules +3 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +32 -0
  6. data/Rakefile +107 -0
  7. data/TODO +15 -0
  8. data/VERSION +1 -0
  9. data/lib/watir-webdriver.rb +74 -0
  10. data/lib/watir-webdriver/base_element.rb +347 -0
  11. data/lib/watir-webdriver/browser.rb +130 -0
  12. data/lib/watir-webdriver/browserbot.js +34 -0
  13. data/lib/watir-webdriver/collections/buttons_collection.rb +13 -0
  14. data/lib/watir-webdriver/collections/element_collection.rb +45 -0
  15. data/lib/watir-webdriver/collections/table_rows_collection.rb +14 -0
  16. data/lib/watir-webdriver/collections/text_fields_collection.rb +13 -0
  17. data/lib/watir-webdriver/container.rb +24 -0
  18. data/lib/watir-webdriver/core_ext/string.rb +22 -0
  19. data/lib/watir-webdriver/elements/button.rb +27 -0
  20. data/lib/watir-webdriver/elements/checkbox.rb +23 -0
  21. data/lib/watir-webdriver/elements/file_field.rb +20 -0
  22. data/lib/watir-webdriver/elements/form.rb +11 -0
  23. data/lib/watir-webdriver/elements/generated.rb +941 -0
  24. data/lib/watir-webdriver/elements/headings.rb +48 -0
  25. data/lib/watir-webdriver/elements/hidden.rb +18 -0
  26. data/lib/watir-webdriver/elements/image.rb +33 -0
  27. data/lib/watir-webdriver/elements/input.rb +39 -0
  28. data/lib/watir-webdriver/elements/link.rb +13 -0
  29. data/lib/watir-webdriver/elements/option.rb +36 -0
  30. data/lib/watir-webdriver/elements/radio.rb +23 -0
  31. data/lib/watir-webdriver/elements/select_list.rb +73 -0
  32. data/lib/watir-webdriver/elements/shared_radio_checkbox.rb +13 -0
  33. data/lib/watir-webdriver/elements/table.rb +18 -0
  34. data/lib/watir-webdriver/elements/table_row.rb +17 -0
  35. data/lib/watir-webdriver/elements/text_field.rb +60 -0
  36. data/lib/watir-webdriver/exception.rb +20 -0
  37. data/lib/watir-webdriver/locators/button_locator.rb +57 -0
  38. data/lib/watir-webdriver/locators/element_locator.rb +269 -0
  39. data/lib/watir-webdriver/locators/table_row_locator.rb +25 -0
  40. data/lib/watir-webdriver/locators/text_field_locator.rb +61 -0
  41. data/lib/watir-webdriver/xpath_support.rb +23 -0
  42. data/spec/element_locator_spec.rb +11 -0
  43. data/spec/spec_helper.rb +16 -0
  44. data/spec/watirspec/area_spec.rb +78 -0
  45. data/spec/watirspec/areas_spec.rb +31 -0
  46. data/spec/watirspec/browser_spec.rb +262 -0
  47. data/spec/watirspec/button_spec.rb +242 -0
  48. data/spec/watirspec/buttons_spec.rb +48 -0
  49. data/spec/watirspec/checkbox_spec.rb +272 -0
  50. data/spec/watirspec/checkboxes_spec.rb +32 -0
  51. data/spec/watirspec/dd_spec.rb +136 -0
  52. data/spec/watirspec/dds_spec.rb +31 -0
  53. data/spec/watirspec/div_spec.rb +222 -0
  54. data/spec/watirspec/divs_spec.rb +31 -0
  55. data/spec/watirspec/dl_spec.rb +136 -0
  56. data/spec/watirspec/dls_spec.rb +32 -0
  57. data/spec/watirspec/dt_spec.rb +136 -0
  58. data/spec/watirspec/dts_spec.rb +31 -0
  59. data/spec/watirspec/element_spec.rb +87 -0
  60. data/spec/watirspec/em_spec.rb +110 -0
  61. data/spec/watirspec/ems_spec.rb +32 -0
  62. data/spec/watirspec/filefield_spec.rb +119 -0
  63. data/spec/watirspec/filefields_spec.rb +32 -0
  64. data/spec/watirspec/form_spec.rb +63 -0
  65. data/spec/watirspec/forms_spec.rb +33 -0
  66. data/spec/watirspec/frame_spec.rb +140 -0
  67. data/spec/watirspec/frames_spec.rb +62 -0
  68. data/spec/watirspec/hidden_spec.rb +102 -0
  69. data/spec/watirspec/hiddens_spec.rb +32 -0
  70. data/spec/watirspec/hn_spec.rb +93 -0
  71. data/spec/watirspec/hns_spec.rb +38 -0
  72. data/spec/watirspec/image_spec.rb +207 -0
  73. data/spec/watirspec/images_spec.rb +31 -0
  74. data/spec/watirspec/label_spec.rb +75 -0
  75. data/spec/watirspec/labels_spec.rb +31 -0
  76. data/spec/watirspec/li_spec.rb +127 -0
  77. data/spec/watirspec/lib/guards.rb +59 -0
  78. data/spec/watirspec/lib/server.rb +127 -0
  79. data/spec/watirspec/lib/spec_helper.rb +79 -0
  80. data/spec/watirspec/lib/watirspec.rb +72 -0
  81. data/spec/watirspec/link_spec.rb +165 -0
  82. data/spec/watirspec/links_spec.rb +35 -0
  83. data/spec/watirspec/lis_spec.rb +31 -0
  84. data/spec/watirspec/map_spec.rb +92 -0
  85. data/spec/watirspec/maps_spec.rb +32 -0
  86. data/spec/watirspec/meta_spec.rb +22 -0
  87. data/spec/watirspec/metas_spec.rb +30 -0
  88. data/spec/watirspec/ol_spec.rb +78 -0
  89. data/spec/watirspec/ols_spec.rb +31 -0
  90. data/spec/watirspec/option_spec.rb +173 -0
  91. data/spec/watirspec/p_spec.rb +143 -0
  92. data/spec/watirspec/pre_spec.rb +125 -0
  93. data/spec/watirspec/pres_spec.rb +31 -0
  94. data/spec/watirspec/ps_spec.rb +31 -0
  95. data/spec/watirspec/radio_spec.rb +278 -0
  96. data/spec/watirspec/radios_spec.rb +32 -0
  97. data/spec/watirspec/select_list_spec.rb +318 -0
  98. data/spec/watirspec/select_lists_spec.rb +35 -0
  99. data/spec/watirspec/span_spec.rb +157 -0
  100. data/spec/watirspec/spans_spec.rb +57 -0
  101. data/spec/watirspec/spec_helper.rb +17 -0
  102. data/spec/watirspec/strong_spec.rb +89 -0
  103. data/spec/watirspec/strongs_spec.rb +32 -0
  104. data/spec/watirspec/table_bodies_spec.rb +45 -0
  105. data/spec/watirspec/table_body_spec.rb +98 -0
  106. data/spec/watirspec/table_cell_spec.rb +68 -0
  107. data/spec/watirspec/table_cells_spec.rb +47 -0
  108. data/spec/watirspec/table_footer_spec.rb +85 -0
  109. data/spec/watirspec/table_footers_spec.rb +47 -0
  110. data/spec/watirspec/table_header_spec.rb +85 -0
  111. data/spec/watirspec/table_headers_spec.rb +45 -0
  112. data/spec/watirspec/table_row_spec.rb +87 -0
  113. data/spec/watirspec/table_rows_spec.rb +50 -0
  114. data/spec/watirspec/table_spec.rb +166 -0
  115. data/spec/watirspec/tables_spec.rb +33 -0
  116. data/spec/watirspec/text_field_spec.rb +276 -0
  117. data/spec/watirspec/text_fields_spec.rb +35 -0
  118. data/spec/watirspec/ul_spec.rb +76 -0
  119. data/spec/watirspec/uls_spec.rb +33 -0
  120. data/spec/xpath_builder_spec.rb +49 -0
  121. data/support/html5/html5.idl +815 -0
  122. data/support/html5/html5_extras.idl +147 -0
  123. data/support/html5/idl_extractor.rb +73 -0
  124. data/support/html5/watir_visitor.rb +169 -0
  125. metadata +220 -0
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Areas" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/images.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of areas" do
12
+ browser.areas.length.should == 3
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the area at the given index" do
18
+ browser.areas[0].id.should == "NCE"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through areas correctly" do
24
+ browser.areas.each_with_index do |a, index|
25
+ a.id.should == browser.area(:index, index).id
26
+ a.value.should == browser.area(:index, index).value
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,262 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Browser" do
5
+
6
+ describe "#exists?" do
7
+ it "returns true if we are at a page" do
8
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
9
+ browser.should exist
10
+ end
11
+
12
+ not_compliant_on :webdriver do
13
+ it "returns false after IE#close" do
14
+ b = WatirSpec.new_browser
15
+ b.close
16
+ b.should_not exist
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "#html" do
22
+ # what guard we want to use here kind of depends on how other impls. behave
23
+ not_compliant_on :watir do
24
+ it "returns the downloaed HTML of the page" do
25
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
26
+ browser.html.should == File.read(File.dirname(__FILE__) + "/html/non_control_elements.html")
27
+ end
28
+ end
29
+
30
+ deviates_on :watir do
31
+ it "returns the DOM of the page as an HTML string" do
32
+ browser.goto(WatirSpec.files + "/right_click.html")
33
+ browser.html.should == "<HTML><HEAD><TITLE>Right Click Test</TITLE>\r\n<META http-equiv=Content-type content=\"text/html; charset=utf-8\">\r\n<SCRIPT src=\"javascript/helpers.js\" type=text/javascript charset=utf-8></SCRIPT>\r\n</HEAD>\r\n<BODY>\r\n<DIV id=messages></DIV>\r\n<DIV oncontextmenu='WatirSpec.addMessage(\"right-clicked\")' id=click>Right click!</DIV></BODY></HTML>"
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#title" do
39
+ it "returns the current page title" do
40
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
41
+ browser.title.should == "Non-control elements"
42
+ end
43
+ end
44
+
45
+ describe "#status" do
46
+ bug "WTR-348", :watir do
47
+ it "returns the current value of window.status" do
48
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
49
+
50
+ # for firefox, this needs to be enabled in
51
+ # Preferences -> Content -> Advanced -> Change status bar text
52
+ browser.execute_script "window.status = 'All done!';"
53
+ browser.status.should == "All done!"
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#text" do
59
+ it "returns the text of the page" do
60
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
61
+ browser.text.should include("Dubito, ergo cogito, ergo sum.")
62
+ end
63
+
64
+ it "returns the text also if the content-type is text/plain" do
65
+ # more specs for text/plain? what happens if we call other methods?
66
+ browser.goto(WatirSpec.host + "/plain_text")
67
+ browser.text.strip.should == 'This is text/plain'
68
+ end
69
+ end
70
+
71
+ describe "#url" do
72
+ it "returns the current url" do
73
+ browser.goto(WatirSpec.host + "/non_control_elements.html")
74
+ browser.url.should == WatirSpec.host + "/non_control_elements.html"
75
+ end
76
+ end
77
+
78
+ not_compliant_on :webdriver do
79
+ # just hangs with watir-webdriver + IE
80
+ describe ".start" do
81
+ it "goes to the given URL and return an instance of itself" do
82
+ browser = Browser.start("#{WatirSpec.files}/non_control_elements.html")
83
+ browser.should be_instance_of(Browser)
84
+ browser.title.should == "Non-control elements"
85
+ browser.quit
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "#goto" do
91
+ it "adds http:// to URLs with no URL scheme specified" do
92
+ url = WatirSpec.host[%r{http://(.*)}, 1]
93
+ url.should_not be_nil
94
+ browser.goto(url)
95
+ browser.url.should =~ %r[http://#{url}/?]
96
+ end
97
+
98
+ it "goes to the given url without raising errors" do
99
+ lambda { browser.goto(WatirSpec.files + "/non_control_elements.html") }.should_not raise_error
100
+ end
101
+
102
+ it "updates the page when location is changed with setTimeout + window.location" do
103
+ browser.goto(WatirSpec.files + "/timeout_window_location.html")
104
+ sleep 1
105
+ browser.url.should include("non_control_elements.html")
106
+ end
107
+ end
108
+
109
+ describe "#refresh" do
110
+ it "refreshes the page" do
111
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
112
+ browser.span(:class, 'footer').click
113
+ browser.span(:class, 'footer').text.should include('Javascript')
114
+ browser.refresh
115
+ browser.span(:class, 'footer').text.should_not include('Javascript')
116
+ end
117
+ end
118
+
119
+ describe "#execute_script" do
120
+ it "executes the given JavaScript on the current page" do
121
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
122
+ browser.pre(:id, 'rspec').text.should_not == "javascript text"
123
+ browser.execute_script("document.getElementById('rspec').innerHTML = 'javascript text'")
124
+ browser.pre(:id, 'rspec').text.should == "javascript text"
125
+ end
126
+ end
127
+
128
+ describe "#back and #forward" do
129
+ it "goes to the previous page" do
130
+ browser.goto("#{WatirSpec.host}/non_control_elements.html")
131
+ orig_url = browser.url
132
+ browser.goto("#{WatirSpec.host}/tables.html")
133
+ new_url = browser.url
134
+ orig_url.should_not == new_url
135
+ browser.back
136
+ orig_url.should == browser.url
137
+ end
138
+
139
+ it "goes to the next page" do
140
+ urls = []
141
+ browser.goto(WatirSpec.host + "/non_control_elements.html")
142
+ urls << browser.url
143
+ browser.goto(WatirSpec.host + "/tables.html")
144
+ urls << browser.url
145
+
146
+ browser.back
147
+ browser.url.should == urls.first
148
+ browser.forward
149
+ browser.url.should == urls.last
150
+ end
151
+
152
+ it "navigates between several history items" do
153
+ urls = [ "#{WatirSpec.host}/non_control_elements.html",
154
+ "#{WatirSpec.host}/tables.html",
155
+ "#{WatirSpec.host}/forms_with_input_elements.html",
156
+ "#{WatirSpec.host}/definition_lists.html"
157
+ ].map do |page|
158
+ browser.goto page
159
+ browser.url
160
+ end
161
+
162
+ 3.times { browser.back }
163
+ browser.url.should == urls.first
164
+ 2.times { browser.forward }
165
+ browser.url.should == urls[2]
166
+ end
167
+ end
168
+
169
+ describe "#element_by_xpath" do
170
+ before :each do
171
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
172
+ end
173
+
174
+ bug "WTR-343", :watir do
175
+ it "finds submit buttons matching the given xpath" do
176
+ browser.element_by_xpath("//input[@type='submit']").should exist
177
+ end
178
+
179
+ it "finds reset buttons matching the given xpath" do
180
+ browser.element_by_xpath("//input[@type='reset']").should exist
181
+ end
182
+
183
+ it "finds image buttons matching the given xpath" do
184
+ browser.element_by_xpath("//input[@type='image']").should exist
185
+ end
186
+
187
+ it "finds the element matching the given xpath" do
188
+ browser.element_by_xpath("//input[@type='password']").should exist
189
+ end
190
+ end
191
+
192
+ bug "WTR-327", :watir do
193
+ it "will not find elements that doesn't exist" do
194
+ e = browser.element_by_xpath("//input[@type='foobar']")
195
+ e.should_not exist
196
+ lambda { e.text }.should raise_error(UnknownObjectException)
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "#elements_by_xpath" do
202
+ before :each do
203
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
204
+ end
205
+
206
+ bug "WTR-344", :watir do
207
+ it "returns an Array of matching elements" do
208
+ objects = browser.elements_by_xpath("//*[@type='text']")
209
+ objects.should be_kind_of(Array)
210
+ objects.size.should == 5
211
+ end
212
+ end
213
+
214
+ bug "WTR-328", :watir do
215
+ it "returns an empty Array if there are no matching elements" do
216
+ objects = browser.elements_by_xpath("//*[@type='foobar']")
217
+ objects.should be_kind_of(Array)
218
+ objects.size.should == 0
219
+ end
220
+ end
221
+ end
222
+
223
+ describe "#add_checker" do
224
+ it "raises ArgumentError when not given any arguments" do
225
+ lambda { browser.add_checker }.should raise_error(ArgumentError)
226
+ end
227
+
228
+ not_compliant_on :webdriver do
229
+ # if on IE, this slows the rest of the suite way down for some reason
230
+ it "runs the given proc on each page load" do
231
+ output = ''
232
+ proc = Proc.new { |browser| output << browser.text }
233
+
234
+ browser.add_checker(proc)
235
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
236
+
237
+ output.should include('Dubito, ergo cogito, ergo sum')
238
+ end
239
+ end
240
+ end
241
+
242
+ describe "#disable_checker" do
243
+ it "removes a previously added checker" do
244
+ output = ''
245
+ checker = lambda { |browser| output << browser.text }
246
+
247
+ browser.add_checker(checker)
248
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
249
+ output.should include('Dubito, ergo cogito, ergo sum')
250
+
251
+ browser.disable_checker(checker)
252
+ browser.goto(WatirSpec.files + "/definition_lists.html")
253
+ output.should_not include('definition_lists')
254
+ end
255
+ end
256
+
257
+ it "raises UnknownObjectException when trying to access DOM elements on plain/text-page" do
258
+ browser.goto(WatirSpec.host + "/plain_text")
259
+ lambda { browser.div(:id, 'foo').id }.should raise_error(UnknownObjectException)
260
+ end
261
+
262
+ end
@@ -0,0 +1,242 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Button" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the button exists" do
13
+ browser.button(:id, "new_user_submit").should exist
14
+ browser.button(:id, /new_user_submit/).should exist
15
+ browser.button(:name, "new_user_reset").should exist
16
+ browser.button(:name, /new_user_reset/).should exist
17
+ browser.button(:value, "Button 2").should exist
18
+ browser.button(:value, /Button 2/).should exist
19
+ browser.button(:src, "images/button.jpg").should exist
20
+ browser.button(:src, /button.jpg/).should exist
21
+ browser.button(:text, "Button 2").should exist
22
+ browser.button(:text, /Button 2/).should exist
23
+ browser.button(:class, "image").should exist
24
+ browser.button(:class, /image/).should exist
25
+ browser.button(:index, 0).should exist
26
+ browser.button(:xpath, "//input[@id='new_user_submit']").should exist
27
+ browser.button(:alt, "Create a new user").should exist
28
+ browser.button(:alt, /Create a/).should exist
29
+ end
30
+
31
+ it "returns true if the button exists (how = :caption)" do
32
+ browser.button(:caption, "Button 2").should exist
33
+ browser.button(:caption, /Button 2/).should exist
34
+ end
35
+
36
+ it "returns false if the button doesn't exist" do
37
+ browser.button(:id, "no_such_id").should_not exist
38
+ browser.button(:id, /no_such_id/).should_not exist
39
+ browser.button(:name, "no_such_name").should_not exist
40
+ browser.button(:name, /no_such_name/).should_not exist
41
+ browser.button(:value, "no_such_value").should_not exist
42
+ browser.button(:value, /no_such_value/).should_not exist
43
+ browser.button(:src, "no_such_src").should_not exist
44
+ browser.button(:src, /no_such_src/).should_not exist
45
+ browser.button(:text, "no_such_text").should_not exist
46
+ browser.button(:text, /no_such_text/).should_not exist
47
+ browser.button(:class, "no_such_class").should_not exist
48
+ browser.button(:class, /no_such_class/).should_not exist
49
+ browser.button(:index, 1337).should_not exist
50
+ browser.button(:xpath, "//input[@id='no_such_id']").should_not exist
51
+ end
52
+
53
+ it "raises TypeError when 'what' argument is invalid" do
54
+ lambda { browser.button(:id, 3.14).exists? }.should raise_error(TypeError)
55
+ end
56
+
57
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
58
+ lambda { browser.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
59
+ end
60
+
61
+ # it "locates the correct button when there are duplicate ids and user disambiguates by parent" do
62
+ # browser.goto(WatirSpec.files + "/buttons_with_duplicate_ids.html")
63
+ # browser.form(:name, "bar-form").button(:id, 'next').parent.name.should == "bar-form"
64
+ # end
65
+ end
66
+
67
+ # Attribute methods
68
+ describe "#class_name" do
69
+ it "returns the class name of the button" do
70
+ browser.button(:name, "new_user_image").class_name.should == "image"
71
+ end
72
+
73
+ it "returns an empty string if the button has no class name" do
74
+ browser.button(:name, "new_user_submit").class_name.should == ""
75
+ end
76
+ end
77
+
78
+ describe "#id" do
79
+ it "returns the id if the button exists" do
80
+ browser.button(:index, 0).id.should == 'new_user_submit'
81
+ browser.button(:index, 1).id.should == 'new_user_reset'
82
+ browser.button(:index, 2).id.should == 'new_user_button'
83
+ end
84
+
85
+ it "raises UnknownObjectException if button does not exist" do
86
+ lambda { browser.button(:index, 1337).id }.should raise_error(UnknownObjectException)
87
+ end
88
+ end
89
+
90
+ describe "#name" do
91
+ it "returns the name if button exists" do
92
+ browser.button(:index, 0).name.should == 'new_user_submit'
93
+ browser.button(:index, 1).name.should == 'new_user_reset'
94
+ browser.button(:index, 2).name.should == 'new_user_button'
95
+ end
96
+
97
+ it "raises UnknownObjectException if the button does not exist" do
98
+ lambda { browser.button(:name, "no_such_name").name }.should raise_error(UnknownObjectException)
99
+ end
100
+ end
101
+
102
+ describe "#src" do
103
+ not_compliant_on :watir do
104
+ it "returns the src attribute for the button image" do
105
+ browser.button(:name, "new_user_image").src.should == "images/button.jpg"
106
+ end
107
+ end
108
+
109
+ deviates_on :watir do
110
+ it "returns the full url for the button image" do
111
+ browser.button(:name, "new_user_image").src.should == "file:///#{File.dirname(__FILE__)}/images/button.jpg"
112
+ end
113
+ end
114
+
115
+ it "raises UnknownObjectException if the button does not exist" do
116
+ lambda { browser.button(:name, "no_such_name").src }.should raise_error(UnknownObjectException)
117
+ end
118
+ end
119
+
120
+ describe "#style" do
121
+ deviates_on :watir do
122
+ it "returns the style attribute if the button exists" do
123
+ 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"
124
+ end
125
+ end
126
+
127
+ not_compliant_on :watir do
128
+ it "returns the style attribute if the button exists" do
129
+ browser.button(:id, 'delete_user_submit').style.should == "border: 4px solid red;"
130
+ end
131
+ end
132
+
133
+ it "returns an empty string if the element exists and the attribute doesn't exist" do
134
+ browser.button(:id, 'new_user_submit').style.should == ""
135
+ end
136
+
137
+ it "raises UnknownObjectException if the button does not exist" do
138
+ lambda { browser.button(:name, "no_such_name").style }.should raise_error(UnknownObjectException)
139
+ end
140
+ end
141
+
142
+ describe "#title" do
143
+ it "returns the title of the button" do
144
+ browser.button(:index, 0).title.should == 'Submit the form'
145
+ end
146
+
147
+ it "returns an empty string for button without title" do
148
+ browser.button(:index, 1).title.should == ''
149
+ end
150
+ end
151
+
152
+ describe "#type" do
153
+ it "returns the type if button exists" do
154
+ browser.button(:index, 0).type.should == 'submit'
155
+ browser.button(:index, 1).type.should == 'reset'
156
+ browser.button(:index, 2).type.should == 'button'
157
+ end
158
+
159
+ it "raises UnknownObjectException if button does not exist" do
160
+ lambda { browser.button(:name, "no_such_name").type }.should raise_error(UnknownObjectException)
161
+ end
162
+ end
163
+
164
+ describe "#value" do
165
+ it "returns the value if button exists" do
166
+ browser.button(:index, 0).value.should == 'Submit'
167
+ browser.button(:index, 1).value.should == 'Reset'
168
+ browser.button(:index, 2).value.should == 'Button'
169
+ end
170
+
171
+ it "raises UnknownObjectException if button does not exist" do
172
+ lambda { browser.button(:name, "no_such_name").value }.should raise_error(UnknownObjectException)
173
+ end
174
+ end
175
+
176
+ describe "#respond_to?" do
177
+ it "returns true for all attribute methods" do
178
+ browser.button(:index, 0).should respond_to(:class_name)
179
+ browser.button(:index, 0).should respond_to(:id)
180
+ browser.button(:index, 0).should respond_to(:name)
181
+ browser.button(:index, 0).should respond_to(:src)
182
+ browser.button(:index, 0).should respond_to(:style)
183
+ browser.button(:index, 0).should respond_to(:title)
184
+ browser.button(:index, 0).should respond_to(:type)
185
+ browser.button(:index, 0).should respond_to(:value)
186
+ end
187
+ end
188
+
189
+ # Access methods
190
+ describe "#enabled?" do
191
+ it "returns true if the button is enabled" do
192
+ browser.button(:name, 'new_user_submit').should be_enabled
193
+ end
194
+
195
+ it "returns false if the button is disabled" do
196
+ browser.button(:name, 'new_user_submit_disabled').should_not be_enabled
197
+ end
198
+
199
+ it "raises UnknownObjectException if the button doesn't exist" do
200
+ lambda { browser.button(:name, "no_such_name").enabled? }.should raise_error(UnknownObjectException)
201
+ end
202
+ end
203
+
204
+ describe "#disabled?" do
205
+ it "returns false when button is enabled" do
206
+ browser.button(:name, 'new_user_submit').should_not be_disabled
207
+ end
208
+
209
+ it "returns true when button is disabled" do
210
+ browser.button(:name, 'new_user_submit_disabled').should be_disabled
211
+ end
212
+
213
+ it "raises UnknownObjectException if button does not exist" do
214
+ lambda { browser.button(:name, "no_such_name").disabled? }.should raise_error(UnknownObjectException)
215
+ end
216
+ end
217
+
218
+ # Manipulation methods
219
+ describe "#click" do
220
+ it "clicks the button if it exists" do
221
+ browser.goto(WatirSpec.host + "/forms_with_input_elements.html")
222
+ browser.button(:id, 'new_user_submit').click
223
+ browser.text.should include("You posted the following content:")
224
+ end
225
+
226
+ it "fires events" do
227
+ browser.button(:id, 'new_user_button').click
228
+ browser.button(:id, 'new_user_button').value.should == 'new_value_set_by_onclick_event'
229
+ end
230
+
231
+ it "raises UnknownObjectException when clicking a button that doesn't exist" do
232
+ lambda { browser.button(:value, "no_such_value").click }.should raise_error(UnknownObjectException)
233
+ lambda { browser.button(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
234
+ end
235
+
236
+ it "raises ObjectDisabledException when clicking a disabled button" do
237
+ lambda { browser.button(:value, "Disabled").click }.should raise_error(ObjectDisabledException)
238
+ end
239
+ end
240
+
241
+
242
+ end