celerity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +621 -0
- data/README.txt +58 -0
- data/Rakefile +4 -0
- data/lib/celerity.rb +47 -0
- data/lib/celerity/clickable_element.rb +11 -0
- data/lib/celerity/collections.rb +99 -0
- data/lib/celerity/container.rb +369 -0
- data/lib/celerity/disabled_element.rb +20 -0
- data/lib/celerity/element.rb +114 -0
- data/lib/celerity/element_collections.rb +67 -0
- data/lib/celerity/elements/button.rb +13 -0
- data/lib/celerity/elements/file_field.rb +12 -0
- data/lib/celerity/elements/form.rb +15 -0
- data/lib/celerity/elements/frame.rb +44 -0
- data/lib/celerity/elements/image.rb +70 -0
- data/lib/celerity/elements/label.rb +10 -0
- data/lib/celerity/elements/link.rb +13 -0
- data/lib/celerity/elements/radio_check.rb +59 -0
- data/lib/celerity/elements/select_list.rb +84 -0
- data/lib/celerity/elements/table.rb +94 -0
- data/lib/celerity/elements/table_body.rb +38 -0
- data/lib/celerity/elements/table_cell.rb +30 -0
- data/lib/celerity/elements/table_row.rb +34 -0
- data/lib/celerity/elements/text_field.rb +80 -0
- data/lib/celerity/exception.rb +48 -0
- data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
- data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
- data/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
- data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
- data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
- data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
- data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
- data/lib/celerity/htmlunit/nekohtml-1.9.7.jar +0 -0
- data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
- data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
- data/lib/celerity/htmlunit/xercesImpl-2.8.1.jar +0 -0
- data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
- data/lib/celerity/ie.rb +126 -0
- data/lib/celerity/input_element.rb +29 -0
- data/lib/celerity/non_control_elements.rb +50 -0
- data/lib/celerity/version.rb +9 -0
- data/setup.rb +1585 -0
- data/spec/area_spec.rb +79 -0
- data/spec/areas_spec.rb +41 -0
- data/spec/button_spec.rb +171 -0
- data/spec/buttons_spec.rb +40 -0
- data/spec/checkbox_spec.rb +259 -0
- data/spec/checkboxes_spec.rb +39 -0
- data/spec/div_spec.rb +174 -0
- data/spec/divs_spec.rb +40 -0
- data/spec/element_spec.rb +29 -0
- data/spec/filefield_spec.rb +110 -0
- data/spec/filefields_spec.rb +41 -0
- data/spec/form_spec.rb +53 -0
- data/spec/forms_spec.rb +42 -0
- data/spec/frame_spec.rb +103 -0
- data/spec/hidden_spec.rb +105 -0
- data/spec/hiddens_spec.rb +40 -0
- data/spec/html/forms_with_input_elements.html +107 -0
- data/spec/html/frame_1.html +17 -0
- data/spec/html/frame_2.html +16 -0
- data/spec/html/frames.html +11 -0
- data/spec/html/iframes.html +12 -0
- data/spec/html/images.html +24 -0
- data/spec/html/images/1.gif +0 -0
- data/spec/html/images/2.gif +0 -0
- data/spec/html/images/3.gif +0 -0
- data/spec/html/images/button.jpg +0 -0
- data/spec/html/images/circle.jpg +0 -0
- data/spec/html/images/map.gif +0 -0
- data/spec/html/images/map2.gif +0 -0
- data/spec/html/images/minus.gif +0 -0
- data/spec/html/images/originaltriangle.jpg +0 -0
- data/spec/html/images/plus.gif +0 -0
- data/spec/html/images/square.jpg +0 -0
- data/spec/html/images/triangle.jpg +0 -0
- data/spec/html/non_control_elements.html +85 -0
- data/spec/html/tables.html +119 -0
- data/spec/ie_spec.rb +146 -0
- data/spec/image_spec.rb +210 -0
- data/spec/images_spec.rb +39 -0
- data/spec/label_spec.rb +65 -0
- data/spec/labels_spec.rb +41 -0
- data/spec/li_spec.rb +114 -0
- data/spec/link_spec.rb +147 -0
- data/spec/links_spec.rb +43 -0
- data/spec/lis_spec.rb +40 -0
- data/spec/map_spec.rb +83 -0
- data/spec/maps_spec.rb +41 -0
- data/spec/p_spec.rb +140 -0
- data/spec/pre_spec.rb +110 -0
- data/spec/pres_spec.rb +41 -0
- data/spec/ps_spec.rb +40 -0
- data/spec/radio_spec.rb +260 -0
- data/spec/radios_spec.rb +43 -0
- data/spec/select_list_spec.rb +286 -0
- data/spec/select_lists_spec.rb +47 -0
- data/spec/span_spec.rb +156 -0
- data/spec/spans_spec.rb +65 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +90 -0
- data/spec/table_bodies.rb +40 -0
- data/spec/table_bodies_spec.rb +42 -0
- data/spec/table_body_spec.rb +72 -0
- data/spec/table_cell_spec.rb +61 -0
- data/spec/table_cells_spec.rb +60 -0
- data/spec/table_row_spec.rb +59 -0
- data/spec/table_rows_spec.rb +57 -0
- data/spec/table_spec.rb +111 -0
- data/spec/tables_spec.rb +42 -0
- data/spec/text_field_spec.rb +234 -0
- data/spec/text_fields_spec.rb +45 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +23 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/testserver.rake +17 -0
- metadata +174 -0
data/spec/lis_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Lis" do
|
4
|
+
before :all do
|
5
|
+
@ie = IE.new
|
6
|
+
add_spec_checker(@ie)
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@ie.goto(TEST_HOST + "/non_control_elements.html")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#length" do
|
14
|
+
it "should return the number of lis" do
|
15
|
+
@ie.lis.length.should == 7
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#[]" do
|
20
|
+
it "should return the p at the given index" do
|
21
|
+
@ie.lis[5].id.should == "non_link_1"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#each" do
|
26
|
+
it "should iterate through lis correctly" do
|
27
|
+
@ie.lis.each_with_index do |l, index|
|
28
|
+
l.name.should == @ie.li(:index, index+1).name
|
29
|
+
l.id.should == @ie.li(:index, index+1).id
|
30
|
+
l.value.should == @ie.li(:index, index+1).value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after :all do
|
36
|
+
@ie.close
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
data/spec/map_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
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 'map' exists" do
|
17
|
+
@ie.map(:id, "triangle_map").should exist
|
18
|
+
@ie.map(:id, /triangle_map/).should exist
|
19
|
+
@ie.map(:name, "triangle_map").should exist
|
20
|
+
@ie.map(:name, /triangle_map/).should exist
|
21
|
+
@ie.map(:index, 1).should exist
|
22
|
+
@ie.map(:xpath, "//map[@id='triangle_map']").should exist
|
23
|
+
end
|
24
|
+
it "should return false if the 'map' doesn't exist" do
|
25
|
+
@ie.map(:id, "no_such_id").should_not exist
|
26
|
+
@ie.map(:id, /no_such_id/).should_not exist
|
27
|
+
@ie.map(:name, "no_such_id").should_not exist
|
28
|
+
@ie.map(:name, /no_such_id/).should_not exist
|
29
|
+
@ie.map(:index, 1337).should_not exist
|
30
|
+
@ie.map(:xpath, "//map[@id='no_such_id']").should_not exist
|
31
|
+
end
|
32
|
+
it "should raise ArgumentError when what argument is invalid" do
|
33
|
+
lambda { @ie.map(:id, 3.14).exists? }.should raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
|
36
|
+
lambda { @ie.map(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Attribute methods
|
41
|
+
describe "#id" do
|
42
|
+
it "should return the id attribute" do
|
43
|
+
@ie.map(:index, 1).id.should == "triangle_map"
|
44
|
+
end
|
45
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
46
|
+
@ie.map(:index, 2).id.should == ''
|
47
|
+
end
|
48
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
49
|
+
lambda { @ie.map(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
50
|
+
lambda { @ie.map(:index, 1337).id }.should raise_error(UnknownObjectException)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#name" do
|
55
|
+
it "should return the name attribute" do
|
56
|
+
@ie.map(:index, 1).name.should == "triangle_map"
|
57
|
+
end
|
58
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
59
|
+
@ie.map(:index, 2).name.should == ''
|
60
|
+
end
|
61
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
62
|
+
lambda { @ie.map(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
|
63
|
+
lambda { @ie.map(:index, 1337).name }.should raise_error(UnknownObjectException)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Other
|
68
|
+
describe "#to_s" do
|
69
|
+
it "should return a human readable representation of the element" do
|
70
|
+
@ie.map(:index, 1).to_s.should == "tag: map\n" +
|
71
|
+
" id: triangle_map\n" +
|
72
|
+
" name: triangle_map"
|
73
|
+
end
|
74
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
75
|
+
lambda { @ie.map(:xpath, "//map[@id='no_such_id']").to_s }.should raise_error( UnknownObjectException)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
after :all do
|
80
|
+
@ie.close
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/maps_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Maps" 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 maps" do
|
16
|
+
@ie.maps.length.should == 2
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#[]" do
|
21
|
+
it "should return the p at the given index" do
|
22
|
+
@ie.maps[1].id.should == "triangle_map"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#each" do
|
27
|
+
it "should iterate through maps correctly" do
|
28
|
+
@ie.maps.each_with_index do |m, index|
|
29
|
+
m.name.should == @ie.map(:index, index+1).name
|
30
|
+
m.id.should == @ie.map(:index, index+1).id
|
31
|
+
m.value.should == @ie.map(:index, index+1).value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after :all do
|
37
|
+
@ie.close
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
data/spec/p_spec.rb
ADDED
@@ -0,0 +1,140 @@
|
|
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 + "/non_control_elements.html")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Exists method
|
15
|
+
describe "#exist?" do
|
16
|
+
it "should return true if the 'p' exists" do
|
17
|
+
@ie.p(:id, "lead").should exist
|
18
|
+
@ie.p(:id, /lead/).should exist
|
19
|
+
@ie.p(:text, "Dubito, ergo cogito, ergo sum.").should exist
|
20
|
+
@ie.p(:text, /Dubito, ergo cogito, ergo sum/).should exist
|
21
|
+
@ie.p(:class, "lead").should exist
|
22
|
+
@ie.p(:class, /lead/).should exist
|
23
|
+
@ie.p(:index, 1).should exist
|
24
|
+
@ie.p(:xpath, "//p[@id='lead']").should exist
|
25
|
+
end
|
26
|
+
it "should return false if the 'p' doesn't exist" do
|
27
|
+
@ie.p(:id, "no_such_id").should_not exist
|
28
|
+
@ie.p(:id, /no_such_id/).should_not exist
|
29
|
+
@ie.p(:text, "no_such_text").should_not exist
|
30
|
+
@ie.p(:text, /no_such_text/).should_not exist
|
31
|
+
@ie.p(:class, "no_such_class").should_not exist
|
32
|
+
@ie.p(:class, /no_such_class/).should_not exist
|
33
|
+
@ie.p(:index, 1337).should_not exist
|
34
|
+
@ie.p(:xpath, "//p[@id='no_such_id']").should_not exist
|
35
|
+
end
|
36
|
+
it "should raise ArgumentError when what argument is invalid" do
|
37
|
+
lambda { @ie.p(:id, 3.14).exists? }.should raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
|
40
|
+
lambda { @ie.p(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Attribute methods
|
45
|
+
describe "#class_name" do
|
46
|
+
it "should return the class attribute" do
|
47
|
+
@ie.p(:index, 1).class_name.should == 'lead'
|
48
|
+
end
|
49
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
50
|
+
@ie.p(:index, 3).class_name.should == ''
|
51
|
+
end
|
52
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
53
|
+
lambda { @ie.p(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#id" do
|
58
|
+
it "should return the id attribute" do
|
59
|
+
@ie.p(:index, 1).id.should == "lead"
|
60
|
+
end
|
61
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
62
|
+
@ie.p(:index, 3).id.should == ''
|
63
|
+
end
|
64
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
65
|
+
lambda { @ie.p(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
66
|
+
lambda { @ie.p(:index, 1337).id }.should raise_error(UnknownObjectException)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#name" do
|
71
|
+
it "should return the name attribute" do
|
72
|
+
@ie.p(:index, 2).name.should == "invalid_attribute"
|
73
|
+
end
|
74
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
75
|
+
@ie.p(:index, 3).name.should == ''
|
76
|
+
end
|
77
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
78
|
+
lambda { @ie.p(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
|
79
|
+
lambda { @ie.p(:index, 1337).name }.should raise_error(UnknownObjectException)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#title" do
|
84
|
+
it "should return the title attribute" do
|
85
|
+
@ie.p(:index, 1).title.should == 'Lorem ipsum'
|
86
|
+
end
|
87
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
88
|
+
@ie.p(:index, 3).title.should == ''
|
89
|
+
end
|
90
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
91
|
+
lambda { @ie.p(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
|
92
|
+
lambda { @ie.p(:xpath, "//p[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#text" do
|
97
|
+
it "should return the text of the p" do
|
98
|
+
@ie.p(:index, 2).text.should == 'Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'
|
99
|
+
end
|
100
|
+
it "should return an empty string if the element doesn't contain any text" do
|
101
|
+
@ie.p(:index, 5).text.should == ''
|
102
|
+
end
|
103
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
104
|
+
lambda { @ie.p(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
|
105
|
+
lambda { @ie.p(:xpath , "//p[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#value" do
|
110
|
+
it "should return the value attribute" do
|
111
|
+
@ie.p(:index, 2).value.should == "invalid_attribute"
|
112
|
+
end
|
113
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
114
|
+
@ie.p(:index, 3).value.should == ''
|
115
|
+
end
|
116
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
117
|
+
lambda { @ie.p(:id , "no_such_id").value }.should raise_error(UnknownObjectException)
|
118
|
+
lambda { @ie.p(:index , 1337).value }.should raise_error(UnknownObjectException)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Other
|
123
|
+
describe "#to_s" do
|
124
|
+
it "should return a human readable representation of the element" do
|
125
|
+
@ie.p(:index, 1).to_s.should == "tag: p\n" +
|
126
|
+
" id: lead\n" +
|
127
|
+
" class: lead\n" +
|
128
|
+
" title: Lorem ipsum\n" +
|
129
|
+
" text: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur eu pede. Ut justo. Praesent feugiat, elit in feugiat iaculis, sem risus rutrum justo, eget fermentum dolor arcu non nunc."
|
130
|
+
end
|
131
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
132
|
+
lambda { @ie.p(:xpath, "//p[@id='no_such_id']").to_s }.should raise_error( UnknownObjectException)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
after :all do
|
137
|
+
@ie.close
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
data/spec/pre_spec.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Pre" 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 + "/non_control_elements.html")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Exists method
|
15
|
+
describe "#exist?" do
|
16
|
+
it "should return true if the 'p' exists" do
|
17
|
+
@ie.pre(:id, "rspec").should exist
|
18
|
+
@ie.pre(:id, /rspec/).should exist
|
19
|
+
@ie.pre(:text, '@ie.pre(:id, "rspec").should exist').should exist
|
20
|
+
@ie.pre(:text, /@ie\.pre/).should exist
|
21
|
+
@ie.pre(:class, "ruby").should exist
|
22
|
+
@ie.pre(:class, /ruby/).should exist
|
23
|
+
@ie.pre(:index, 1).should exist
|
24
|
+
@ie.pre(:xpath, "//pre[@id='rspec']").should exist
|
25
|
+
end
|
26
|
+
it "should return false if the 'p' doesn't exist" do
|
27
|
+
@ie.pre(:id, "no_such_id").should_not exist
|
28
|
+
@ie.pre(:id, /no_such_id/).should_not exist
|
29
|
+
@ie.pre(:text, "no_such_text").should_not exist
|
30
|
+
@ie.pre(:text, /no_such_text/).should_not exist
|
31
|
+
@ie.pre(:class, "no_such_class").should_not exist
|
32
|
+
@ie.pre(:class, /no_such_class/).should_not exist
|
33
|
+
@ie.pre(:index, 1337).should_not exist
|
34
|
+
@ie.pre(:xpath, "//pre[@id='no_such_id']").should_not exist
|
35
|
+
end
|
36
|
+
it "should raise ArgumentError when what argument is invapred" do
|
37
|
+
lambda { @ie.pre(:id, 3.14).exists? }.should raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
it "should raise MissingWayOfFindingObjectException when how argument is invapred" do
|
40
|
+
lambda { @ie.pre(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Attribute methods
|
45
|
+
describe "#class_name" do
|
46
|
+
it "should return the class attribute" do
|
47
|
+
@ie.pre(:id, 'rspec').class_name.should == 'ruby'
|
48
|
+
end
|
49
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
50
|
+
@ie.pre(:index, 1).class_name.should == ''
|
51
|
+
end
|
52
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
53
|
+
lambda { @ie.pre(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#id" do
|
58
|
+
it "should return the id attribute" do
|
59
|
+
@ie.pre(:class, 'ruby').id.should == "rspec"
|
60
|
+
end
|
61
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
62
|
+
@ie.pre(:index, 1).id.should == ''
|
63
|
+
end
|
64
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
65
|
+
lambda { @ie.pre(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
66
|
+
lambda { @ie.pre(:index, 1337).id }.should raise_error(UnknownObjectException)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#title" do
|
71
|
+
it "should return the title attribute" do
|
72
|
+
@ie.pre(:class, 'brainfuck').title.should == 'The brainfuck language is an esoteric programming language noted for its extreme minimalism'
|
73
|
+
end
|
74
|
+
it "should return an empty string if the element exists and the attribute doesn't" do
|
75
|
+
@ie.pre(:index, 1).title.should == ''
|
76
|
+
end
|
77
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
78
|
+
lambda { @ie.pre(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
|
79
|
+
lambda { @ie.pre(:xpath, "//pre[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#text" do
|
84
|
+
it "should return the text of the p" do
|
85
|
+
@ie.pre(:class, 'haskell').text.should == 'main = putStrLn "Hello World"'
|
86
|
+
end
|
87
|
+
it "should return an empty string if the element doesn't contain any text" do
|
88
|
+
@ie.pre(:index, 1).text.should == ''
|
89
|
+
end
|
90
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
91
|
+
lambda { @ie.pre(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
|
92
|
+
lambda { @ie.pre(:xpath , "//pre[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Other
|
97
|
+
describe "#to_s" do
|
98
|
+
it "should return a human readable representation of the element" do
|
99
|
+
@ie.pre(:index, 1).to_s.should == "tag: pre"
|
100
|
+
end
|
101
|
+
it "should raise UnknownObjectException if the p doesn't exist" do
|
102
|
+
lambda { @ie.pre(:xpath, "//pre[@id='no_such_id']").to_s }.should raise_error( UnknownObjectException)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
after :all do
|
107
|
+
@ie.close
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
data/spec/pres_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Pres" 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 + "/non_control_elements.html")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#length" do
|
15
|
+
it "should return the number of pres" do
|
16
|
+
@ie.pres.length.should == 7
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#[]" do
|
21
|
+
it "should return the pre at the given index" do
|
22
|
+
@ie.pres[2].id.should == "rspec"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#each" do
|
27
|
+
it "should iterate through pres correctly" do
|
28
|
+
@ie.pres.each_with_index do |p, index|
|
29
|
+
p.name.should == @ie.pre(:index, index+1).name
|
30
|
+
p.id.should == @ie.pre(:index, index+1).id
|
31
|
+
p.value.should == @ie.pre(:index, index+1).value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after :all do
|
37
|
+
@ie.close
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|