celerity 0.0.3 → 0.0.4

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 (136) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +14 -0
  3. data/Manifest.txt +127 -151
  4. data/README.txt +15 -20
  5. data/lib/celerity.rb +13 -5
  6. data/lib/celerity/browser.rb +296 -0
  7. data/lib/celerity/clickable_element.rb +1 -0
  8. data/lib/celerity/collections.rb +4 -0
  9. data/lib/celerity/container.rb +69 -2
  10. data/lib/celerity/disabled_element.rb +1 -0
  11. data/lib/celerity/element.rb +103 -38
  12. data/lib/celerity/element_collections.rb +14 -8
  13. data/lib/celerity/element_locator.rb +61 -50
  14. data/lib/celerity/element_map.rb +51 -0
  15. data/lib/celerity/elements/button.rb +1 -0
  16. data/lib/celerity/elements/file_field.rb +3 -2
  17. data/lib/celerity/elements/form.rb +1 -0
  18. data/lib/celerity/elements/frame.rb +16 -1
  19. data/lib/celerity/elements/image.rb +15 -13
  20. data/lib/celerity/elements/link.rb +4 -1
  21. data/lib/celerity/elements/option.rb +1 -0
  22. data/lib/celerity/elements/radio_check.rb +19 -7
  23. data/lib/celerity/elements/select_list.rb +17 -2
  24. data/lib/celerity/elements/table.rb +34 -20
  25. data/lib/celerity/elements/table_body.rb +2 -2
  26. data/lib/celerity/elements/table_cell.rb +3 -1
  27. data/lib/celerity/elements/table_footer.rb +2 -2
  28. data/lib/celerity/elements/table_header.rb +2 -2
  29. data/lib/celerity/elements/table_row.rb +4 -2
  30. data/lib/celerity/elements/text_field.rb +20 -9
  31. data/lib/celerity/exception.rb +11 -18
  32. data/lib/celerity/extra/method_generator.rb +13 -8
  33. data/lib/celerity/htmlunit/download.sh +23 -0
  34. data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
  35. data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
  36. data/lib/celerity/htmlunit/{nekohtml-1.9.7.jar → nekohtml-1.9.8.jar} +0 -0
  37. data/lib/celerity/input_element.rb +1 -1
  38. data/lib/celerity/version.rb +1 -1
  39. data/lib/celerity/watir_compatibility.rb +37 -23
  40. data/spec/area_spec.rb +19 -4
  41. data/spec/areas_spec.rb +2 -3
  42. data/spec/{ie_spec.rb → browser_spec.rb} +66 -15
  43. data/spec/button_spec.rb +36 -3
  44. data/spec/buttons_spec.rb +2 -3
  45. data/spec/checkbox_spec.rb +43 -8
  46. data/spec/checkboxes_spec.rb +2 -3
  47. data/spec/div_spec.rb +31 -4
  48. data/spec/divs_spec.rb +2 -3
  49. data/spec/element_spec.rb +36 -6
  50. data/spec/filefield_spec.rb +28 -13
  51. data/spec/filefields_spec.rb +2 -3
  52. data/spec/form_spec.rb +6 -3
  53. data/spec/forms_spec.rb +2 -3
  54. data/spec/frame_spec.rb +14 -5
  55. data/spec/frames_spec.rb +71 -0
  56. data/spec/hidden_spec.rb +21 -3
  57. data/spec/hiddens_spec.rb +2 -3
  58. data/spec/hn_spec.rb +30 -12
  59. data/spec/hns_spec.rb +14 -10
  60. data/spec/html/form_js_bug.html +11 -0
  61. data/spec/html/forms_with_input_elements.html +2 -1
  62. data/spec/html/invalid_js.html +11 -0
  63. data/spec/html/latin1_text.html +1 -0
  64. data/spec/html/non_control_elements.html +8 -4
  65. data/spec/html/simple_ajax.html +22 -0
  66. data/spec/htmlunit_spec.rb +4 -5
  67. data/spec/image_spec.rb +33 -3
  68. data/spec/images_spec.rb +2 -3
  69. data/spec/label_spec.rb +16 -3
  70. data/spec/labels_spec.rb +2 -3
  71. data/spec/li_spec.rb +25 -3
  72. data/spec/link_spec.rb +35 -3
  73. data/spec/links_spec.rb +2 -3
  74. data/spec/lis_spec.rb +2 -3
  75. data/spec/map_spec.rb +19 -3
  76. data/spec/maps_spec.rb +2 -3
  77. data/spec/meta_spec.rb +3 -1
  78. data/spec/ol_spec.rb +17 -3
  79. data/spec/ols_spec.rb +2 -3
  80. data/spec/option_spec.rb +28 -3
  81. data/spec/p_spec.rb +30 -2
  82. data/spec/pre_spec.rb +25 -3
  83. data/spec/pres_spec.rb +2 -3
  84. data/spec/ps_spec.rb +2 -3
  85. data/spec/radio_spec.rb +47 -3
  86. data/spec/radios_spec.rb +2 -3
  87. data/spec/select_list_spec.rb +42 -3
  88. data/spec/select_lists_spec.rb +2 -3
  89. data/spec/span_spec.rb +32 -7
  90. data/spec/spans_spec.rb +2 -4
  91. data/spec/spec_helper.rb +5 -25
  92. data/spec/table_bodies_spec.rb +7 -5
  93. data/spec/table_body_spec.rb +11 -4
  94. data/spec/table_cell_spec.rb +15 -4
  95. data/spec/table_cells_spec.rb +3 -4
  96. data/spec/table_footer_spec.rb +11 -4
  97. data/spec/table_footers_spec.rb +7 -5
  98. data/spec/table_header_spec.rb +11 -4
  99. data/spec/table_headers_spec.rb +7 -5
  100. data/spec/table_row_spec.rb +31 -7
  101. data/spec/table_rows_spec.rb +5 -4
  102. data/spec/table_spec.rb +36 -7
  103. data/spec/tables_spec.rb +2 -3
  104. data/spec/text_field_spec.rb +51 -13
  105. data/spec/text_fields_spec.rb +2 -3
  106. data/spec/ul_spec.rb +18 -3
  107. data/spec/uls_spec.rb +2 -3
  108. data/spec/{watir_compatability_spec.rb → watir_compatibility_spec.rb} +42 -35
  109. data/support/spec_server.rb +9 -0
  110. metadata +167 -161
  111. metadata.gz.sig +0 -0
  112. data/benchmark/bm_2000_spans.rb +0 -48
  113. data/benchmark/bm_digg.rb +0 -26
  114. data/benchmark/bm_google_images.rb +0 -36
  115. data/benchmark/bm_input_locator.rb +0 -69
  116. data/benchmark/loader.rb +0 -9
  117. data/config/hoe.rb +0 -68
  118. data/config/requirements.rb +0 -15
  119. data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
  120. data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
  121. data/lib/celerity/ie.rb +0 -195
  122. data/setup.rb +0 -1583
  123. data/support/celerity_viewer/rubycocoa/CelerityViewer.icns +0 -0
  124. data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/classes.nib +0 -37
  125. data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/info.nib +0 -19
  126. data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/keyedobjects.nib +0 -0
  127. data/support/celerity_viewer/rubycocoa/Info.plist.erb +0 -28
  128. data/support/celerity_viewer/rubycocoa/MainController.rb +0 -23
  129. data/support/celerity_viewer/rubycocoa/README +0 -94
  130. data/support/celerity_viewer/rubycocoa/Rakefile +0 -100
  131. data/support/celerity_viewer/rubycocoa/distributed_viewer.rb +0 -86
  132. data/support/celerity_viewer/rubycocoa/main.m +0 -7
  133. data/support/celerity_viewer/rubycocoa/main.rb +0 -27
  134. data/tasks/benchmark.rake +0 -4
  135. data/tasks/environment.rake +0 -7
  136. data/tasks/simple_ci.rake +0 -94
