celerity 0.0.2 → 0.0.3

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 (127) hide show
  1. data/History.txt +15 -1
  2. data/Manifest.txt +174 -0
  3. data/README.txt +19 -10
  4. data/config/hoe.rb +68 -0
  5. data/config/requirements.rb +15 -0
  6. data/lib/celerity.rb +14 -11
  7. data/lib/celerity/collections.rb +37 -8
  8. data/lib/celerity/container.rb +100 -3
  9. data/lib/celerity/disabled_element.rb +4 -2
  10. data/lib/celerity/element.rb +21 -8
  11. data/lib/celerity/element_collections.rb +4 -7
  12. data/lib/celerity/element_locator.rb +1 -0
  13. data/lib/celerity/elements/button.rb +6 -2
  14. data/lib/celerity/elements/file_field.rb +1 -1
  15. data/lib/celerity/elements/form.rb +1 -2
  16. data/lib/celerity/elements/frame.rb +0 -3
  17. data/lib/celerity/elements/image.rb +1 -4
  18. data/lib/celerity/elements/label.rb +1 -0
  19. data/lib/celerity/elements/link.rb +2 -0
  20. data/lib/celerity/elements/option.rb +1 -0
  21. data/lib/celerity/elements/radio_check.rb +3 -5
  22. data/lib/celerity/elements/select_list.rb +3 -10
  23. data/lib/celerity/elements/table.rb +8 -22
  24. data/lib/celerity/elements/table_body.rb +5 -11
  25. data/lib/celerity/elements/table_cell.rb +1 -0
  26. data/lib/celerity/elements/table_footer.rb +30 -0
  27. data/lib/celerity/elements/table_header.rb +30 -0
  28. data/lib/celerity/elements/table_row.rb +5 -3
  29. data/lib/celerity/elements/text_field.rb +18 -13
  30. data/lib/celerity/exception.rb +8 -8
  31. data/lib/celerity/extra/method_generator.rb +5 -2
  32. data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
  33. data/lib/celerity/ie.rb +195 -141
  34. data/lib/celerity/non_control_elements.rb +30 -4
  35. data/lib/celerity/version.rb +1 -1
  36. data/lib/celerity/watir_compatibility.rb +62 -0
  37. data/setup.rb +0 -2
  38. data/spec/area_spec.rb +4 -1
  39. data/spec/areas_spec.rb +1 -1
  40. data/spec/button_spec.rb +35 -17
  41. data/spec/buttons_spec.rb +1 -1
  42. data/spec/checkbox_spec.rb +6 -4
  43. data/spec/checkboxes_spec.rb +1 -1
  44. data/spec/div_spec.rb +20 -19
  45. data/spec/divs_spec.rb +2 -2
  46. data/spec/element_spec.rb +13 -2
  47. data/spec/filefield_spec.rb +6 -3
  48. data/spec/filefields_spec.rb +1 -1
  49. data/spec/form_spec.rb +4 -1
  50. data/spec/forms_spec.rb +1 -1
  51. data/spec/frame_spec.rb +6 -2
  52. data/spec/hidden_spec.rb +8 -4
  53. data/spec/hiddens_spec.rb +1 -1
  54. data/spec/hn_spec.rb +86 -0
  55. data/spec/hns_spec.rb +41 -0
  56. data/spec/html/bug_duplicate_attributes.html +14 -0
  57. data/spec/html/bug_javascript_001.html +11 -0
  58. data/spec/html/forms_with_input_elements.html +11 -11
  59. data/spec/html/images.html +18 -15
  60. data/spec/html/latin1_text.html +16 -0
  61. data/spec/html/non_control_elements.html +28 -4
  62. data/spec/html/tables.html +3 -3
  63. data/spec/html/utf8_text.html +15 -0
  64. data/spec/htmlunit_spec.rb +27 -0
  65. data/spec/ie_spec.rb +47 -12
  66. data/spec/image_spec.rb +4 -7
  67. data/spec/images_spec.rb +3 -2
  68. data/spec/label_spec.rb +4 -3
  69. data/spec/labels_spec.rb +1 -1
  70. data/spec/li_spec.rb +11 -8
  71. data/spec/link_spec.rb +5 -1
  72. data/spec/links_spec.rb +2 -1
  73. data/spec/lis_spec.rb +3 -2
  74. data/spec/map_spec.rb +4 -1
  75. data/spec/maps_spec.rb +1 -1
  76. data/spec/meta_spec.rb +6 -0
  77. data/spec/ol_spec.rb +73 -0
  78. data/spec/ols_spec.rb +41 -0
  79. data/spec/option_spec.rb +129 -0
  80. data/spec/p_spec.rb +4 -1
  81. data/spec/pre_spec.rb +4 -1
  82. data/spec/pres_spec.rb +1 -1
  83. data/spec/ps_spec.rb +2 -1
  84. data/spec/radio_spec.rb +7 -19
  85. data/spec/radios_spec.rb +1 -1
  86. data/spec/select_list_spec.rb +19 -57
  87. data/spec/select_lists_spec.rb +3 -2
  88. data/spec/span_spec.rb +8 -5
  89. data/spec/spans_spec.rb +2 -1
  90. data/spec/spec_helper.rb +8 -43
  91. data/spec/table_bodies_spec.rb +17 -4
  92. data/spec/table_body_spec.rb +47 -16
  93. data/spec/table_cell_spec.rb +5 -3
  94. data/spec/table_cells_spec.rb +1 -1
  95. data/spec/table_footer_spec.rb +94 -0
  96. data/spec/table_footers_spec.rb +53 -0
  97. data/spec/table_header_spec.rb +94 -0
  98. data/spec/table_headers_spec.rb +53 -0
  99. data/spec/table_row_spec.rb +25 -4
  100. data/spec/table_rows_spec.rb +1 -1
  101. data/spec/table_spec.rb +22 -2
  102. data/spec/tables_spec.rb +2 -1
  103. data/spec/text_field_spec.rb +52 -20
  104. data/spec/text_fields_spec.rb +1 -1
  105. data/spec/ul_spec.rb +73 -0
  106. data/spec/uls_spec.rb +41 -0
  107. data/spec/watir_compatability_spec.rb +253 -0
  108. data/support/celerity_viewer/rubycocoa/CelerityViewer.icns +0 -0
  109. data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/classes.nib +37 -0
  110. data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/info.nib +19 -0
  111. data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/keyedobjects.nib +0 -0
  112. data/support/celerity_viewer/rubycocoa/Info.plist.erb +28 -0
  113. data/support/celerity_viewer/rubycocoa/MainController.rb +23 -0
  114. data/support/celerity_viewer/rubycocoa/README +94 -0
  115. data/support/celerity_viewer/rubycocoa/Rakefile +100 -0
  116. data/support/celerity_viewer/rubycocoa/distributed_viewer.rb +86 -0
  117. data/support/celerity_viewer/rubycocoa/main.m +7 -0
  118. data/support/celerity_viewer/rubycocoa/main.rb +27 -0
  119. data/support/spec_server.rb +64 -0
  120. data/tasks/benchmark.rake +1 -0
  121. data/tasks/rdoc.rake +4 -0
  122. data/tasks/rspec.rake +10 -3
  123. data/tasks/simple_ci.rake +94 -0
  124. data/tasks/specserver.rake +21 -0
  125. metadata +160 -114
  126. data/spec/table_bodies.rb +0 -40
  127. data/tasks/testserver.rake +0 -32
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Ols do
4
+
5
+ before :all do
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
+ end
9
+
10
+ before :each do
11
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
12
+ end
13
+
14
+ describe "#length" do
15
+ it "should return the number of ols" do
16
+ @browser.ols.length.should == 2
17
+ end
18
+ end
19
+
20
+ describe "#[]" do
21
+ it "should return the ol at the given index" do
22
+ @browser.ols[1].id.should == "favorite_compounds"
23
+ end
24
+ end
25
+
26
+ describe "#each" do
27
+ it "should iterate through ols correctly" do
28
+ @browser.ols.each_with_index do |ul, index|
29
+ ul.name.should == @browser.ol(:index, index+1).name
30
+ ul.id.should == @browser.ol(:index, index+1).id
31
+ ul.value.should == @browser.ol(:index, index+1).value
32
+ end
33
+ end
34
+ end
35
+
36
+ after :all do
37
+ @browser.close
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,129 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Option do
4
+
5
+ before :all do
6
+ @browser = Celerity::IE.new
7
+ add_spec_checker(@browser)
8
+ end
9
+
10
+ before :each do
11
+ @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
12
+ end
13
+
14
+ describe "#exists?" do
15
+ it "should return true if the element exists (page context)" do
16
+ @browser.option(:id, "nor").should exist
17
+ @browser.option(:id, /nor/).should exist
18
+ @browser.option(:value, "2").should exist
19
+ @browser.option(:value, /2/).should exist
20
+ @browser.option(:text, "Norway").should exist
21
+ @browser.option(:text, /Norway/).should exist
22
+ @browser.option(:class, "scandinavia").should exist
23
+ @browser.option(:index, 2).should exist
24
+ @browser.option(:xpath, "//option[@id='nor']").should exist
25
+ end
26
+ it "should return true if the element exists (select_list context)" do
27
+ @browser.select_list(:name, "new_user_country").option(:id, "nor").should exist
28
+ @browser.select_list(:name, "new_user_country").option(:id, /nor/).should exist
29
+ @browser.select_list(:name, "new_user_country").option(:value, "2").should exist
30
+ @browser.select_list(:name, "new_user_country").option(:value, /2/).should exist
31
+ @browser.select_list(:name, "new_user_country").option(:text, "Norway").should exist
32
+ @browser.select_list(:name, "new_user_country").option(:text, /Norway/).should exist
33
+ @browser.select_list(:name, "new_user_country").option(:class, "scandinavia").should exist
34
+ @browser.select_list(:name, "new_user_country").option(:index, 2).should exist
35
+ @browser.select_list(:name, "new_user_country").option(:xpath, "//option[@id='nor']").should exist
36
+ end
37
+ it "should return true if the element exists (default how = :text)" do
38
+ @browser.option("Swedish").should exist
39
+ @browser.select_list(:name, "new_user_languages").option("Swedish").should exist
40
+ end
41
+ it "should return false if the element does not exist (page context)" do
42
+ @browser.option(:id, "no_such_id").should_not exist
43
+ @browser.option(:id, /no_such_id/).should_not exist
44
+ @browser.option(:value, "no_such_value").should_not exist
45
+ @browser.option(:value, /no_such_value/).should_not exist
46
+ @browser.option(:text, "no_such_text").should_not exist
47
+ @browser.option(:text, /no_such_text/).should_not exist
48
+ @browser.option(:class, "no_such_class").should_not exist
49
+ @browser.option(:index, 1337).should_not exist
50
+ @browser.option(:xpath, "//option[@id='no_such_id']").should_not exist
51
+ end
52
+ it "should return false if the element does not exist (select_list context)" do
53
+ @browser.select_list(:name, "new_user_country").option(:id, "no_such_id").should_not exist
54
+ @browser.select_list(:name, "new_user_country").option(:id, /no_such_id/).should_not exist
55
+ @browser.select_list(:name, "new_user_country").option(:value, "no_such_value").should_not exist
56
+ @browser.select_list(:name, "new_user_country").option(:value, /no_such_value/).should_not exist
57
+ @browser.select_list(:name, "new_user_country").option(:text, "no_such_text").should_not exist
58
+ @browser.select_list(:name, "new_user_country").option(:text, /no_such_text/).should_not exist
59
+ @browser.select_list(:name, "new_user_country").option(:class, "no_such_class").should_not exist
60
+ @browser.select_list(:name, "new_user_country").option(:index, 1337).should_not exist
61
+ @browser.select_list(:name, "new_user_country").option(:xpath, "//option[@id='no_such_id']").should_not exist
62
+ end
63
+ it "should raise ArgumentError when 'what' argument is invalid" do
64
+ lambda { @browser.option(:id, 3.14).exists? }.should raise_error(ArgumentError)
65
+ lambda { @browser.select_list(:name, "new_user_country").option(:id, 3.14).exists? }.should raise_error(ArgumentError)
66
+ end
67
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
68
+ lambda { @browser.option(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
69
+ lambda { @browser.select_list(:name, "new_user_country").option(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
70
+ end
71
+ end
72
+
73
+ describe "#select" do
74
+ it "should should be able to select the chosen option (page context)" do
75
+ @browser.select_list(:name, "new_user_country").clear_selection
76
+ @browser.option(:text, "Denmark").select
77
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
78
+ end
79
+ it "should should be able to select the chosen option (select_list context)" do
80
+ @browser.select_list(:name, "new_user_country").clear_selection
81
+ @browser.select_list(:name, "new_user_country").option(:text, "Denmark").select
82
+ @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Denmark"]
83
+ end
84
+ it "should select the option when found by text (page context)" do
85
+ @browser.option(:text, 'Sweden').select
86
+ @browser.option(:text, 'Sweden').should be_selected
87
+ end
88
+ it "should select the option when found by text (select_list context)" do
89
+ @browser.select_list(:name, 'new_user_country').option(:text, 'Sweden').select
90
+ @browser.select_list(:name, 'new_user_country').option(:text, 'Sweden').should be_selected
91
+ end
92
+ it "should fire onclick event (page context)" do
93
+ @browser.option(:text, "Username 3").select
94
+ @browser.text_field(:id, 'delete_user_comment').value.should == 'Don\'t do it!'
95
+ end
96
+ it "should fire onclick event (select_list context)" do
97
+ @browser.select_list(:id, 'delete_user_username').option(:text, "Username 3").select
98
+ @browser.text_field(:id, 'delete_user_comment').value.should == 'Don\'t do it!'
99
+ end
100
+ it "should raise UnknownObjectException if the option does not exist (page context)" do
101
+ lambda { @browser.option(:text, "no_such_text").select }.should raise_error(UnknownObjectException)
102
+ lambda { @browser.option(:text, /missing/).select }.should raise_error(UnknownObjectException)
103
+ end
104
+ it "should raise UnknownObjectException if the option does not exist (select_list context)" do
105
+ lambda { @browser.select_list(:name, "new_user_country").option(:text, "no_such_text").select }.should raise_error(UnknownObjectException)
106
+ lambda { @browser.select_list(:name, "new_user_country").option(:text, /missing/).select }.should raise_error(UnknownObjectException)
107
+ end
108
+ it "should raise MissingWayOfFindingObjectException when given a bad 'how' (page context)" do
109
+ lambda { @browser.option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
110
+ end
111
+ it "should raise MissingWayOfFindingObjectException when given a bad 'how' (select_list context)" do
112
+ lambda { @browser.select_list(:name, "new_user_country").option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
113
+ end
114
+ end
115
+
116
+ describe "#class_name" do
117
+ it "should be able to get attributes (page context)" do
118
+ @browser.option(:text, 'Sweden').class_name.should == "scandinavia"
119
+ end
120
+ it "should be able to get attributes (select_list context)" do
121
+ @browser.select_list(:name, "new_user_country").option(:text , 'Sweden').class_name.should == "scandinavia"
122
+ end
123
+ end
124
+
125
+ after :all do
126
+ @browser.close
127
+ end
128
+
129
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "P" do
3
+ describe P do
4
4
 
5
5
  before :all do
6
6
  @browser = IE.new
@@ -23,6 +23,9 @@ describe "P" do
23
23
  @browser.p(:index, 1).should exist
24
24
  @browser.p(:xpath, "//p[@id='lead']").should exist
25
25
  end
26
+ it "should return true if the element exists (default how = :id)" do
27
+ @browser.p("lead").should exist
28
+ end
26
29
  it "should return false if the 'p' doesn't exist" do
27
30
  @browser.p(:id, "no_such_id").should_not exist
28
31
  @browser.p(:id, /no_such_id/).should_not exist
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "Pre" do
3
+ describe Pre do
4
4
 
5
5
  before :all do
6
6
  @browser = IE.new
@@ -23,6 +23,9 @@ describe "Pre" do
23
23
  @browser.pre(:index, 1).should exist
24
24
  @browser.pre(:xpath, "//pre[@id='rspec']").should exist
25
25
  end
26
+ it "should return true if the element exists (default how = :id)" do
27
+ @browser.pre("rspec").should exist
28
+ end
26
29
  it "should return false if the 'p' doesn't exist" do
27
30
  @browser.pre(:id, "no_such_id").should_not exist
28
31
  @browser.pre(:id, /no_such_id/).should_not exist
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "Pres" do
3
+ describe Pres do
4
4
 
5
5
  before :all do
6
6
  @browser = IE.new
@@ -1,6 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "Ps" do
3
+ describe Ps do
4
+
4
5
  before :all do
5
6
  @browser = IE.new
6
7
  add_spec_checker(@browser)
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "Radio" do
3
+ describe Radio do
4
4
 
5
5
  before :all do
6
6
  @browser = IE.new
@@ -10,10 +10,8 @@ describe "Radio" do
10
10
  before :each do
11
11
  @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
12
12
  end
13
-
14
13
 
15
14
  # Exists method
16
-
17
15
  describe "#exists?" do
18
16
  it "should return true if the radio button exists" do
19
17
  @browser.radio(:id, "new_user_newsletter_yes").should exist
@@ -25,18 +23,18 @@ describe "Radio" do
25
23
  # TODO: figure out what :text means for a radio button
26
24
  # @browser.radio(:text, "yes").should exist
27
25
  # @browser.radio(:text, /yes/).should exist
28
-
29
26
  @browser.radio(:class, "huge").should exist
30
27
  @browser.radio(:class, /huge/).should exist
31
28
  @browser.radio(:index, 1).should exist
32
29
  @browser.radio(:xpath, "//input[@id='new_user_newsletter_yes']").should exist
33
30
  end
34
-
31
+ it "should return true if the element exists (default how = :name)" do
32
+ @browser.radio("new_user_newsletter").should exist
33
+ end
35
34
  it "should return true if the radio button exists (search by name and value)" do
36
35
  @browser.radio(:name, "new_user_newsletter", 'yes').should exist
37
36
  @browser.radio(:xpath, "//input[@name='new_user_newsletter' and @value='yes']").set
38
37
  end
39
-
40
38
  it "should return false if the radio button does not exist" do
41
39
  @browser.radio(:id, "no_such_id").should_not exist
42
40
  @browser.radio(:id, /no_such_id/).should_not exist
@@ -51,23 +49,19 @@ describe "Radio" do
51
49
  @browser.radio(:index, 1337).should_not exist
52
50
  @browser.radio(:xpath, "input[@id='no_such_id']").should_not exist
53
51
  end
54
-
55
52
  it "should return false if the radio button does not exist (search by name and value)" do
56
53
  @browser.radio(:name, "new_user_newsletter", 'no_such_value').should_not exist
57
54
  @browser.radio(:xpath, "//input[@name='new_user_newsletter' and @value='no_such_value']").should_not exist
58
55
  @browser.radio(:name, "no_such_name", 'yes').should_not exist
59
56
  @browser.radio(:xpath, "//input[@name='no_such_name' and @value='yes']").should_not exist
60
57
  end
61
-
62
58
  it "should return true for radios with a string value" do
63
59
  @browser.radio(:name, 'new_user_newsletter', 'yes').should exist
64
60
  @browser.radio(:name, 'new_user_newsletter', 'no').should exist
65
61
  end
66
-
67
62
  it "should raise ArgumentError when 'what' argument is invalid" do
68
63
  lambda { @browser.radio(:id, 3.14).exists? }.should raise_error(ArgumentError)
69
64
  end
70
-
71
65
  it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
72
66
  lambda { @browser.radio(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
73
67
  end
@@ -75,7 +69,6 @@ describe "Radio" do
75
69
 
76
70
 
77
71
  # Attribute methods
78
-
79
72
  describe "#class_name" do
80
73
  it "should return the class name if the radio exists and has an attribute" do
81
74
  @browser.radio(:id, "new_user_newsletter_yes").class_name.should == "huge"
@@ -144,7 +137,6 @@ describe "Radio" do
144
137
 
145
138
 
146
139
  # Access methods
147
-
148
140
  describe "#enabled?" do
149
141
  it "should return true if the radio button is enabled" do
150
142
  @browser.radio(:id, "new_user_newsletter_yes").should be_enabled
@@ -174,8 +166,7 @@ describe "Radio" do
174
166
 
175
167
 
176
168
  # Manipulation methods
177
-
178
- describe "clear" do
169
+ describe "#clear" do
179
170
  it "should clear the radio button if it is set" do
180
171
  @browser.radio(:id, "new_user_newsletter_yes").clear
181
172
  @browser.radio(:id, "new_user_newsletter_yes").should_not be_set
@@ -204,7 +195,6 @@ describe "Radio" do
204
195
  @browser.radio(:xpath, "//input[@id='new_user_newsletter_no']").set
205
196
  @browser.radio(:xpath, "//input[@id='new_user_newsletter_no']").should be_set
206
197
  end
207
-
208
198
  it "should fire the onclick event" do
209
199
  @browser.div(:id, "wants_newsletter").text.should be_empty
210
200
  @browser.radio(:id, "new_user_newsletter_no").set
@@ -212,7 +202,6 @@ describe "Radio" do
212
202
  @browser.radio(:id, "new_user_newsletter_yes").set
213
203
  @browser.div(:id, "wants_newsletter").text.should be_empty
214
204
  end
215
-
216
205
  it "should raise UnknownObjectException if the radio button doesn't exist" do
217
206
  lambda { @browser.radio(:name, "no_such_name").set }.should raise_error(UnknownObjectException)
218
207
  lambda { @browser.radio(:xpath, "//input[@name='no_such_name']").set }.should raise_error(UnknownObjectException)
@@ -225,7 +214,6 @@ describe "Radio" do
225
214
 
226
215
 
227
216
  # Other
228
-
229
217
  describe '#set?' do
230
218
  it "should return true if the radio button is set" do
231
219
  @browser.radio(:id, "new_user_newsletter_yes").should be_set
@@ -254,8 +242,8 @@ describe "Radio" do
254
242
  @browser.radio(:id, "new_user_newsletter_no").get_state.should be_false
255
243
  end
256
244
  it "should raise UnknownObjectException if the radio doesn't exist" do
257
- lambda { @browser.radio(:name, "no_such_name").get_state }.should raise_error(UnknownObjectException)
258
- lambda { @browser.radio(:xpath, "//input[@name='no_such_name']").get_state }.should raise_error(UnknownObjectException)
245
+ lambda { @browser.radio(:name, "no_such_name").get_state }.should raise_error(UnknownObjectException)
246
+ lambda { @browser.radio(:xpath, "//input[@name='no_such_name']").get_state }.should raise_error(UnknownObjectException)
259
247
  end
260
248
  end
261
249
 
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "Radios" do
3
+ describe Radios do
4
4
 
5
5
  before :all do
6
6
  @browser = IE.new
@@ -1,6 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe "SelectList" do
3
+ describe SelectList do
4
+
4
5
  before :all do
5
6
  @browser = Celerity::IE.new
6
7
  add_spec_checker(@browser)
@@ -10,28 +11,26 @@ describe "SelectList" do
10
11
  @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
11
12
  end
12
13
 
13
-
14
14
  # Exists method
15
-
16
15
  describe "#exists?" do
17
16
  it "should return true if the select list exists" do
18
17
  @browser.select_list(:id, 'new_user_country').should exist
19
18
  @browser.select_list(:id, /new_user_country/).should exist
20
19
  @browser.select_list(:name, 'new_user_country').should exist
21
20
  @browser.select_list(:name, /new_user_country/).should exist
22
-
23
- # check behaviour in Watir
21
+ # TODO: check behaviour in Watir
24
22
  # @browser.select_list(:value, 'Norway').should exist
25
23
  # @browser.select_list(:value, /Norway/).should exist
26
-
27
- # not sure what :text is for input elements
28
- # @browser.select_list(:text, 'Norway').should exist
29
- # @browser.select_list(:text, /Norway/).should exist
24
+ @browser.select_list(:text, 'Norway').should exist
25
+ @browser.select_list(:text, /Norway/).should exist
30
26
  @browser.select_list(:class, 'country').should exist
31
27
  @browser.select_list(:class, /country/).should exist
32
28
  @browser.select_list(:index, 1).should exist
33
29
  @browser.select_list(:xpath, "//select[@id='new_user_country']").should exist
34
30
  end
31
+ it "should return true if the element exists (default how = :name)" do
32
+ @browser.select_list("new_user_country").should exist
33
+ end
35
34
  it "should return false if the select list doesn't exist" do
36
35
  @browser.select_list(:id, 'no_such_id').should_not exist
37
36
  @browser.select_list(:id, /no_such_id/).should_not exist
@@ -46,11 +45,9 @@ describe "SelectList" do
46
45
  @browser.select_list(:index, 1337).should_not exist
47
46
  @browser.select_list(:xpath, "//select[@id='no_such_id']").should_not exist
48
47
  end
49
-
50
48
  it "should raise ArgumentError when 'what' argument is invalid" do
51
49
  lambda { @browser.select_list(:id, 3.14).exists? }.should raise_error(ArgumentError)
52
50
  end
53
-
54
51
  it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
55
52
  lambda { @browser.select_list(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
56
53
  end
@@ -58,7 +55,6 @@ describe "SelectList" do
58
55
 
59
56
 
60
57
  # Attribute methods
61
-
62
58
  describe "#class_name" do
63
59
  it "should return the class name of the select list" do
64
60
  @browser.select_list(:name, 'new_user_country').class_name.should == 'country'
@@ -98,18 +94,16 @@ describe "SelectList" do
98
94
 
99
95
  describe "#value" do
100
96
  it "should return the value of the selected option" do
101
- @browser.select_list(:index, 1).value.should == "Norway"
97
+ @browser.select_list(:index, 1).value.should == "2"
102
98
  @browser.select_list(:index, 1).select(/Sweden/)
103
- @browser.select_list(:index, 1).value.should == "Sweden"
99
+ @browser.select_list(:index, 1).value.should == "3"
104
100
  end
105
101
  it "should raise UnknownObjectException if the select list doesn't exist" do
106
- lambda { @browser.select_list(:index, 1337).value }.should raise_error(UnknownObjectException)
102
+ lambda { @browser.select_list(:index, 1337).value }.should raise_error(UnknownObjectException)
107
103
  end
108
104
  end
109
-
110
105
 
111
106
  # Access methods
112
-
113
107
  describe "#enabled?" do
114
108
  it "should return true if the select list is enabled" do
115
109
  @browser.select_list(:name, 'new_user_country').should be_enabled
@@ -129,46 +123,20 @@ describe "SelectList" do
129
123
  it "should return false if the select list is enabled" do
130
124
  @browser.select_list(:index, 1).should_not be_disabled
131
125
  end
132
-
133
126
  it "should should raise UnknownObjectException when the select list does not exist" do
134
127
  lambda { @browser.select_list(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
135
128
  end
136
129
  end
137
130
 
138
-
139
131
  # Other
140
-
141
132
  describe "#option" do
142
133
  it "should return an instance of Option" do
143
- @browser.select_list(:name, "new_user_country").option(:text, "Denmark").should be_instance_of(Celerity::Option)
144
- end
145
-
146
- # do we need a seperate spec for this object?
147
- it "should should be able to select the chosen option" do
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
- end
152
-
153
- it "should select the option when found by text" do
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
- end
157
-
158
- it "should raise UnknownObjectException if the option does not exist" do
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
- end
162
-
163
- it "should raise MissingWayOfFindingObjectException when given a bad 'how'" do
164
- lambda { @browser.select_list(:name, "new_user_country").option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
165
- end
166
-
167
- it "should be able to get attributes" do
168
- @browser.select_list(:name, "new_user_country").option(:text , 'Sweden').class_name.should == "scandinavia"
169
- end
134
+ option = @browser.select_list(:name, "new_user_country").option(:text, "Denmark")
135
+ option.should be_instance_of(Option)
136
+ option.value.should == "1"
137
+ end
170
138
  end
171
-
139
+
172
140
  describe "#get_all_contents" do
173
141
  it "should should raise UnknownObjectException if the select list doesn't exist" do
174
142
  lambda { @browser.select_list(:name, 'no_such_name').get_all_contents }.should raise_error(UnknownObjectException)
@@ -182,7 +150,6 @@ describe "SelectList" do
182
150
  it "should should raise UnknownObjectException if the select list doesn't exist" do
183
151
  lambda { @browser.select_list(:name, 'no_such_name').get_selected_items }.should raise_error(UnknownObjectException)
184
152
  end
185
-
186
153
  it "should get the currently selected item(s)" do
187
154
  @browser.select_list(:name, "new_user_country").get_selected_items.should == ["Norway"]
188
155
  @browser.select_list(:name, "new_user_languages").get_selected_items.should == ["English", "Norwegian"]
@@ -251,27 +218,23 @@ describe "SelectList" do
251
218
  end
252
219
  it "should be able to select multiple items using :xpath" do
253
220
  @browser.select_list(:xpath, "//select[@name='new_user_languages']").clear_selection
254
- @browser.select_list(:xpath, "//select[@name='new_user_languages']").select( /ish/ )
221
+ @browser.select_list(:xpath, "//select[@name='new_user_languages']").select(/ish/)
255
222
  @browser.select_list(:xpath, "//select[@name='new_user_languages']").get_selected_items.should == ["Danish", "English", "Swedish"]
256
223
  end
257
-
258
224
  it "should fire onchange event when selecting an item" do
259
225
  @browser.div(:id, "changed_language").text.should be_empty
260
226
  @browser.select_list(:id, "new_user_languages").select("Danish")
261
227
  @browser.div(:id, "changed_language").text.should == "changed language"
262
228
  @browser.refresh # to reset js
263
229
  end
264
-
265
230
  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
231
+ @browser.select_list(:id, "new_user_languages").clear_selection # removes the two pre-selected options
267
232
  @browser.div(:id, "changed_language").text.should == "changed languagechanged language"
268
233
  @browser.select_list(:id, "new_user_languages").select("English")
269
234
  @browser.div(:id, "changed_language").text.should == "changed languagechanged languagechanged language"
270
-
271
235
  @browser.select_list(:id, "new_user_languages").select("English")
272
236
  @browser.div(:id, "changed_language").text.should == "changed languagechanged languagechanged language"
273
237
  end
274
-
275
238
  it "should raise NoValueFoundException if the option doesn't exist" do
276
239
  lambda { @browser.select_list(:name, "new_user_country").select("missing_option") }.should raise_error(NoValueFoundException)
277
240
  lambda { @browser.select_list(:name, "new_user_country").select(/missing_option/) }.should raise_error(NoValueFoundException)
@@ -294,5 +257,4 @@ describe "SelectList" do
294
257
  @browser.close
295
258
  end
296
259
 
297
- end
298
-
260
+ end