celerity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +621 -0
  3. data/README.txt +58 -0
  4. data/Rakefile +4 -0
  5. data/lib/celerity.rb +47 -0
  6. data/lib/celerity/clickable_element.rb +11 -0
  7. data/lib/celerity/collections.rb +99 -0
  8. data/lib/celerity/container.rb +369 -0
  9. data/lib/celerity/disabled_element.rb +20 -0
  10. data/lib/celerity/element.rb +114 -0
  11. data/lib/celerity/element_collections.rb +67 -0
  12. data/lib/celerity/elements/button.rb +13 -0
  13. data/lib/celerity/elements/file_field.rb +12 -0
  14. data/lib/celerity/elements/form.rb +15 -0
  15. data/lib/celerity/elements/frame.rb +44 -0
  16. data/lib/celerity/elements/image.rb +70 -0
  17. data/lib/celerity/elements/label.rb +10 -0
  18. data/lib/celerity/elements/link.rb +13 -0
  19. data/lib/celerity/elements/radio_check.rb +59 -0
  20. data/lib/celerity/elements/select_list.rb +84 -0
  21. data/lib/celerity/elements/table.rb +94 -0
  22. data/lib/celerity/elements/table_body.rb +38 -0
  23. data/lib/celerity/elements/table_cell.rb +30 -0
  24. data/lib/celerity/elements/table_row.rb +34 -0
  25. data/lib/celerity/elements/text_field.rb +80 -0
  26. data/lib/celerity/exception.rb +48 -0
  27. data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
  28. data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
  29. data/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
  30. data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
  31. data/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
  32. data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  33. data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  34. data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
  35. data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
  36. data/lib/celerity/htmlunit/nekohtml-1.9.7.jar +0 -0
  37. data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  38. data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
  39. data/lib/celerity/htmlunit/xercesImpl-2.8.1.jar +0 -0
  40. data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
  41. data/lib/celerity/ie.rb +126 -0
  42. data/lib/celerity/input_element.rb +29 -0
  43. data/lib/celerity/non_control_elements.rb +50 -0
  44. data/lib/celerity/version.rb +9 -0
  45. data/setup.rb +1585 -0
  46. data/spec/area_spec.rb +79 -0
  47. data/spec/areas_spec.rb +41 -0
  48. data/spec/button_spec.rb +171 -0
  49. data/spec/buttons_spec.rb +40 -0
  50. data/spec/checkbox_spec.rb +259 -0
  51. data/spec/checkboxes_spec.rb +39 -0
  52. data/spec/div_spec.rb +174 -0
  53. data/spec/divs_spec.rb +40 -0
  54. data/spec/element_spec.rb +29 -0
  55. data/spec/filefield_spec.rb +110 -0
  56. data/spec/filefields_spec.rb +41 -0
  57. data/spec/form_spec.rb +53 -0
  58. data/spec/forms_spec.rb +42 -0
  59. data/spec/frame_spec.rb +103 -0
  60. data/spec/hidden_spec.rb +105 -0
  61. data/spec/hiddens_spec.rb +40 -0
  62. data/spec/html/forms_with_input_elements.html +107 -0
  63. data/spec/html/frame_1.html +17 -0
  64. data/spec/html/frame_2.html +16 -0
  65. data/spec/html/frames.html +11 -0
  66. data/spec/html/iframes.html +12 -0
  67. data/spec/html/images.html +24 -0
  68. data/spec/html/images/1.gif +0 -0
  69. data/spec/html/images/2.gif +0 -0
  70. data/spec/html/images/3.gif +0 -0
  71. data/spec/html/images/button.jpg +0 -0
  72. data/spec/html/images/circle.jpg +0 -0
  73. data/spec/html/images/map.gif +0 -0
  74. data/spec/html/images/map2.gif +0 -0
  75. data/spec/html/images/minus.gif +0 -0
  76. data/spec/html/images/originaltriangle.jpg +0 -0
  77. data/spec/html/images/plus.gif +0 -0
  78. data/spec/html/images/square.jpg +0 -0
  79. data/spec/html/images/triangle.jpg +0 -0
  80. data/spec/html/non_control_elements.html +85 -0
  81. data/spec/html/tables.html +119 -0
  82. data/spec/ie_spec.rb +146 -0
  83. data/spec/image_spec.rb +210 -0
  84. data/spec/images_spec.rb +39 -0
  85. data/spec/label_spec.rb +65 -0
  86. data/spec/labels_spec.rb +41 -0
  87. data/spec/li_spec.rb +114 -0
  88. data/spec/link_spec.rb +147 -0
  89. data/spec/links_spec.rb +43 -0
  90. data/spec/lis_spec.rb +40 -0
  91. data/spec/map_spec.rb +83 -0
  92. data/spec/maps_spec.rb +41 -0
  93. data/spec/p_spec.rb +140 -0
  94. data/spec/pre_spec.rb +110 -0
  95. data/spec/pres_spec.rb +41 -0
  96. data/spec/ps_spec.rb +40 -0
  97. data/spec/radio_spec.rb +260 -0
  98. data/spec/radios_spec.rb +43 -0
  99. data/spec/select_list_spec.rb +286 -0
  100. data/spec/select_lists_spec.rb +47 -0
  101. data/spec/span_spec.rb +156 -0
  102. data/spec/spans_spec.rb +65 -0
  103. data/spec/spec.opts +1 -0
  104. data/spec/spec_helper.rb +90 -0
  105. data/spec/table_bodies.rb +40 -0
  106. data/spec/table_bodies_spec.rb +42 -0
  107. data/spec/table_body_spec.rb +72 -0
  108. data/spec/table_cell_spec.rb +61 -0
  109. data/spec/table_cells_spec.rb +60 -0
  110. data/spec/table_row_spec.rb +59 -0
  111. data/spec/table_rows_spec.rb +57 -0
  112. data/spec/table_spec.rb +111 -0
  113. data/spec/tables_spec.rb +42 -0
  114. data/spec/text_field_spec.rb +234 -0
  115. data/spec/text_fields_spec.rb +45 -0
  116. data/tasks/environment.rake +7 -0
  117. data/tasks/rspec.rake +23 -0
  118. data/tasks/simple_ci.rake +94 -0
  119. data/tasks/testserver.rake +17 -0
  120. metadata +174 -0
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "P" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie.goto(TEST_HOST + "/images.html")
12
+ end
13
+
14
+ # Exists method
15
+ describe "#exist?" do
16
+ it "should return true if the 'area' exists" do
17
+ @ie.area(:id, "NCE").should exist
18
+ @ie.area(:id, /NCE/).should exist
19
+ @ie.area(:name, "NCE").should exist
20
+ @ie.area(:name, /NCE/).should exist
21
+ @ie.area(:title, "Tables").should exist
22
+ @ie.area(:title, /Tables/).should exist
23
+ @ie.area(:url, "tables.html").should exist
24
+ @ie.area(:url, /tables/).should exist
25
+ @ie.area(:index, 1).should exist
26
+ @ie.area(:xpath, "//area[@id='NCE']").should exist
27
+ end
28
+ it "should return false if the 'area' doesn't exist" do
29
+ @ie.area(:id, "no_such_id").should_not exist
30
+ @ie.area(:id, /no_such_id/).should_not exist
31
+ @ie.area(:name, "no_such_id").should_not exist
32
+ @ie.area(:name, /no_such_id/).should_not exist
33
+ @ie.area(:title, "no_such_title").should_not exist
34
+ @ie.area(:title, /no_such_title/).should_not exist
35
+ @ie.area(:url, "no_such_href").should_not exist
36
+ @ie.area(:url, /no_such_href/).should_not exist
37
+ @ie.area(:index, 1337).should_not exist
38
+ @ie.area(:xpath, "//area[@id='no_such_id']").should_not exist
39
+ end
40
+ it "should raise ArgumentError when what argument is invalid" do
41
+ lambda { @ie.area(:id, 3.14).exists? }.should raise_error(ArgumentError)
42
+ end
43
+ it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
44
+ lambda { @ie.area(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
45
+ end
46
+ end
47
+
48
+ # Attribute methods
49
+ describe "#id" do
50
+ it "should return the id attribute" do
51
+ @ie.area(:index, 1).id.should == "NCE"
52
+ end
53
+ it "should return an empty string if the element exists and the attribute doesn't" do
54
+ @ie.area(:index, 3).id.should == ''
55
+ end
56
+ it "should raise UnknownObjectException if the p doesn't exist" do
57
+ lambda { @ie.area(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
58
+ lambda { @ie.area(:index, 1337).id }.should raise_error(UnknownObjectException)
59
+ end
60
+ end
61
+
62
+ describe "#name" do
63
+ it "should return the name attribute" do
64
+ @ie.area(:index, 1).name.should == "NCE"
65
+ end
66
+ it "should return an empty string if the element exists and the attribute doesn't" do
67
+ @ie.area(:index, 3).name.should == ''
68
+ end
69
+ it "should raise UnknownObjectException if the p doesn't exist" do
70
+ lambda { @ie.area(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
71
+ lambda { @ie.area(:index, 1337).name }.should raise_error(UnknownObjectException)
72
+ end
73
+ end
74
+
75
+ after :all do
76
+ @ie.close
77
+ end
78
+
79
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Areas" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie.goto(TEST_HOST + "/images.html")
12
+ end
13
+
14
+ describe "#length" do
15
+ it "should return the number of areas" do
16
+ @ie.areas.length.should == 3
17
+ end
18
+ end
19
+
20
+ describe "#[]" do
21
+ it "should return the p at the given index" do
22
+ @ie.areas[1].id.should == "NCE"
23
+ end
24
+ end
25
+
26
+ describe "#each" do
27
+ it "should iterate through areas correctly" do
28
+ @ie.areas.each_with_index do |a, index|
29
+ a.name.should == @ie.area(:index, index+1).name
30
+ a.id.should == @ie.area(:index, index+1).id
31
+ a.value.should == @ie.area(:index, index+1).value
32
+ end
33
+ end
34
+ end
35
+
36
+ after :all do
37
+ @ie.close
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,171 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Button" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
12
+ end
13
+
14
+ # Exists method
15
+ describe "#exists?" do
16
+ it "should return true if the button exists" do
17
+ @ie.button(:id, "new_user_submit").should exist
18
+ @ie.button(:id, /new_user_submit/).should exist
19
+ @ie.button(:name, "new_user_reset").should exist
20
+ @ie.button(:name, /new_user_reset/).should exist
21
+ # we need to figure out what :text and :value/:caption means on input type="button" and <button /> elements
22
+ @ie.button(:value, "Button 2").should exist
23
+ @ie.button(:value, /Button 2/).should exist
24
+ @ie.button(:text, "Button 2").should exist
25
+ @ie.button(:text, /Button 2/).should exist
26
+ @ie.button(:class, "image").should exist
27
+ @ie.button(:class, /image/).should exist
28
+ @ie.button(:index, 1).should exist
29
+ @ie.button(:xpath, "//input[@id='new_user_submit']").should exist
30
+ end
31
+ it "should return true if the button exists (how = :caption)" do
32
+ # we need to figure out what :text and :value/:caption means on input type="button" and <button /> elements
33
+ @ie.button(:caption, "Button 2").should exist
34
+ @ie.button(:caption, /Button 2/).should exist
35
+ end
36
+ it "should return true if the button exists (default how = :value)" do
37
+ @ie.button("Submit").should exist
38
+ end
39
+ it "should return false if the button doesn't exist" do
40
+ @ie.button(:id, "no_such_id").should_not exist
41
+ @ie.button(:id, /no_such_id/).should_not exist
42
+ @ie.button(:name, "no_such_name").should_not exist
43
+ @ie.button(:name, /no_such_name/).should_not exist
44
+ # we need to figure out what :text and :value/:caption means on input type="button" and <button /> elements
45
+ @ie.button(:value, "no_such_value").should_not exist
46
+ @ie.button(:value, /no_such_value/).should_not exist
47
+ @ie.button(:text, "no_such_text").should_not exist
48
+ @ie.button(:text, /no_such_text/).should_not exist
49
+ @ie.button(:class, "no_such_class").should_not exist
50
+ @ie.button(:class, /no_such_class/).should_not exist
51
+ @ie.button(:index, 1337).should_not exist
52
+ @ie.button(:xpath, "//input[@id='no_such_id']").should_not exist
53
+ end
54
+ it "should raise ArgumentError when what argument is invalid" do
55
+ lambda { @ie.button(:id, 3.14).exists? }.should raise_error(ArgumentError)
56
+ end
57
+ it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
58
+ lambda { @ie.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
59
+ end
60
+ end
61
+
62
+ # Attribute methods
63
+ describe "#class_name" do
64
+ it "should return the class name of the button" do
65
+ @ie.button(:name, "new_user_image").class_name.should == "image"
66
+ end
67
+ it "should return an empty string if the button has no class name" do
68
+ @ie.button(:name, "new_user_submit").class_name.should == ""
69
+ end
70
+ end
71
+
72
+ describe "#id" do
73
+ it "should return the id if the button exists" do
74
+ @ie.button(:index, 1).id.should == 'new_user_submit'
75
+ @ie.button(:index, 2).id.should == 'new_user_reset'
76
+ @ie.button(:index, 3).id.should == 'new_user_button'
77
+ end
78
+ it "should raise UnknownObjectException if button does not exist" do
79
+ lambda { @ie.button(:index, 1337).id }.should raise_error(UnknownObjectException)
80
+ end
81
+ end
82
+
83
+ describe "#name" do
84
+ it "should return the name if button exists" do
85
+ @ie.button(:index, 1).name.should == 'new_user_submit'
86
+ @ie.button(:index, 2).name.should == 'new_user_reset'
87
+ @ie.button(:index, 3).name.should == 'new_user_button'
88
+ end
89
+ it "should raise UnknownObjectException if button does not exist" do
90
+ lambda { @ie.button(:name, "no_such_name").name }.should raise_error(UnknownObjectException)
91
+ end
92
+ end
93
+
94
+ describe "#title" do
95
+ it "should return the title of the button" do
96
+ @ie.button(:index, 1).title.should == 'Submit the form'
97
+ end
98
+ it "should return an empty string for button without title" do
99
+ @ie.button(:index, 2).title.should == ''
100
+ end
101
+ end
102
+
103
+ describe "#type" do
104
+ it "should return the type if button exists" do
105
+ @ie.button(:index, 1).type.should == 'submit'
106
+ @ie.button(:index, 2).type.should == 'reset'
107
+ @ie.button(:index, 3).type.should == 'button'
108
+ end
109
+ it "should raise UnknownObjectException if button does not exist" do
110
+ lambda { @ie.button(:name, "no_such_name").type }.should raise_error(UnknownObjectException)
111
+ end
112
+ end
113
+
114
+ describe "#value" do
115
+ it "should return the value if button exists" do
116
+ @ie.button(:index, 1).value.should == 'Submit'
117
+ @ie.button(:index, 2).value.should == 'Reset'
118
+ @ie.button(:index, 3).value.should == 'Button'
119
+ end
120
+ it "should raise UnknownObjectException if button does not exist" do
121
+ lambda { @ie.button(:name, "no_such_name").value }.should raise_error(UnknownObjectException)
122
+ end
123
+ end
124
+
125
+ # Access methods
126
+ describe "#enabled?" do
127
+ it "should return true if the button is enabled" do
128
+ @ie.button(:name, 'new_user_submit').should be_enabled
129
+ end
130
+ it "should return false if the button is disabled" do
131
+ @ie.button(:name, 'new_user_submit_disabled').should_not be_enabled
132
+ end
133
+ it "should raise UnknownObjectException if the button doesn't exist" do
134
+ lambda { @ie.button(:name, "no_such_name").enabled? }.should raise_error(UnknownObjectException)
135
+ end
136
+ end
137
+
138
+ describe "#disabled?" do
139
+ it "should return false when button is enabled" do
140
+ @ie.button(:name, 'new_user_submit').should_not be_disabled
141
+ end
142
+ it "should return true when button is disabled" do
143
+ @ie.button(:name, 'new_user_submit_disabled').should be_disabled
144
+ end
145
+ it "should raise UnknownObjectException if button does not exist" do
146
+ lambda { @ie.button(:name, "no_such_name").disabled? }.should raise_error(UnknownObjectException)
147
+ end
148
+ end
149
+
150
+ # Manipulation methods
151
+ describe "#click" do
152
+ it "should click the button if it exists" do
153
+ pending
154
+ end
155
+ it "should fire events" do
156
+ @ie.button(:id, 'new_user_button').click
157
+ @ie.button(:id, 'new_user_button').value.should == 'new_value_set_by_onclick_event'
158
+ end
159
+ it "should raise UnknownObjectException when clicking a button that doesn't exist" do
160
+ lambda { @ie.button(:value, "no_such_value").click }.should raise_error(UnknownObjectException)
161
+ lambda { @ie.button(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
162
+ end
163
+ it "should raise ObjectDisabledException when clicking a disabled button" do
164
+ lambda { @ie.button(:value, "Disabled").click }.should raise_error(ObjectDisabledException)
165
+ end
166
+ end
167
+
168
+ after :all do
169
+ @ie.close
170
+ end
171
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Buttons" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
12
+ end
13
+
14
+ describe "#length" do
15
+ it "should return the number of buttons" do
16
+ @ie.buttons.length.should == 7
17
+ end
18
+ end
19
+
20
+ describe "#[]" do
21
+ it "should return the button at the given index" do
22
+ @ie.buttons[1].title.should == "Submit the form"
23
+ end
24
+ end
25
+
26
+ describe "#each" do
27
+ it "should iterate through buttons correctly" do
28
+ @ie.buttons.each_with_index do |b, index|
29
+ b.name.should == @ie.button(:index, index+1).name
30
+ b.id.should == @ie.button(:index, index+1).id
31
+ b.value.should == @ie.button(:index, index+1).value
32
+ end
33
+ end
34
+ end
35
+
36
+ after :all do
37
+ @ie.close
38
+ end
39
+
40
+ end
@@ -0,0 +1,259 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Checkbox" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
12
+ end
13
+
14
+
15
+ # Exists method
16
+
17
+ describe "#exists?" do
18
+ it "should return true if the checkbox button exists" do
19
+ @ie.checkbox(:id, "new_user_interests_books").should exist
20
+ @ie.checkbox(:id, /new_user_interests_books/).should exist
21
+ @ie.checkbox(:name, "new_user_interests").should exist
22
+ @ie.checkbox(:name, /new_user_interests/).should exist
23
+ @ie.checkbox(:value, "books").should exist
24
+ @ie.checkbox(:value, /books/).should exist
25
+ # unsure what :text is supposed to represent here
26
+ # @ie.checkbox(:text, "books").should exist
27
+ # @ie.checkbox(:text, /books/).should exist
28
+ @ie.checkbox(:class, "fun").should exist
29
+ @ie.checkbox(:class, /fun/).should exist
30
+ @ie.checkbox(:index, 1).should exist
31
+ @ie.checkbox(:xpath, "//input[@id='new_user_interests_books']").should exist
32
+ end
33
+
34
+ it "should return true if the checkbox button exists (search by name and value)" do
35
+ @ie.checkbox(:name, "new_user_interests", 'cars').should exist
36
+ @ie.checkbox(:xpath, "//input[@name='new_user_interests' and @value='cars']").set
37
+ end
38
+
39
+ it "should return false if the checkbox button does not exist" do
40
+ @ie.checkbox(:id, "no_such_id").should_not exist
41
+ @ie.checkbox(:id, /no_such_id/).should_not exist
42
+ @ie.checkbox(:name, "no_such_name").should_not exist
43
+ @ie.checkbox(:name, /no_such_name/).should_not exist
44
+ @ie.checkbox(:value, "no_such_value").should_not exist
45
+ @ie.checkbox(:value, /no_such_value/).should_not exist
46
+ @ie.checkbox(:text, "no_such_text").should_not exist
47
+ @ie.checkbox(:text, /no_such_text/).should_not exist
48
+ @ie.checkbox(:class, "no_such_class").should_not exist
49
+ @ie.checkbox(:class, /no_such_class/).should_not exist
50
+ @ie.checkbox(:index, 1337).should_not exist
51
+ @ie.checkbox(:xpath, "//input[@id='no_such_id']").should_not exist
52
+ end
53
+
54
+ it "should return false if the checkbox button does not exist (search by name and value)" do
55
+ @ie.checkbox(:name, "new_user_interests", 'no_such_value').should_not exist
56
+ @ie.checkbox(:xpath, "//input[@name='new_user_interests' and @value='no_such_value']").should_not exist
57
+ @ie.checkbox(:name, "no_such_name", 'cars').should_not exist
58
+ @ie.checkbox(:xpath, "//input[@name='no_such_name' and @value='cars']").should_not exist
59
+ end
60
+
61
+ it "should return true for checkboxs with a string value" do
62
+ @ie.checkbox(:name, 'new_user_interests', 'books').should exist
63
+ @ie.checkbox(:name, 'new_user_interests', 'cars').should exist
64
+ end
65
+
66
+ it "should raise ArgumentError when what argument is invalid" do
67
+ lambda { @ie.checkbox(:id, 3.14).exists? }.should raise_error(ArgumentError)
68
+ end
69
+
70
+ it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
71
+ lambda { @ie.checkbox(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
72
+ end
73
+ end
74
+
75
+
76
+ # Attribute methods
77
+
78
+ describe "#class_name" do
79
+ it "should return the class name if the checkbox exists and has an attribute" do
80
+ @ie.checkbox(:id, "new_user_interests_dancing").class_name.should == "fun"
81
+ end
82
+ it "should return an emptry string if the checkbox exists and the attribute doesn't" do
83
+ @ie.checkbox(:id, "new_user_interests_books").class_name.should == ""
84
+ end
85
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
86
+ lambda { @ie.checkbox(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
87
+ end
88
+ end
89
+
90
+ describe "#id" do
91
+ it "should return the id attribute if the checkbox exists and has an attribute" do
92
+ @ie.checkbox(:index, 1).id.should == "new_user_interests_books"
93
+ end
94
+ it "should return an emptry string if the checkbox exists and the attribute doesn't" do
95
+ @ie.checkbox(:index, 2).id.should == ""
96
+ end
97
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
98
+ lambda { @ie.checkbox(:index, 1337).id }.should raise_error(UnknownObjectException)
99
+ end
100
+ end
101
+
102
+ describe "#name" do
103
+ it "should return the name attribute if the checkbox exists" do
104
+ @ie.checkbox(:id, 'new_user_interests_books').name.should == "new_user_interests"
105
+ end
106
+ it "should return an empty string if the checkbox exists and the attribute doesn't" do
107
+ @ie.checkbox(:id, 'new_user_interests_food').name.should == ""
108
+ end
109
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
110
+ lambda { @ie.checkbox(:index, 1337).name }.should raise_error(UnknownObjectException)
111
+ end
112
+ end
113
+
114
+ describe "#title" do
115
+ it "should return the title attribute if the checkbox exists" do
116
+ @ie.checkbox(:id, "new_user_interests_dancing").title.should == "Dancing is fun!"
117
+ end
118
+ it "should return an emptry string if the checkbox exists and the attribute doesn't" do
119
+ @ie.checkbox(:id, "new_user_interests_books").title.should == ""
120
+ end
121
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
122
+ lambda { @ie.checkbox(:index, 1337).title }.should raise_error(UnknownObjectException)
123
+ end
124
+ end
125
+
126
+ describe "#type" do
127
+ it "should return the type attribute if the checkbox exists" do
128
+ @ie.checkbox(:index, 1).type.should == "checkbox"
129
+ end
130
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
131
+ lambda { @ie.checkbox(:index, 1337).type }.should raise_error(UnknownObjectException)
132
+ end
133
+ end
134
+
135
+ describe "#value" do
136
+ it "should return the value attribute if the checkbox exists" do
137
+ @ie.checkbox(:id, 'new_user_interests_books').value.should == 'books'
138
+ end
139
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
140
+ lambda { @ie.checkbox(:index, 1337).value}.should raise_error(UnknownObjectException)
141
+ end
142
+ end
143
+
144
+
145
+ # Access methods
146
+
147
+ describe "#enabled?" do
148
+ it "should return true if the checkbox button is enabled" do
149
+ @ie.checkbox(:id, "new_user_interests_books").should be_enabled
150
+ @ie.checkbox(:xpath, "//input[@id='new_user_interests_books']").should be_enabled
151
+ end
152
+ it "should return false if the checkbox button is disabled" do
153
+ @ie.checkbox(:id, "new_user_interests_dentistry").should_not be_enabled
154
+ @ie.checkbox(:xpath,"//input[@id='new_user_interests_dentistry']").should_not be_enabled
155
+ end
156
+ it "should raise UnknownObjectException if the checkbox button doesn't exist" do
157
+ lambda { @ie.checkbox(:id, "no_such_id").enabled? }.should raise_error(UnknownObjectException)
158
+ lambda { @ie.checkbox(:xpath, "//input[@id='no_such_id']").enabled? }.should raise_error(UnknownObjectException)
159
+ end
160
+ end
161
+
162
+ describe "#disabled?" do
163
+ it "should return true if the checkbox is disabled" do
164
+ @ie.checkbox(:id, 'new_user_interests_dentistry').should be_disabled
165
+ end
166
+ it "should return false if the checkbox is enabled" do
167
+ @ie.checkbox(:id, 'new_user_interests_books').should_not be_disabled
168
+ end
169
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
170
+ lambda { @ie.checkbox(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
171
+ end
172
+ end
173
+
174
+
175
+ # Manipulation methods
176
+
177
+ describe "#clear" do
178
+ it "should raise ObjectDisabledException if the checkbox is disabled" do
179
+ @ie.checkbox(:id, "new_user_interests_dentistry").should_not be_set
180
+ lambda { @ie.checkbox(:id, "new_user_interests_dentistry").clear }.should raise_error(ObjectDisabledException)
181
+ lambda { @ie.checkbox(:xpath, "//input[@id='new_user_interests_dentistry']").clear }.should raise_error(ObjectDisabledException)
182
+ end
183
+ it "should clear the checkbox button if it is set" do
184
+ @ie.checkbox(:id, "new_user_interests_books").clear
185
+ @ie.checkbox(:id, "new_user_interests_books").should_not be_set
186
+ end
187
+ it "should clear the checkbox button when found by :xpath" do
188
+ @ie.checkbox(:xpath, "//input[@id='new_user_interests_books']").clear
189
+ @ie.checkbox(:xpath, "//input[@id='new_user_interests_books']").should_not be_set
190
+ end
191
+ it "should raise UnknownObjectException if the checkbox button doesn't exist" do
192
+ lambda { @ie.checkbox(:name, "no_such_id").clear }.should raise_error(UnknownObjectException)
193
+ lambda { @ie.checkbox(:xpath, "//input[@id='no_such_id']").clear }.should raise_error(UnknownObjectException)
194
+ end
195
+ end
196
+
197
+ describe "#set" do
198
+ it "should set the checkbox button" do
199
+ @ie.checkbox(:id, "new_user_interests_cars").set
200
+ @ie.checkbox(:id, "new_user_interests_cars").should be_set
201
+ end
202
+ it "should set the checkbox button when found by :xpath" do
203
+ @ie.checkbox(:xpath, "//input[@id='new_user_interests_cars']").set
204
+ @ie.checkbox(:xpath, "//input[@id='new_user_interests_cars']").should be_set
205
+ end
206
+
207
+ it "should fire the onclick event"
208
+
209
+ it "should raise UnknownObjectException if the checkbox button doesn't exist" do
210
+ lambda { @ie.checkbox(:name, "no_such_name").set }.should raise_error(UnknownObjectException)
211
+ lambda { @ie.checkbox(:xpath, "//input[@name='no_such_name']").set }.should raise_error(UnknownObjectException)
212
+ end
213
+ it "should raise ObjectDisabledException if the checkbox is disabled" do
214
+ lambda { @ie.checkbox(:id, "new_user_interests_dentistry").set }.should raise_error(ObjectDisabledException)
215
+ lambda { @ie.checkbox(:xpath, "//input[@id='new_user_interests_dentistry']").set }.should raise_error(ObjectDisabledException )
216
+ end
217
+ end
218
+
219
+
220
+ # Other
221
+
222
+ describe '#set?' do
223
+ it "should return true if the checkbox button is set" do
224
+ @ie.checkbox(:id, "new_user_interests_books").should be_set
225
+ end
226
+ it "should return false if the checkbox button unset" do
227
+ @ie.checkbox(:id, "new_user_interests_cars").should_not be_set
228
+ end
229
+ it "should return the state for checkboxs with string values" do
230
+ @ie.checkbox(:name, "new_user_interests", 'cars').should_not be_set
231
+ @ie.checkbox(:name, "new_user_interests", 'cars').set
232
+ @ie.checkbox(:name, "new_user_interests", 'cars').should be_set
233
+ @ie.checkbox(:name, "new_user_interests", 'cars').clear
234
+ @ie.checkbox(:name, "new_user_interests", 'cars').should_not be_set
235
+ end
236
+ it "should raise UnknownObjectException if the checkbox button doesn't exist" do
237
+ lambda { @ie.checkbox(:id, "no_such_id").set? }.should raise_error(UnknownObjectException)
238
+ lambda { @ie.checkbox(:xpath, "//input[@id='no_such_id']").set? }.should raise_error(UnknownObjectException)
239
+ end
240
+ end
241
+
242
+ describe "#get_state" do
243
+ it "should return true if the checkbox is set" do
244
+ @ie.checkbox(:id, "new_user_interests_books").get_state.should be_true
245
+ end
246
+ it "should return false if the checkbox is unset" do
247
+ @ie.checkbox(:id, "new_user_interests_cars").get_state.should be_false
248
+ end
249
+ it "should raise UnknownObjectException if the checkbox doesn't exist" do
250
+ lambda { @ie.checkbox(:name, "no_such_name").get_state }.should raise_error(UnknownObjectException)
251
+ lambda { @ie.checkbox(:xpath, "//input[@name='no_such_name']").get_state }.should raise_error(UnknownObjectException)
252
+ end
253
+ end
254
+
255
+ after :all do
256
+ @ie.close
257
+ end
258
+ end
259
+