@@ -17,7 +17,7 @@ module Celerity
17
17
  def assert_not_readonly
18
18
  if readonly?
19
19
  raise ObjectReadOnlyException,
20
- "Textfield #{@how.inspect} and #{@what.inspect} is read only."
20
+ "InputElement #{identifier_string()} is read only."
21
21
  end
22
22
  end
23
23
 
@@ -2,7 +2,7 @@ module Celerity #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,62 +1,76 @@
1
1
  module Celerity
2
- class IE
3
- # these are just for Watir compatability - should we keep them?
2
+ class Browser
4
3
  class << self
4
+ # added for Watir compatability - not in use by Celerity
5
5
  attr_accessor :speed, :attach_timeout, :visible
6
+ # added for Watir compatability - not in use by Celerity
6
7
  alias_method :start_window, :start
8
+ # added for Watir compatability - not in use by Celerity
7
9
  def reset_attach_timeout; @attach_timeout = 2.0; end
10
+ # added for Watir compatability - not in use by Celerity
8
11
  def each; end
12
+ # added for Watir compatability - not in use by Celerity
9
13
  def quit; end
14
+ # added for Watir compatability - not in use by Celerity
10
15
  def set_fast_speed; @speed = :fast; end
16
+ # added for Watir compatability - not in use by Celerity
11
17
  def set_slow_speed; @speed = :slow; end
