celerity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +10 -0
  2. data/README.txt +8 -11
  3. data/Rakefile +5 -3
  4. data/benchmark/bm_2000_spans.rb +48 -0
  5. data/benchmark/bm_digg.rb +26 -0
  6. data/benchmark/bm_google_images.rb +36 -0
  7. data/benchmark/bm_input_locator.rb +69 -0
  8. data/benchmark/loader.rb +9 -0
  9. data/lib/celerity.rb +3 -1
  10. data/lib/celerity/container.rb +23 -171
  11. data/lib/celerity/disabled_element.rb +1 -1
  12. data/lib/celerity/element.rb +78 -47
  13. data/lib/celerity/element_collections.rb +16 -32
  14. data/lib/celerity/element_locator.rb +135 -0
  15. data/lib/celerity/elements/button.rb +15 -0
  16. data/lib/celerity/elements/file_field.rb +1 -1
  17. data/lib/celerity/elements/form.rb +2 -1
  18. data/lib/celerity/elements/frame.rb +18 -21
  19. data/lib/celerity/elements/image.rb +2 -8
  20. data/lib/celerity/elements/label.rb +1 -3
  21. data/lib/celerity/elements/link.rb +1 -1
  22. data/lib/celerity/elements/option.rb +16 -0
  23. data/lib/celerity/elements/radio_check.rb +18 -7
  24. data/lib/celerity/elements/select_list.rb +1 -17
  25. data/lib/celerity/elements/table.rb +4 -4
  26. data/lib/celerity/elements/table_body.rb +6 -8
  27. data/lib/celerity/elements/table_cell.rb +3 -14
  28. data/lib/celerity/elements/table_row.rb +4 -10
  29. data/lib/celerity/elements/text_field.rb +16 -4
  30. data/lib/celerity/extra/method_generator.rb +144 -0
  31. data/lib/celerity/identifier.rb +10 -0
  32. data/lib/celerity/ie.rb +28 -13
  33. data/lib/celerity/input_element.rb +0 -4
  34. data/lib/celerity/non_control_elements.rb +12 -12
  35. data/lib/celerity/version.rb +1 -1
  36. data/spec/area_spec.rb +41 -41
  37. data/spec/areas_spec.rb +11 -11
  38. data/spec/button_spec.rb +73 -68
  39. data/spec/buttons_spec.rb +10 -10
  40. data/spec/checkbox_spec.rb +102 -96
  41. data/spec/checkboxes_spec.rb +10 -10
  42. data/spec/div_spec.rb +78 -73
  43. data/spec/divs_spec.rb +10 -10
  44. data/spec/element_spec.rb +20 -11
  45. data/spec/filefield_spec.rb +36 -41
  46. data/spec/filefields_spec.rb +10 -10
  47. data/spec/form_spec.rb +29 -29
  48. data/spec/forms_spec.rb +11 -11
  49. data/spec/frame_spec.rb +54 -49
  50. data/spec/hidden_spec.rb +43 -43
  51. data/spec/hiddens_spec.rb +10 -10
  52. data/spec/html/2000_spans.html +2009 -0
  53. data/spec/html/forms_with_input_elements.html +15 -9
  54. data/spec/html/non_control_elements.html +4 -2
  55. data/spec/ie_spec.rb +82 -48
  56. data/spec/image_spec.rb +83 -100
  57. data/spec/images_spec.rb +10 -10
  58. data/spec/label_spec.rb +29 -29
  59. data/spec/labels_spec.rb +10 -10
  60. data/spec/li_spec.rb +41 -41
  61. data/spec/link_spec.rb +65 -59
  62. data/spec/links_spec.rb +11 -11
  63. data/spec/lis_spec.rb +10 -10
  64. data/spec/map_spec.rb +30 -30
  65. data/spec/maps_spec.rb +10 -10
  66. data/spec/p_spec.rb +49 -49
  67. data/spec/pre_spec.rb +41 -41
  68. data/spec/pres_spec.rb +10 -10
  69. data/spec/ps_spec.rb +10 -10
  70. data/spec/radio_spec.rb +104 -97
  71. data/spec/radios_spec.rb +11 -11
  72. data/spec/select_list_spec.rb +118 -106
  73. data/spec/select_lists_spec.rb +15 -15
  74. data/spec/span_spec.rb +54 -54
  75. data/spec/spans_spec.rb +11 -11
  76. data/spec/spec.opts +1 -1
  77. data/spec/spec_helper.rb +23 -3
  78. data/spec/table_bodies.rb +8 -8
  79. data/spec/table_bodies_spec.rb +9 -9
  80. data/spec/table_body_spec.rb +28 -27
  81. data/spec/table_cell_spec.rb +25 -25
  82. data/spec/table_cells_spec.rb +16 -16
  83. data/spec/table_row_spec.rb +16 -16
  84. data/spec/table_rows_spec.rb +12 -12
  85. data/spec/table_spec.rb +36 -36
  86. data/spec/tables_spec.rb +12 -12
  87. data/spec/text_field_spec.rb +111 -92
  88. data/spec/text_fields_spec.rb +13 -13
  89. data/tasks/benchmark.rake +3 -0
  90. data/tasks/rspec.rake +2 -2
  91. data/tasks/testserver.rake +15 -0
  92. metadata +58 -46
  93. data/tasks/simple_ci.rake +0 -94
