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,47 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "SelectLists" do
4
+ before :all do
5
+ @ie = Celerity::IE.new
6
+ add_spec_checker(@ie)
7
+ end
8
+
9
+ before :each do
10
+ @ie.goto(TEST_HOST + "/forms_with_input_elements.html")
11
+ end
12
+
13
+ describe "#length" do
14
+ it "should return the correct number of select lists on the page" do
15
+ @ie.select_lists.length.should == 4
16
+ end
17
+ end
18
+
19
+ describe "#[]" do
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"
25
+ end
26
+ end
27
+
28
+ describe "#each" do
29
+ it "should iterate through the select lists correctly" do
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
36
+ index += 1
37
+ end
38
+ (index - 1).should == @ie.select_lists.length
39
+ end
40
+ end
41
+
42
+ after :all do
43
+ @ie.close
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,156 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Span" 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.span(:id, "lead").should exist
18
+ @ie.span(:id, /lead/).should exist
19
+ @ie.span(:text, "Dubito, ergo cogito, ergo sum.").should exist
20
+ @ie.span(:text, /Dubito, ergo cogito, ergo sum/).should exist
21
+ @ie.span(:class, "lead").should exist
22
+ @ie.span(:class, /lead/).should exist
23
+ @ie.span(:index, 1).should exist
24
+ @ie.span(:xpath, "//span[@id='lead']").should exist
25
+ end
26
+ it "should return false if the 'p' doesn't exist" do
27
+ @ie.span(:id, "no_such_id").should_not exist
28
+ @ie.span(:id, /no_such_id/).should_not exist
29
+ @ie.span(:text, "no_such_text").should_not exist
30
+ @ie.span(:text, /no_such_text/).should_not exist
31
+ @ie.span(:class, "no_such_class").should_not exist
32
+ @ie.span(:class, /no_such_class/).should_not exist
33
+ @ie.span(:index, 1337).should_not exist
34
+ @ie.span(:xpath, "//span[@id='no_such_id']").should_not exist
35
+ end
36
+ it "should raise ArgumentError when what argument is invalid" do
37
+ lambda { @ie.span(:id, 3.14).exists? }.should raise_error(ArgumentError)
38
+ end
39
+ it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
40
+ lambda { @ie.span(: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.span(: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.span(:index, 3).class_name.should == ''
51
+ end
52
+ it "should raise UnknownObjectException if the span doesn't exist" do
53
+ lambda { @ie.span(: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.span(: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.span(:index, 3).id.should == ''
63
+ end
64
+ it "should raise UnknownObjectException if the span doesn't exist" do
65
+ lambda { @ie.span(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
66
+ lambda { @ie.span(: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.span(: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.span(:index, 3).name.should == ''
76
+ end
77
+ it "should raise UnknownObjectException if the span doesn't exist" do
78
+ lambda { @ie.span(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
79
+ lambda { @ie.span(: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.span(: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.span(:index, 3).title.should == ''
89
+ end
90
+ it "should raise UnknownObjectException if the p doesn't exist" do
91
+ lambda { @ie.span(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
92
+ lambda { @ie.span(:xpath, "//span[@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.span(: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.span(:index, 5).text.should == ''
102
+ end
103
+ it "should raise UnknownObjectException if the p doesn't exist" do
104
+ lambda { @ie.span(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
105
+ lambda { @ie.span(:xpath , "//span[@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.span(: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.span(:index, 3).value.should == ''
115
+ end
116
+ it "should raise UnknownObjectException if the p doesn't exist" do
117
+ lambda { @ie.span(:id , "no_such_id").value }.should raise_error(UnknownObjectException)
118
+ lambda { @ie.span(:index , 1337).value }.should raise_error(UnknownObjectException)
119
+ end
120
+ end
121
+
122
+ # Other
123
+ describe "#click" do
124
+ it "should fire events" do
125
+ @ie.span(:id, 'footer').text.include?('Javascript').should_not be_true
126
+ @ie.span(:id, 'footer').click
127
+ @ie.span(:id, 'footer').text.include?('Javascript').should be_true
128
+ end
129
+ it "should raise UnknownObjectException if the span doesn't exist" do
130
+ lambda { @ie.span(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
131
+ lambda { @ie.span(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
132
+ end
133
+ end
134
+
135
+ describe "#to_s" do
136
+ it "should return a human readable representation of the element" do
137
+ @ie.span(:index, 2).to_s.should == "tag: span\n" +
138
+ " name: invalid_attribute\n" +
139
+ " value: invalid_attribute\n" +
140
+ " text: 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."
141
+ end
142
+ it "should raise UnknownObjectException if the p doesn't exist" do
143
+ lambda { @ie.span(:xpath, "//span[@id='no_such_id']").to_s }.should raise_error( UnknownObjectException)
144
+ end
145
+ end
146
+
147
+
148
+
149
+
150
+
151
+ after :all do
152
+ @ie.close
153
+ end
154
+
155
+ end
156
+
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Spans" 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
+
14
+ describe "#length" do
15
+ it "should return the number of spans" do
16
+ @ie.spans.length.should == 6
17
+ end
18
+ end
19
+
20
+ describe "#[]" do
21
+ it "should return the p at the given index" do
22
+ @ie.spans[1].id.should == "lead"
23
+ end
24
+ end
25
+
26
+ describe "#each" do
27
+ it "should iterate through spans correctly" do
28
+ @ie.spans.each_with_index do |s, index|
29
+ s.name.should == @ie.span(:index, index+1).name
30
+ s.id.should == @ie.span(:index, index+1).id
31
+ s.value.should == @ie.span(:index, index+1).value
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#to_s" do
37
+ it "should return a human readable representation of the collection" do
38
+ @ie.spans.to_s.should == "tag: span\n" +
39
+ " id: lead\n" +
40
+ " class: lead\n" +
41
+ " title: Lorem ipsum\n" +
42
+ " 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.\n" +
43
+ "tag: span\n" +
44
+ " name: invalid_attribute\n" +
45
+ " value: invalid_attribute\n" +
46
+ " text: 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.\n" +
47
+ "tag: span\n" +
48
+ " text: Suspendisse at ipsum a turpis viverra venenatis. Praesent ut nibh. Nullam eu odio. Donec tempor, elit ut lacinia porttitor, augue neque vehicula diam, in elementum ligula nisi a tellus. Aliquam vestibulum ultricies tortor. \n" +
49
+ "tag: span\n" +
50
+ " text: Dubito, ergo cogito, ergo sum.\n" +
51
+ "tag: span\n" +
52
+ "tag: span\n" +
53
+ " class: footer\n" +
54
+ " name: footer\n" +
55
+ " onclick: this.innerHTML = 'This is a footer with text set by Javascript.'\n" +
56
+ " text: This is a footer."
57
+ end
58
+ end
59
+
60
+ after :all do
61
+ @ie.close
62
+ end
63
+
64
+ end
65
+
@@ -0,0 +1 @@
1
+ --colour --format html
@@ -0,0 +1,90 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ # require "profile"
10
+
11
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
12
+
13
+ if RUBY_PLATFORM =~ /java/
14
+ require 'celerity'
15
+ include Celerity
16
+ include Celerity::Exception
17
+ elsif ENV['WATIR_SPEC']
18
+ require 'watir'
19
+ include Watir
20
+ include Watir::Exception
21
+ end
22
+
23
+ # ============
24
+ # = Debugger =
25
+ # ============
26
+
27
+ if ENV['DEBUGGER']
28
+ require "ruby-debug"
29
+ Debugger.start
30
+ Debugger.settings[:autoeval] = true
31
+ Debugger.settings[:autolist] = 1
32
+ end
33
+
34
+ # ===========
35
+ # = WEBrick =
36
+ # ===========
37
+
38
+ if RUBY_PLATFORM =~ /java/ || ENV['WATIR_SPEC']
39
+ unless defined? WEBRICK_SERVER
40
+ require 'webrick'
41
+ doc_root = File.join(File.dirname(__FILE__), "html")
42
+ log_file = File.join(File.dirname(__FILE__), "..", "log", "webrick_log.txt")
43
+ server_port = 2000
44
+ tries = 0
45
+ begin
46
+ TEST_HOST = "http://localhost:#{server_port}"
47
+ server = WEBrick::HTTPServer.new(:Port => server_port,
48
+ :DocumentRoot => doc_root,
49
+ :Logger => WEBrick::Log.new(log_file, WEBrick::BasicLog::WARN),
50
+ :AccessLog => [])
51
+ rescue Errno::EADDRINUSE => e
52
+ server_port += 5
53
+ if tries < 3
54
+ tries += 1
55
+ retry
56
+ else
57
+ raise e
58
+ end
59
+ end
60
+
61
+ server.mount("/", WEBrick::HTTPServlet::FileHandler, doc_root, {:FancyIndexing=>true})
62
+ WEBRICK_SERVER = Thread.new { server.start }
63
+ end
64
+ else
65
+ puts "Remember to run \"rake testserver\" before running these tests!"
66
+ end
67
+
68
+ # ===========================
69
+ # = RubyCocoa CelerityViewer =
70
+ # ===========================
71
+ begin
72
+ if `uname`.chomp == "Darwin" && `ps ax`[/CelerityViewer/]
73
+ WEB_VIEWER = DRbObject.new_with_uri("druby://127.0.0.1:1337")
74
+ end
75
+ rescue IOError
76
+ end
77
+
78
+ # ================
79
+ # = Spec Checker =
80
+ # ================
81
+
82
+ # define a checker that is run on every page
83
+ def add_spec_checker(ie)
84
+ if defined? WEB_VIEWER
85
+ ie.add_checker { WEB_VIEWER.render_html(ie.object.asXml, ie.base_url) }
86
+ end
87
+ end
88
+
89
+
90
+
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "TableBody" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie = IE.new
12
+ @ie.goto(TEST_HOST + "/tables.html")
13
+ end
14
+
15
+ describe "#length" do
16
+ it "should return the number of table bodies" do
17
+ @ie.table(:index, 1).bodies.length.should == 2
18
+ @ie.table(:index, 2).bodies.length.should == 0
19
+ end
20
+ end
21
+
22
+ describe "#[]n" do
23
+ it "should return the nth table body" do
24
+ pending
25
+ end
26
+ end
27
+
28
+ describe "#each" do
29
+ it "should iterate through table bodies correctly" do
30
+ #@ie.table(:index, 1).bodies.each_with_index do |body, index|
31
+ #end
32
+ pending
33
+ end
34
+ end
35
+
36
+ after :all do
37
+ @ie.close
38
+ end
39
+
40
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "TableBodies" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie = IE.new
12
+ @ie.goto(TEST_HOST + "/tables.html")
13
+ end
14
+
15
+ describe "#length" do
16
+ it "should return the correct number of table bodies" do
17
+ @ie.table(:index, 1).bodies.length.should == 2
18
+ end
19
+ end
20
+
21
+ describe "#[]" do
22
+ it "should return the row at the given index" do
23
+ @ie.table(:index, 1).bodies[1].id.should == "first"
24
+ @ie.table(:index, 1).bodies[2].name.should == "second"
25
+ end
26
+ end
27
+
28
+ describe "#each" do
29
+ it "should iterate through table bodies correctly" do
30
+ table = @ie.table(:index, 1)
31
+ table.bodies.each_with_index do |body, index|
32
+ body.name.should == table.body(:index, index+1).name
33
+ body.id.should == table.body(:index, index+1).id
34
+ end
35
+ end
36
+ end
37
+
38
+ after :all do
39
+ @ie.close
40
+ end
41
+
42
+ end