12
18
  end
13
19
 
20
+ # added for Watir compatability - not in use by Celerity
14
21
  attr_accessor :visible
15
22
 
23
+ # added for Watir compatability - not in use by Celerity
16
24
  def bring_to_front; true; end
17
- def speed=(s); end
25
+ # added for Watir compatability - not in use by Celerity
26
+ def speed=(s); s end
27
+ # added for Watir compatability - not in use by Celerity
18
28
  def wait; end
19
29
  end
20
30
 
21
31
 
22
32
  module ClickableElement
23
- alias_method :click_no_wait, :click
33
+ alias_method :click_no_wait, :click
24
34
  end
25
35
 
26
36
  module Container
27
- alias_method :checkbox, :check_box
28
- alias_method :checkBox, :check_box
29
- alias_method :body, :tbody
30
- alias_method :bodies, :tbodies
37
+ alias_method :checkbox, :check_box
38
+ alias_method :checkBox, :check_box
39
+ alias_method :body, :tbody
40
+ alias_method :bodies, :tbodies
31
41
  end
32
42
 
33
43
  class Image
34
- alias_method :hasLoaded?, :loaded?
35
- alias_method :has_loaded?, :loaded?
36
- alias_method :fileSize, :file_size
37
- alias_method :fileCreatedDate, :file_created_date
44
+ alias_method :hasLoaded?, :loaded?
45
+ alias_method :has_loaded?, :loaded?
46
+ alias_method :fileSize, :file_size
47
+ alias_method :fileCreatedDate, :file_created_date
38
48
  end
39
49
 
40
50
  class Link
41
- alias_method :click_no_wait, :click
51
+ alias_method :click_no_wait, :click
42
52
  end
43
53
 
44
54
  class RadioCheckCommon
45
- alias_method :is_set?, :set?
46
- alias_method :get_state, :set?
47
- alias_method :isSet?, :set?
48
- alias_method :getState, :set?
55
+ alias_method :is_set?, :set?
56
+ alias_method :get_state, :set?
57
+ alias_method :isSet?, :set?
58
+ alias_method :getState, :set?
49
59
  end
50
60
 
51
61
  class SelectList
52
62
  alias_method :getSelectedItems, :get_selected_items
53
- alias_method :getAllContents, :get_all_contents
54
- alias_method :clearSelection, :clear_selection
55
- alias_method :select_value, :select
63
+ alias_method :getAllContents, :get_all_contents
64
+ alias_method :clearSelection, :clear_selection
65
+ alias_method :select_value, :select
66
+ alias_method :includes?, :include?
56
67
  end
57
68
 
58
69
  class TextField
59
- alias_method :dragContentsTo, :drag_contents_to
60
- alias_method :getContents, :get_contents
70
+ alias_method :dragContentsTo, :drag_contents_to
71
+ alias_method :getContents, :value
72
+ alias_method :get_contents, :value
61
73
  end
62
- end
74
+ end
75
+
76
+ Celerity::IE = Celerity::Browser
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe Area do
3
+ describe "Area" do
4
4
 
5
5
  before :all do
6
- @browser = IE.new
7
- add_spec_checker(@browser)
6
+ @browser = Browser.new
8
7
  end
9
8
 
10
9
  before :each do
@@ -25,9 +24,11 @@ describe Area do
25
24
  @browser.area(:index, 1).should exist
26
25
  @browser.area(:xpath, "//area[@id='NCE']").should exist
27
26
  end
27
+
28
28
  it "should return true if the element exists (default how = :id)" do