data/spec/radios_spec.rb CHANGED
@@ -3,41 +3,41 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "Radios" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
11
+ @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
12
12
  end
13
13
 
14
14
  describe "#length" do
15
15
  it "should return the number of radios" do
16
- @ie.radios.length.should == 5
16
+ @browser.radios.length.should == 5
17
17
  end
18
18
  end
19
19
 
20
20
  describe "#[]" do
21
21
  it "should return the radio button at the given index" do
22
- @ie.radios[1].id.should == "new_user_newsletter_yes"
22
+ @browser.radios[1].id.should == "new_user_newsletter_yes"
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#each" do
27
27
  it "should iterate through radio buttons correctly" do
28
28
  index = 1
29
- @ie.radios.each do |r|
30
- r.name.should == @ie.radio(:index, index).name
31
- r.id.should == @ie.radio(:index, index).id
32
- r.value.should == @ie.radio(:index, index).value
29
+ @browser.radios.each do |r|
30
+ r.name.should == @browser.radio(:index, index).name
31
+ r.id.should == @browser.radio(:index, index).id
32
+ r.value.should == @browser.radio(:index, index).value
33
33
  index += 1
34
34
  end
35
- @ie.radios.length.should == index - 1
35
+ @browser.radios.length.should == index - 1
36
36
  end
37
37
  end
38
38
 
39
39
  after :all do
40
- @ie.close
40
+ @browser.close
41
41
  end
42
42
 
43
43
  end
@@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe "SelectList" do
4
4
  before :all do
5
- @ie = Celerity::IE.new
6
- add_spec_checker(@ie)
5
+ @browser = Celerity::IE.new
6
+ add_spec_checker(@browser)
7
7
  end
8
8
 
9
9
  before :each do
10
- @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
10
+ @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
11
11
  end
12
12
 
13
13
 
@@ -15,44 +15,44 @@ describe "SelectList" do
15
15
 
16
16
  describe "#exists?" do
17
17
  it "should return true if the select list exists" do
18
- @ie.select_list(:id, 'new_user_country').should exist
19
- @ie.select_list(:id, /new_user_country/).should exist
20
- @ie.select_list(:name, 'new_user_country').should exist
21
- @ie.select_list(:name, /new_user_country/).should exist
18
+ @browser.select_list(:id, 'new_user_country').should exist
19
+ @browser.select_list(:id, /new_user_country/).should exist
20
+ @browser.select_list(:name, 'new_user_country').should exist
21
+ @browser.select_list(:name, /new_user_country/).should exist
22
22
 
23
23
  # check behaviour in Watir
24
- # @ie.select_list(:value, 'Norway').should exist
25
- # @ie.select_list(:value, /Norway/).should exist
24
+ # @browser.select_list(:value, 'Norway').should exist
25
+ # @browser.select_list(:value, /Norway/).should exist
26
26
 
27
27
  # not sure what :text is for input elements
28
- # @ie.select_list(:text, 'Norway').should exist
29
- # @ie.select_list(:text, /Norway/).should exist
30
- @ie.select_list(:class, 'country').should exist
31
- @ie.select_list(:class, /country/).should exist
32
- @ie.select_list(:index, 1).should exist
33
- @ie.select_list(:xpath, "//select[@id='new_user_country']").should exist
28
+ # @browser.select_list(:text, 'Norway').should exist
29
+ # @browser.select_list(:text, /Norway/).should exist
30
+ @browser.select_list(:class, 'country').should exist
31
+ @browser.select_list(:class, /country/).should exist
32
+ @browser.select_list(:index, 1).should exist
33
+ @browser.select_list(:xpath, "//select[@id='new_user_country']").should exist
34
34
  end
35
35
  it "should return false if the select list doesn't exist" do
36
- @ie.select_list(:id, 'no_such_id').should_not exist
37
- @ie.select_list(:id, /no_such_id/).should_not exist
38
- @ie.select_list(:name, 'no_such_name').should_not exist
39
- @ie.select_list(:name, /no_such_name/).should_not exist
40
- @ie.select_list(:value, 'no_such_value').should_not exist
41
- @ie.select_list(:value, /no_such_value/).should_not exist
42
- @ie.select_list(:text, 'no_such_text').should_not exist
43
- @ie.select_list(:text, /no_such_text/).should_not exist
44
- @ie.select_list(:class, 'no_such_class').should_not exist
45
- @ie.select_list(:class, /no_such_class/).should_not exist
46
- @ie.select_list(:index, 1337).should_not exist
47
- @ie.select_list(:xpath, "//select[@id='no_such_id']").should_not exist
36
+ @browser.select_list(:id, 'no_such_id').should_not exist
37
+ @browser.select_list(:id, /no_such_id/).should_not exist
38
+ @browser.select_list(:name, 'no_such_name').should_not exist
39
+ @browser.select_list(:name, /no_such_name/).should_not exist
40
+ @browser.select_list(:value, 'no_such_value').should_not exist
41
+ @browser.select_list(:value, /no_such_value/).should_not exist
42
+ @browser.select_list(:text, 'no_such_text').should_not exist
43
+ @browser.select_list(:text, /no_such_text/).should_not exist
44
+ @browser.select_list(:class, 'no_such_class').should_not exist
45
+ @browser.select_list(:class, /no_such_class/).should_not exist
46
+ @browser.select_list(:index, 1337).should_not exist
47
+ @browser.select_list(:xpath, "//select[@id='no_such_id']").should_not exist
48
48
  end
49
49
 
50
- it "should raise ArgumentError when what argument is invalid" do
51
- lambda { @ie.select_list(:id, 3.14).exists? }.should raise_error(ArgumentError)
50
+ it "should raise ArgumentError when 'what' argument is invalid" do
51
+ lambda { @browser.select_list(:id, 3.14).exists? }.should raise_error(ArgumentError)
52
52
  end
53
53
 