29
29
  @browser.area("NCE").should exist
30
30
  end
31
+
31
32
  it "should return false if the area doesn't exist" do
32
33
  @browser.area(:id, "no_such_id").should_not exist
33
34
  @browser.area(:id, /no_such_id/).should_not exist
@@ -40,9 +41,11 @@ describe Area do
40
41
  @browser.area(:index, 1337).should_not exist
41
42
  @browser.area(:xpath, "//area[@id='no_such_id']").should_not exist
42
43
  end
44
+
43
45
  it "should raise ArgumentError when 'what' argument is invalid" do
44
46
  lambda { @browser.area(:id, 3.14).exists? }.should raise_error(ArgumentError)
45
47
  end
48
+
46
49
  it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
47
50
  lambda { @browser.area(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
48
51
  end
@@ -53,28 +56,40 @@ describe Area do
53
56
  it "should return the id attribute" do
54
57
  @browser.area(:index, 1).id.should == "NCE"
55
58
  end
59
+
56
60
  it "should return an empty string if the element exists and the attribute doesn't" do
57
61
  @browser.area(:index, 3).id.should == ''
58
62
  end
63
+
59
64
  it "should raise UnknownObjectException if the area doesn't exist" do
60
65
  lambda { @browser.area(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
61
66
  lambda { @browser.area(:index, 1337).id }.should raise_error(UnknownObjectException)
62
67
  end
68
+
63
69
  end
64
70
 
65
71
  describe "#name" do
66
72
  it "should return the name attribute" do
67
73
  @browser.area(:index, 1).name.should == "NCE"
68
74
  end
75
+
69
76
  it "should return an empty string if the element exists and the attribute doesn't" do
70
77
  @browser.area(:index, 3).name.should == ''
71
78
  end
79
+
72
80
  it "should raise UnknownObjectException if the area doesn't exist" do
73
81
  lambda { @browser.area(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
74
82
  lambda { @browser.area(:index, 1337).name }.should raise_error(UnknownObjectException)
75
83
  end
76
84
  end
77
-
85
+
86
+ describe "#respond_to?" do
87
+ it "should return true for all attribute methods" do
88
+ @browser.area(:index, 1).should respond_to(:id)
89
+ @browser.area(:index, 1).should respond_to(:name)
90
+ end
91
+ end
92
+
78
93
  after :all do
79
94
  @browser.close
80
95
  end
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe Areas do
3
+ describe "Areas" do
4
4
 
5
5
  before :all do
6
- @browser = IE.new
7
- add_spec_checker(@browser)
6
+ @browser = Browser.new
8
7
  end
9
8
 
10
9
  before :each do
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe IE do
3
+ describe "Browser" do
4
4
 
5
5
  before :all do
6
- @browser = IE.new
7
- add_spec_checker(@browser)
6
+ @browser = Browser.new
8
7
  end
9
8
 
10
9
  # Exists
@@ -14,6 +13,7 @@ describe IE do
14
13
  @browser.goto(TEST_HOST + "/non_control_elements.html")
15
14
  @browser.should exist
16
15
  end
16
+
17
17
  it "should return false after IE#close" do
18
18
  @browser.close
19
19
  @browser.should_not exist
@@ -39,18 +39,54 @@ describe IE do
39
39
  @browser.goto(TEST_HOST + "/non_control_elements.html")
40
40
  @browser.text.should include("Dubito, ergo cogito, ergo sum.")
41
41
  end
42
+
42
43
  it "should return the text also if the content-type is text/plain" do
43
44
  # more specs for text/plain? what happens if we call other methods?
44
45
  @browser.goto(TEST_HOST + "/plain_text")
45
46
  @browser.text.strip.should == 'This is text/plain'
46
47
  end
47
- it "should return text in the correct charset (utf-8)" do
48
- @browser.goto(TEST_HOST + "/utf8_text.html")
49
- @browser.text.strip.should == "\303\246\303\245\303\270"
50
- end
51
- it "should return text in the correct charset (latin-1)" do
52
- @browser.goto(TEST_HOST + "/latin1_text.html")
53
- @browser.text.strip.should == "\370\345\346"
48
+
49
+ it "should return a text representation including newlines" do
50
+ @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
51
+ @browser.text.should == <<-TEXT
52
+ Forms with input elementsUser administration
53
+
54
+ Add user
55
+
56
+ Personal informationFirst name
57
+
58
+ Last name
59
+
60
+ Email address
61
+
62
+ Country Denmark Norway Sweden United Kingdom USA
63
+
64
+ Occupation
65
+
66
+ Species
67
+
68
+ Personal code
69
+
70
+ Languages Danish English Norwegian Swedish
71
+
72
+ Portrait
73
+
74
+ Dental records Login informationUsername (max 20 characters) 0
75
+
76
+ Password
77
+
78
+ Role Administrator Moderator Regular user Interests Books Bowling Cars Dancing Dentistry Food Preferences
79
+
80
+ Do you want to recieve our newslettter?
81
+
82
+ Yes No Certainly Absolutely Nah Actions Button 2
83
+
84
+ Delete user
85
+
86
+ Username Username 1 Username 2 Username 3
87
+
88
+ Comment Default comment.
89
+ TEXT
54
90
  end
55
91
  end
56
92
 
@@ -73,8 +109,8 @@ describe IE do
73
109
  end
74
110
 
75
111
  # Show methods
76
- describe "#method_missing" do
77
- it "should return all div elements on the page in a human readable format" do
112
+ describe "#show_«collection»" do
113
+ it "should print a human readable representation of elements matching the given name" do
78
114
  @browser.goto(TEST_HOST + "/non_control_elements.html")
79
115
  temp_stdout = StringIO.new
80
116
  old_stdout = $stdout
@@ -96,6 +132,7 @@ describe IE do
96
132
  8: id="footer" title="Closing remarks" class="profile"
97
133
  '
98
134
  end
135
+
99
136
  it "should raise NoMethodError if the collection does not exist" do
100
137
  @browser.goto(TEST_HOST + "/non_control_elements.html")
101
138
  lambda { @browser.show_no_such_collection }.should raise_error(NoMethodError)
@@ -105,8 +142,8 @@ describe IE do
105
142
  # Manipulation methods
106
143
  describe ".start" do
107
144
  it "should go to the given URL and return an instance of itself" do
108
- @browser = Celerity::IE.start(TEST_HOST + "/non_control_elements.html")
109
- @browser.should be_instance_of(Celerity::IE)
145
+ @browser = Browser.start(TEST_HOST + "/non_control_elements.html")
146
+ @browser.should be_instance_of(Browser)
110
147
  @browser.title.should == "Non-control elements"
111
148
  end
112
149
  end
@@ -116,6 +153,14 @@ describe IE do
116
153
  # it "should handle HTTPS" do
117
154
  # pending
118
155
  # end
156
+
157
+ it "should add http:// to URLs with no protocol specified" do
158
+ url = TEST_HOST[%r{http://(.*)}, 1]
159
+ url.should_not be_nil
160
+ @browser.goto(url)
161
+ @browser.url.should == "http://#{url}"
162
+ end
163
+
119
164
  it "should go to the given url without raising errors" do
120
165
  lambda { @browser.goto(TEST_HOST + "/non_control_elements.html") }.should_not raise_error
121
166
  end
@@ -157,21 +202,25 @@ describe IE do
157
202
  before :each do
158
203
  @browser.goto(TEST_HOST + "/non_control_elements.html")
159
204
  end
205
+
160
206
  it "should raise ArgumentError when called with no or wrong arguments" do
161
207
  lambda { @browser.contains_text }.should raise_error(ArgumentError)
162
208
  lambda { @browser.contains_text(nil) }.should raise_error(ArgumentError)
163
209
  lambda { @browser.contains_text(42) }.should raise_error(ArgumentError)
164
210
  end
211
+
165
212
  it "should return the index if the given text exists" do
166
213
  @browser.contains_text('Dubito, ergo cogito, ergo sum.').should be_instance_of(Fixnum)
167
214
  @browser.contains_text(/Dubito.*sum./).should_not be_nil
168
215
  end
216
+
169
217
  it "should return nil if the text doesn't exist" do
170
218
  @browser.contains_text('no_such_text').should be_nil
171
219
  @browser.contains_text(/no_such_text/).should be_nil
172
220
  end
221
+
173
222
  it "should not raise error on a blank page" do
174
- @browser = IE.new
223
+ @browser = Browser.new
175
224
  lambda { @browser.contains_text('') }.should_not raise_error
176
225
  end
177
226
  end
@@ -180,6 +229,7 @@ describe IE do
180
229
  it "should raise ArgumentError when not given any arguments" do
181
230
  lambda { @browser.add_checker }.should raise_error(ArgumentError)
182
231
  end
232
+
183
233
  it "should run the given proc on each page load" do
184
234
  output = ''
185
235
  proc = Proc.new { |ie| output << ie.text }
@@ -187,6 +237,7 @@ describe IE do
187
237
  @browser.goto(TEST_HOST + "/non_control_elements.html")
188
238
  output.should include('Dubito, ergo cogito, ergo sum')
189
239
  end
240
+
190
241
  it "should run the given block on each page load" do
191
242
  output = ''
192
243
  @browser.add_checker { |ie| output << ie.text }
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe Button do
3
+ describe "Button" do
4
4
 
5
5
  before :all do
6
- @browser = IE.new
7
- add_spec_checker(@browser)
6
+ @browser = Browser.new
8
7
  end
9
8
 
10
9
  before :each do
@@ -29,13 +28,16 @@ describe Button do
29
28
  @browser.button(:index, 1).should exist
30
29
  @browser.button(:xpath, "//input[@id='new_user_submit']").should exist
31
30
  end
31
+
32
32
  it "should return true if the button exists (how = :caption)" do
33
33
  @browser.button(:caption, "Button 2").should exist
34
34
  @browser.button(:caption, /Button 2/).should exist
35
35
  end
36
+
36
37
  it "should return true if the button exists (default how = :value)" do
37
38
  @browser.button("Submit").should exist
38
39
  end
40
+
39
41
  it "should return false if the button doesn't exist" do
40
42
  @browser.button(:id, "no_such_id").should_not exist
41
43
  @browser.button(:id, /no_such_id/).should_not exist
@@ -52,9 +54,11 @@ describe Button do
52
54
  @browser.button(:index, 1337).should_not exist
53
55
  @browser.button(:xpath, "//input[@id='no_such_id']").should_not exist
54
56
  end
57
+
55
58
  it "should raise ArgumentError when 'what' argument is invalid" do
56
59
  lambda { @browser.button(:id, 3.14).exists? }.should raise_error(ArgumentError)
57
60
  end
61
+
58
62
  it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
59
63
  lambda { @browser.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
60
64
  end
@@ -65,6 +69,7 @@ describe Button do
65
69
  it "should return the class name of the button" do
66
70
  @browser.button(:name, "new_user_image").class_name.should == "image"
67
71
  end
72
+
68
73
  it "should return an empty string if the button has no class name" do
69
74
  @browser.button(:name, "new_user_submit").class_name.should == ""
70
75
  end
@@ -76,6 +81,7 @@ describe Button do
76
81
  @browser.button(:index, 2).id.should == 'new_user_reset'
77
82
  @browser.button(:index, 3).id.should == 'new_user_button'
78
83
  end
84
+
79
85
  it "should raise UnknownObjectException if button does not exist" do
80
86
  lambda { @browser.button(:index, 1337).id }.should raise_error(UnknownObjectException, 'Unable to locate object, using :index and 1337')
81
87
  end
@@ -87,6 +93,7 @@ describe Button do
87
93
  @browser.button(:index, 2).name.should == 'new_user_reset'
88
94
  @browser.button(:index, 3).name.should == 'new_user_button'
89
95
  end
96
+
90
97
  it "should raise UnknownObjectException if the button does not exist" do
91
98
  lambda { @browser.button(:name, "no_such_name").name }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
92
99
  end
@@ -96,6 +103,7 @@ describe Button do
96
103
  it "should return the url for the button image" do
97
104
  @browser.button(:name, "new_user_image").src.should == "images/button.jpg"
98
105
  end
106
+
99
107
  it "should raise UnknownObjectException if the button does not exist" do
100
108
  lambda { @browser.button(:name, "no_such_name").src }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
101
109
  end
@@ -105,9 +113,11 @@ describe Button do
105
113
  it "should return the style attribute if the button exists" do
106
114
  @browser.button(:id, 'delete_user_submit').style.should == "border: 4px solid red;"
107
115
  end
116
+
108
117
  it "should return an empty string if the element exists and the attribute doesn't" do
109
118
  @browser.button(:id, 'new_user_submit').style.should == ""
110
119
  end
120
+
111
121
  it "should raise UnknownObjectException if the button does not exist" do
112
122
  lambda { @browser.button(:name, "no_such_name").style }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
113
123
  end
@@ -117,6 +127,7 @@ describe Button do
117
127
  it "should return the title of the button" do
118
128
  @browser.button(:index, 1).title.should == 'Submit the form'
119
129
  end
130
+
120
131
  it "should return an empty string for button without title" do
121
132
  @browser.button(:index, 2).title.should == ''
122
133
  end
@@ -128,6 +139,7 @@ describe Button do
128
139
  @browser.button(:index, 2).type.should == 'reset'
129
140
  @browser.button(:index, 3).type.should == 'button'
130
141
  end
142
+
131
143
  it "should raise UnknownObjectException if button does not exist" do
132
144
  lambda { @browser.button(:name, "no_such_name").type }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
133
145
  end
@@ -139,19 +151,35 @@ describe Button do
139
151
  @browser.button(:index, 2).value.should == 'Reset'
140
152
  @browser.button(:index, 3).value.should == 'Button'
141
153
  end
154
+
142
155
  it "should raise UnknownObjectException if button does not exist" do
143
156
  lambda { @browser.button(:name, "no_such_name").value }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
144
157
  end
145
158
  end
159
+
160
+ describe "#respond_to?" do
161
+ it "should return true for all attribute methods" do
162
+ @browser.button(:index, 1).should respond_to(:class_name)
163
+ @browser.button(:index, 1).should respond_to(:id)
164
+ @browser.button(:index, 1).should respond_to(:name)
165
+ @browser.button(:index, 1).should respond_to(:src)
166
+ @browser.button(:index, 1).should respond_to(:style)
167
+ @browser.button(:index, 1).should respond_to(:title)
168
+ @browser.button(:index, 1).should respond_to(:type)
169
+ @browser.button(:index, 1).should respond_to(:value)
170
+ end
171
+ end
146
172
 
147
173
  # Access methods
148
174
  describe "#enabled?" do
149
175
  it "should return true if the button is enabled" do
150
176
  @browser.button(:name, 'new_user_submit').should be_enabled
151
177
  end
178
+
152
179
  it "should return false if the button is disabled" do
153
180
  @browser.button(:name, 'new_user_submit_disabled').should_not be_enabled
154
181
  end
182
+
155
183
  it "should raise UnknownObjectException if the button doesn't exist" do
156
184
  lambda { @browser.button(:name, "no_such_name").enabled? }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
157
185
  end
@@ -161,9 +189,11 @@ describe Button do
161
189
  it "should return false when button is enabled" do
162
190
  @browser.button(:name, 'new_user_submit').should_not be_disabled
163
191
  end
192
+
164
193
  it "should return true when button is disabled" do
165
194
  @browser.button(:name, 'new_user_submit_disabled').should be_disabled
166
195
  end
196
+
167
197
  it "should raise UnknownObjectException if button does not exist" do
168
198
  lambda { @browser.button(:name, "no_such_name").disabled? }.should raise_error(UnknownObjectException, 'Unable to locate object, using :name and "no_such_name"')
169
199
  end
@@ -175,14 +205,17 @@ describe Button do
175
205
  @browser.button(:id, 'new_user_submit').click
176
206
  @browser.text.should include("You posted the following content:")
177
207
  end
208
+
178
209
  it "should fire events" do
179
210
  @browser.button(:id, 'new_user_button').click
180
211
  @browser.button(:id, 'new_user_button').value.should == 'new_value_set_by_onclick_event'
181
212
  end
213
+
182
214
  it "should raise UnknownObjectException when clicking a button that doesn't exist" do
183
215
  lambda { @browser.button(:value, "no_such_value").click }.should raise_error(UnknownObjectException, 'Unable to locate object, using :value and "no_such_value"')
184
216
  lambda { @browser.button(:id, "no_such_id").click }.should raise_error(UnknownObjectException, 'Unable to locate object, using :id and "no_such_id"')
185
217
  end
218
+
186
219
  it "should raise ObjectDisabledException when clicking a disabled button" do
187
220
  lambda { @browser.button(:value, "Disabled").click }.should raise_error(ObjectDisabledException)
188
221
  end