54
- it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
55
- lambda { @ie.select_list(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
54
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
55
+ lambda { @browser.select_list(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
56
56
  end
57
57
  end
58
58
 
@@ -61,53 +61,49 @@ describe "SelectList" do
61
61
 
62
62
  describe "#class_name" do
63
63
  it "should return the class name of the select list" do
64
- @ie.select_list(:name, 'new_user_country').class_name.should == 'country'
64
+ @browser.select_list(:name, 'new_user_country').class_name.should == 'country'
65
65
  end
66
66
  it "should raise UnknownObjectException if the select list doesn't exist" do
67
- lambda { @ie.select_list(:name, 'no_such_name').class_name }.should raise_error(UnknownObjectException)
67
+ lambda { @browser.select_list(:name, 'no_such_name').class_name }.should raise_error(UnknownObjectException)
68
68
  end
69
69
  end
70
70
 
71
71
  describe "#id" do
72
72
  it "should return the id of the element" do
73
- @ie.select_list(:index, 1).id.should == "new_user_country"
73
+ @browser.select_list(:index, 1).id.should == "new_user_country"
74
74
  end
75
75
  it "should raise UnknownObjectException if the select list doesn't exist" do
76
- lambda { @ie.select_list(:index, 1337).id }.should raise_error(UnknownObjectException)
76
+ lambda { @browser.select_list(:index, 1337).id }.should raise_error(UnknownObjectException)
77
77
  end
78
78
  end
79
79
 
80
80
  describe "#name" do
81
81
  it "should return the name of the element" do
82
- @ie.select_list(:index, 1).name.should == "new_user_country"
82
+ @browser.select_list(:index, 1).name.should == "new_user_country"
83
83
  end
84
84
  it "should raise UnknownObjectException if the select list doesn't exist" do
85
- lambda { @ie.select_list(:index, 1337).name }.should raise_error(UnknownObjectException)
85
+ lambda { @browser.select_list(:index, 1337).name }.should raise_error(UnknownObjectException)
86
86
  end
87
87
  end
88
88
 
89
- it "should should raise UnknownObjectException when the select list does not exist" do
90
- lambda { @ie.select_list(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
91
- end
92
-
93
89
  describe "#type" do
94
90
  it "should return the type of the element" do
95
- @ie.select_list(:index, 1).type.should == "select-one"
96
- @ie.select_list(:index, 2).type.should == "select-multiple"
91
+ @browser.select_list(:index, 1).type.should == "select-one"
92
+ @browser.select_list(:index, 2).type.should == "select-multiple"
97
93
  end
98
94
  it "should raise UnknownObjectException if the select list doesn't exist" do
99
- lambda { @ie.select_list(:index, 1337).type }.should raise_error(UnknownObjectException)
95
+ lambda { @browser.select_list(:index, 1337).type }.should raise_error(UnknownObjectException)
100
96
  end
101
97
  end
102
98
 
103
99
  describe "#value" do
104
100
  it "should return the value of the selected option" do
105
- @ie.select_list(:index, 1).value.should == "Norway"
106
- @ie.select_list(:index, 1).select(/Sweden/)
107
- @ie.select_list(:index, 1).value.should == "Sweden"
101
+ @browser.select_list(:index, 1).value.should == "Norway"
102
+ @browser.select_list(:index, 1).select(/Sweden/)
103
+ @browser.select_list(:index, 1).value.should == "Sweden"
108
104
  end
109
105
  it "should raise UnknownObjectException if the select list doesn't exist" do
110
- lambda { @ie.select_list(:index, 1337).value }.should raise_error(UnknownObjectException)
106
+ lambda { @browser.select_list(:index, 1337).value }.should raise_error(UnknownObjectException)
111
107
  end
112
108
  end
113
109
 
@@ -116,22 +112,26 @@ describe "SelectList" do
116
112
 
117
113
  describe "#enabled?" do
118
114
  it "should return true if the select list is enabled" do
119
- @ie.select_list(:name, 'new_user_country').should be_enabled
115
+ @browser.select_list(:name, 'new_user_country').should be_enabled
120
116
  end
121
117
  it "should return false if the select list is disabled" do
122
- @ie.select_list(:name, 'new_user_role').should_not be_enabled
118
+ @browser.select_list(:name, 'new_user_role').should_not be_enabled
123
119
  end
124
120
  it "should raise UnknownObjectException if the select_list doesn't exist" do
125
- lambda { @ie.select_list(:name, 'no_such_name').enabled? }.should raise_error(UnknownObjectException)
121
+ lambda { @browser.select_list(:name, 'no_such_name').enabled? }.should raise_error(UnknownObjectException)
126
122
  end
127
123
  end
128
124
 
129
125
  describe "#disabled?" do
130
126
  it "should return true if the select list is disabled" do
131
- @ie.select_list(:index, 3).should be_disabled
127
+ @browser.select_list(:index, 3).should be_disabled
132
128
  end
133
129
  it "should return false if the select list is enabled" do
134
- @ie.select_list(:index, 1).should_not be_disabled
130
+ @browser.select_list(:index, 1).should_not be_disabled
131
+ end
132
+
133
+ it "should should raise UnknownObjectException when the select list does not exist" do
134
+ lambda { @browser.select_list(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
135
135
  end
136
136
  end
137
137
 
@@ -140,146 +140,158 @@ describe "SelectList" do
140
140
 
141
141
  describe "#option" do
142
142
  it "should return an instance of Option" do
143
- @ie.select_list(:name, "new_user_country").option(:text, "Denmark").should be_instance_of(Celerity::Option)
143
+ @browser.select_list(:name, "new_user_country").option(:text, "Denmark").should be_instance_of(Celerity::Option)
144
144
  end
145
145
 
146
146
  # do we need a seperate spec for this object?
147
147
  it "should should be able to select the chosen option" do
148
- @ie.select_list(:name , "new_user_country").clear_selection
149
- @ie.select_list(:name , "new_user_country").option(:text, "Denmark").select
150
- @ie.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
148
+ @browser.select_list(:name , "new_user_country").clear_selection
149
+ @browser.select_list(:name , "new_user_country").option(:text, "Denmark").select
150
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
151
151
  end
152
152
 
153
153
  it "should select the option when found by text" do
154
- @ie.select_list(:name, 'new_user_country').option(:text, 'Sweden').select
155
- @ie.select_list(:name, 'new_user_country').option(:text, 'Sweden').should be_selected
154
+ @browser.select_list(:name, 'new_user_country').option(:text, 'Sweden').select
155
+ @browser.select_list(:name, 'new_user_country').option(:text, 'Sweden').should be_selected
156
156
  end
157
157
 
158
158
  it "should raise UnknownObjectException if the option does not exist" do
159
- lambda { @ie.select_list(:name, "new_user_country").option(:text, "no_such_text").select }.should raise_error(UnknownObjectException)
160
- lambda { @ie.select_list(:name, "new_user_country").option(:text, /missing/).select }.should raise_error(UnknownObjectException)
159
+ lambda { @browser.select_list(:name, "new_user_country").option(:text, "no_such_text").select }.should raise_error(UnknownObjectException)
160
+ lambda { @browser.select_list(:name, "new_user_country").option(:text, /missing/).select }.should raise_error(UnknownObjectException)
161
161
  end
162
162
 
163
163
  it "should raise MissingWayOfFindingObjectException when given a bad 'how'" do
164
- lambda { @ie.select_list(:name, "new_user_country").option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
164
+ lambda { @browser.select_list(:name, "new_user_country").option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
165
165
  end
166
166
 
167
167
  it "should be able to get attributes" do
168
- @ie.select_list(:name, "new_user_country").option(:text , 'Sweden').class_name.should == "scandinavia"
169
- lambda { @ie.select_list(:name, "new_user_country").option(:text, "no_such_text").class_name }.should raise_error(UnknownObjectException)
168
+ @browser.select_list(:name, "new_user_country").option(:text , 'Sweden').class_name.should == "scandinavia"
170
169
  end
171
170
  end
172
171
 
173
172
  describe "#get_all_contents" do
174
173
  it "should should raise UnknownObjectException if the select list doesn't exist" do
175
- lambda { @ie.select_list(:name, 'no_such_name').get_all_contents }.should raise_error(UnknownObjectException)
174
+ lambda { @browser.select_list(:name, 'no_such_name').get_all_contents }.should raise_error(UnknownObjectException)
176
175
  end
177
176
  it "should return all the options as an Array" do
178
- @ie.select_list(:name, "new_user_country").get_all_contents.should == ["Denmark" ,"Norway" , "Sweden" , "United Kingdom", "USA"]
177
+ @browser.select_list(:name, "new_user_country").get_all_contents.should == ["Denmark" ,"Norway" , "Sweden" , "United Kingdom", "USA"]
179
178
  end
180
179
  end
181
180
 
182
181
  describe "#get_selected_items" do
183
182
  it "should should raise UnknownObjectException if the select list doesn't exist" do
184
- lambda { @ie.select_list(:name, 'no_such_name').get_selected_items }.should raise_error(UnknownObjectException)
183
+ lambda { @browser.select_list(:name, 'no_such_name').get_selected_items }.should raise_error(UnknownObjectException)
185
184
  end
186
185
 
187
186
  it "should get the currently selected item(s)" do
188
- @ie.select_list(:name, "new_user_country").get_selected_items.should == ["Norway"]
189
- @ie.select_list(:name, "new_user_languages").get_selected_items.should == ["English", "Norwegian"]
187
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Norway"]
188
+ @browser.select_list(:name, "new_user_languages").get_selected_items.should == ["English", "Norwegian"]
190
189
  end
191
190
  end
192
191
 
193
192
  describe "#clear_selection" do
194
193
  it "should clear the selection when possible" do
195
- @ie.select_list(:name, "new_user_languages").clear_selection
196
- @ie.select_list(:name, "new_user_languages").get_selected_items.should be_empty
194
+ @browser.select_list(:name, "new_user_languages").clear_selection
195
+ @browser.select_list(:name, "new_user_languages").get_selected_items.should be_empty
197
196
  end
198
197
  it "should not clear selections when not possible" do
199
- @ie.select_list(:name , "new_user_country").clear_selection
200
- @ie.select_list(:name, "new_user_country").get_selected_items.should == ["Norway"]
198
+ @browser.select_list(:name , "new_user_country").clear_selection
199
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Norway"]
201
200
  end
202
201
  it "should should raise UnknownObjectException if the select list doesn't exist" do
203
- lambda { @ie.select_list(:name, 'no_such_name').clear_selection }.should raise_error(UnknownObjectException)
202
+ lambda { @browser.select_list(:name, 'no_such_name').clear_selection }.should raise_error(UnknownObjectException)
204
203
  end
205
204
  end
206
205
 
207
206
  describe "#includes?" do
208
207
  it "should return true if the given option exists" do
209
- @ie.select_list(:name, 'new_user_country').includes?('Denmark').should be_true
208
+ @browser.select_list(:name, 'new_user_country').includes?('Denmark').should be_true
210
209
  end
211
210
  it "should return false if the given option doesn't exist" do
212
- @ie.select_list(:name, 'new_user_country').includes?('Ireland').should be_false
211
+ @browser.select_list(:name, 'new_user_country').includes?('Ireland').should be_false
213
212
  end
214
213
  end
215
214
 
216
215
  describe "#selected?" do
217
216
  it "should return true if the given option is selected" do
218
- @ie.select_list(:name, 'new_user_country').select('Denmark')
219
- @ie.select_list(:name, 'new_user_country').selected?('Denmark').should be_true
217
+ @browser.select_list(:name, 'new_user_country').select('Denmark')
218
+ @browser.select_list(:name, 'new_user_country').selected?('Denmark').should be_true
220
219
  end
221
220
  it "should return false if the given option is not selected" do
222
- @ie.select_list(:name, 'new_user_country').selected?('Sweden').should be_false
221
+ @browser.select_list(:name, 'new_user_country').selected?('Sweden').should be_false
223
222
  end
224
223
  it "should raise UnknonwObjectException if the option doesn't exist" do
225
- lambda { @ie.select_list(:name, 'new_user_country').selected?('missing_option') }.should raise_error(UnknownObjectException)
224
+ lambda { @browser.select_list(:name, 'new_user_country').selected?('missing_option') }.should raise_error(UnknownObjectException)
226
225
  end
227
226
  end
228
227
 
229
228
  describe "#select" do
230
229
  it "should select the given item when given a String" do
231
- @ie.select_list(:name, "new_user_country").select("Denmark")
232
- @ie.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
230
+ @browser.select_list(:name, "new_user_country").select("Denmark")
231
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
233
232
  end
234
233
  it "should select the given item when given a Regexp" do
235
- @ie.select_list(:name, "new_user_country").select(/Denmark/)
236
- @ie.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
234
+ @browser.select_list(:name, "new_user_country").select(/Denmark/)
235
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
237
236
  end
238
237
  it "should select the given item when given an Xpath" do
239
- @ie.select_list(:xpath, "//select[@name='new_user_country']").select("Denmark")
240
- @ie.select_list(:xpath, "//select[@name='new_user_country']").get_selected_items.should == ["Denmark"]
238
+ @browser.select_list(:xpath, "//select[@name='new_user_country']").select("Denmark")
239
+ @browser.select_list(:xpath, "//select[@name='new_user_country']").get_selected_items.should == ["Denmark"]
241
240
  end
242
241
  it "should be able to select multiple items using :name and a String" do
243
- @ie.select_list(:name, "new_user_languages").clear_selection
244
- @ie.select_list(:name, "new_user_languages").select("Danish")
245
- @ie.select_list(:name, "new_user_languages").select("Swedish")
246
- @ie.select_list(:name, "new_user_languages").get_selected_items.should == ["Danish", "Swedish"]
242
+ @browser.select_list(:name, "new_user_languages").clear_selection
243
+ @browser.select_list(:name, "new_user_languages").select("Danish")
244
+ @browser.select_list(:name, "new_user_languages").select("Swedish")
245
+ @browser.select_list(:name, "new_user_languages").get_selected_items.should == ["Danish", "Swedish"]
247
246
  end
248
247
  it "should be able to select multiple items using :name and a Regexp" do
249
- @ie.select_list(:name, "new_user_languages").clear_selection
250
- @ie.select_list(:name, "new_user_languages").select(/ish/)
251
- @ie.select_list(:name, "new_user_languages").get_selected_items.should == ["Danish", "English", "Swedish"]
248
+ @browser.select_list(:name, "new_user_languages").clear_selection
249
+ @browser.select_list(:name, "new_user_languages").select(/ish/)
250
+ @browser.select_list(:name, "new_user_languages").get_selected_items.should == ["Danish", "English", "Swedish"]
252
251
  end
253
252
  it "should be able to select multiple items using :xpath" do
254
- @ie.select_list(:xpath, "//select[@name='new_user_languages']").clear_selection
255
- @ie.select_list(:xpath, "//select[@name='new_user_languages']").select( /ish/ )
256
- @ie.select_list(:xpath, "//select[@name='new_user_languages']").get_selected_items.should == ["Danish", "English", "Swedish"]
253
+ @browser.select_list(:xpath, "//select[@name='new_user_languages']").clear_selection
254
+ @browser.select_list(:xpath, "//select[@name='new_user_languages']").select( /ish/ )
255
+ @browser.select_list(:xpath, "//select[@name='new_user_languages']").get_selected_items.should == ["Danish", "English", "Swedish"]
257
256
  end
258
257
 
259
- it "should fire onchange event when selecting an item"
258
+ it "should fire onchange event when selecting an item" do
259
+ @browser.div(:id, "changed_language").text.should be_empty
260
+ @browser.select_list(:id, "new_user_languages").select("Danish")
261
+ @browser.div(:id, "changed_language").text.should == "changed language"
262
+ @browser.refresh # to reset js
263
+ end
264
+
265
+ it "should not fire onchange event when selecting an already selected item" do
266
+ @browser.select_list(:id, "new_user_languages").clear_selection # removes two options
267
+ @browser.div(:id, "changed_language").text.should == "changed languagechanged language"
268
+ @browser.select_list(:id, "new_user_languages").select("English")
269
+ @browser.div(:id, "changed_language").text.should == "changed languagechanged languagechanged language"
260
270
 
261
- it "should not fire onchange event when selecting an already selected item"
271
+ @browser.select_list(:id, "new_user_languages").select("English")
272
+ @browser.div(:id, "changed_language").text.should == "changed languagechanged languagechanged language"
273
+ end
262
274
 
263
275
  it "should raise NoValueFoundException if the option doesn't exist" do
264
- lambda { @ie.select_list(:name, "new_user_country").select("missing_option") }.should raise_error(NoValueFoundException)
265
- lambda { @ie.select_list(:name, "new_user_country").select(/missing_option/) }.should raise_error(NoValueFoundException)
276
+ lambda { @browser.select_list(:name, "new_user_country").select("missing_option") }.should raise_error(NoValueFoundException)
277
+ lambda { @browser.select_list(:name, "new_user_country").select(/missing_option/) }.should raise_error(NoValueFoundException)
266
278
  end
267
279
  end
268
280
 
269
281
  describe "#select_value" do
270
282
  it "should select the given item" do
271
- @ie.select_list(:name, "new_user_languages").clear_selection
272
- @ie.select_list(:name, "new_user_languages").select("Swedish")
273
- @ie.select_list(:name, "new_user_languages").get_selected_items.should == ["Swedish"]
283
+ @browser.select_list(:name, "new_user_languages").clear_selection
284
+ @browser.select_list(:name, "new_user_languages").select("Swedish")
285
+ @browser.select_list(:name, "new_user_languages").get_selected_items.should == ["Swedish"]
274
286
  end
275
287
  it "should raise NoValueFoundException if the option doesn't exist" do
276
- lambda { @ie.select_list(:name, "new_user_languages").select_value("no_such_option") }.should raise_error(NoValueFoundException)
277
- lambda { @ie.select_list(:name, "new_user_languages").select_value(/no_such_option/) }.should raise_error(NoValueFoundException)
288
+ lambda { @browser.select_list(:name, "new_user_languages").select_value("no_such_option") }.should raise_error(NoValueFoundException)
289
+ lambda { @browser.select_list(:name, "new_user_languages").select_value(/no_such_option/) }.should raise_error(NoValueFoundException)
278
290
  end
279
291
  end
280
292
 
281
293
  after :all do
282
- @ie.close
294
+ @browser.close
283
295
  end
284
296
 
285
297
  end
@@ -2,45 +2,45 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe "SelectLists" do
4
4
  before :all do
5
- @ie = Celerity::IE.new
6
- add_spec_checker(@ie)
5
+ @browser = Celerity::IE.new
6
+ add_spec_checker(@browser)
7
7
  end
8
8
 
9
9
  before :each do
10
- @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
10
+ @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
11
11
  end
12
12
 
13
13
  describe "#length" do
14
14
  it "should return the correct number of select lists on the page" do
15
- @ie.select_lists.length.should == 4
15
+ @browser.select_lists.length.should == 4
16
16
  end
17
17
  end
18
18
 
19
19
  describe "#[]" do
20
20
  it "should return the correct item" do
21
- @ie.select_lists[1].value.should == "Norway"
22
- @ie.select_lists[1].name.should == "new_user_country"
23
- @ie.select_lists[1].type.should == "select-one"
24
- @ie.select_lists[2].type.should == "select-multiple"
21
+ @browser.select_lists[1].value.should == "Norway"
22
+ @browser.select_lists[1].name.should == "new_user_country"
23
+ @browser.select_lists[1].type.should == "select-one"
24
+ @browser.select_lists[2].type.should == "select-multiple"
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#each" do
29
29
  it "should iterate through the select lists correctly" do
30
30
  index=1
31
- @ie.select_lists.each do |l|
32
- @ie.select_list(:index, index).name.should == l.name
33
- @ie.select_list(:index, index).id.should == l.id
34
- @ie.select_list(:index, index).type.should == l.type
35
- @ie.select_list(:index, index).value.should == l.value
31
+ @browser.select_lists.each do |l|
32
+ @browser.select_list(:index, index).name.should == l.name
33
+ @browser.select_list(:index, index).id.should == l.id
34
+ @browser.select_list(:index, index).type.should == l.type
35
+ @browser.select_list(:index, index).value.should == l.value
36
36
  index += 1
37
37
  end
38
- (index - 1).should == @ie.select_lists.length
38
+ (index - 1).should == @browser.select_lists.length
39
39
  end
40
40
  end
41
41
 
42
42
  after :all do
43
- @ie.close
43
+ @browser.close
44
44
  end
45
45
 
46
46
  end