drnic-celerity 0.0.6.17

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 (230) hide show
  1. data/History.txt +75 -0
  2. data/License.txt +621 -0
  3. data/Manifest.txt +229 -0
  4. data/README.rdoc +78 -0
  5. data/Rakefile +25 -0
  6. data/benchmark/bm_2000_spans.rb +48 -0
  7. data/benchmark/bm_digg.rb +26 -0
  8. data/benchmark/bm_google_images.rb +36 -0
  9. data/benchmark/bm_input_locator.rb +69 -0
  10. data/benchmark/bm_text_input.rb +19 -0
  11. data/benchmark/loader.rb +14 -0
  12. data/celerity.gemspec +40 -0
  13. data/lib/celerity.rb +77 -0
  14. data/lib/celerity/browser.rb +888 -0
  15. data/lib/celerity/clickable_element.rb +73 -0
  16. data/lib/celerity/collections.rb +156 -0
  17. data/lib/celerity/container.rb +779 -0
  18. data/lib/celerity/default_viewer.rb +14 -0
  19. data/lib/celerity/disabled_element.rb +40 -0
  20. data/lib/celerity/element.rb +314 -0
  21. data/lib/celerity/element_collection.rb +107 -0
  22. data/lib/celerity/element_locator.rb +177 -0
  23. data/lib/celerity/elements/button.rb +45 -0
  24. data/lib/celerity/elements/file_field.rb +29 -0
  25. data/lib/celerity/elements/form.rb +23 -0
  26. data/lib/celerity/elements/frame.rb +77 -0
  27. data/lib/celerity/elements/image.rb +76 -0
  28. data/lib/celerity/elements/label.rb +11 -0
  29. data/lib/celerity/elements/link.rb +30 -0
  30. data/lib/celerity/elements/meta.rb +7 -0
  31. data/lib/celerity/elements/non_control_elements.rb +106 -0
  32. data/lib/celerity/elements/option.rb +32 -0
  33. data/lib/celerity/elements/radio_check.rb +115 -0
  34. data/lib/celerity/elements/select_list.rb +142 -0
  35. data/lib/celerity/elements/table.rb +144 -0
  36. data/lib/celerity/elements/table_cell.rb +29 -0
  37. data/lib/celerity/elements/table_elements.rb +42 -0
  38. data/lib/celerity/elements/table_row.rb +48 -0
  39. data/lib/celerity/elements/text_field.rb +169 -0
  40. data/lib/celerity/exception.rb +83 -0
  41. data/lib/celerity/htmlunit.rb +65 -0
  42. data/lib/celerity/htmlunit/commons-codec-1.4.jar +0 -0
  43. data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  44. data/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
  45. data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
  46. data/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
  47. data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  48. data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  49. data/lib/celerity/htmlunit/htmlunit-2.6-SNAPSHOT.jar +0 -0
  50. data/lib/celerity/htmlunit/htmlunit-core-js-2.6-SNAPSHOT.jar +0 -0
  51. data/lib/celerity/htmlunit/nekohtml-1.9.13-20090820.100833-15.jar +0 -0
  52. data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  53. data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  54. data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  55. data/lib/celerity/htmlunit/xercesImpl-2.9.1.jar +0 -0
  56. data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  57. data/lib/celerity/identifier.rb +11 -0
  58. data/lib/celerity/ignoring_web_connection.rb +15 -0
  59. data/lib/celerity/input_element.rb +25 -0
  60. data/lib/celerity/listener.rb +141 -0
  61. data/lib/celerity/resources/no_viewer.png +0 -0
  62. data/lib/celerity/short_inspect.rb +20 -0
  63. data/lib/celerity/util.rb +91 -0
  64. data/lib/celerity/viewer_connection.rb +89 -0
  65. data/lib/celerity/watir_compatibility.rb +83 -0
  66. data/lib/celerity/xpath_support.rb +48 -0
  67. data/spec/browser_authentication_spec.rb +16 -0
  68. data/spec/browser_spec.rb +300 -0
  69. data/spec/clickable_element_spec.rb +39 -0
  70. data/spec/default_viewer_spec.rb +23 -0
  71. data/spec/element_spec.rb +51 -0
  72. data/spec/filefield_spec.rb +18 -0
  73. data/spec/htmlunit_spec.rb +56 -0
  74. data/spec/index_offset_spec.rb +24 -0
  75. data/spec/listener_spec.rb +142 -0
  76. data/spec/spec_helper.rb +8 -0
  77. data/tasks/benchmark.rake +4 -0
  78. data/tasks/deployment.rake +43 -0
  79. data/tasks/environment.rake +7 -0
  80. data/tasks/fix.rake +25 -0
  81. data/tasks/jar.rake +57 -0
  82. data/tasks/rdoc.rake +4 -0
  83. data/tasks/rspec.rake +43 -0
  84. data/tasks/simple_ci.rake +94 -0
  85. data/tasks/snapshot.rake +22 -0
  86. data/tasks/website.rake +17 -0
  87. data/tasks/yard.rake +9 -0
  88. data/website/benchmarks.html +237 -0
  89. data/website/css/color.css +153 -0
  90. data/website/css/hacks.css +3 -0
  91. data/website/css/layout.css +179 -0
  92. data/website/css/screen.css +5 -0
  93. data/website/css/textmate.css +226 -0
  94. data/website/css/typography.css +72 -0
  95. data/website/gfx/body_bg.gif +0 -0
  96. data/website/gfx/button_bg.jpg +0 -0
  97. data/website/gfx/header_bg.jpg +0 -0
  98. data/website/gfx/header_left.jpg +0 -0
  99. data/website/gfx/header_right.jpg +0 -0
  100. data/website/gfx/nav_bg.jpg +0 -0
  101. data/website/index.html +133 -0
  102. data/website/yard/Celerity.html +50 -0
  103. data/website/yard/Celerity/Area.html +212 -0
  104. data/website/yard/Celerity/Areas.html +103 -0
  105. data/website/yard/Celerity/Browser.html +5594 -0
  106. data/website/yard/Celerity/Button.html +312 -0
  107. data/website/yard/Celerity/Buttons.html +103 -0
  108. data/website/yard/Celerity/CheckBox.html +347 -0
  109. data/website/yard/Celerity/CheckBoxes.html +103 -0
  110. data/website/yard/Celerity/ClickableElement.html +448 -0
  111. data/website/yard/Celerity/Container.html +7676 -0
  112. data/website/yard/Celerity/Dd.html +198 -0
  113. data/website/yard/Celerity/Dds.html +103 -0
  114. data/website/yard/Celerity/DefaultViewer.html +101 -0
  115. data/website/yard/Celerity/DisabledElement.html +252 -0
  116. data/website/yard/Celerity/Div.html +198 -0
  117. data/website/yard/Celerity/Divs.html +103 -0
  118. data/website/yard/Celerity/Dl.html +198 -0
  119. data/website/yard/Celerity/Dls.html +103 -0
  120. data/website/yard/Celerity/Dt.html +198 -0
  121. data/website/yard/Celerity/Dts.html +103 -0
  122. data/website/yard/Celerity/Element.html +1703 -0
  123. data/website/yard/Celerity/ElementCollection.html +725 -0
  124. data/website/yard/Celerity/ElementLocator.html +589 -0
  125. data/website/yard/Celerity/Em.html +198 -0
  126. data/website/yard/Celerity/Ems.html +103 -0
  127. data/website/yard/Celerity/Exception.html +23 -0
  128. data/website/yard/Celerity/Exception/CelerityException.html +32 -0
  129. data/website/yard/Celerity/Exception/MissingWayOfFindingObjectException.html +32 -0
  130. data/website/yard/Celerity/Exception/NavigationException.html +33 -0
  131. data/website/yard/Celerity/Exception/NoValueFoundException.html +33 -0
  132. data/website/yard/Celerity/Exception/ObjectDisabledException.html +33 -0
  133. data/website/yard/Celerity/Exception/ObjectReadOnlyException.html +33 -0
  134. data/website/yard/Celerity/Exception/UnexpectedPageException.html +33 -0
  135. data/website/yard/Celerity/Exception/UnknownCellException.html +33 -0
  136. data/website/yard/Celerity/Exception/UnknownFormException.html +33 -0
  137. data/website/yard/Celerity/Exception/UnknownFrameException.html +33 -0
  138. data/website/yard/Celerity/Exception/UnknownObjectException.html +33 -0
  139. data/website/yard/Celerity/Exception/UnknownRowException.html +33 -0
  140. data/website/yard/Celerity/FileField.html +289 -0
  141. data/website/yard/Celerity/FileFields.html +103 -0
  142. data/website/yard/Celerity/Form.html +284 -0
  143. data/website/yard/Celerity/Forms.html +103 -0
  144. data/website/yard/Celerity/Frame.html +527 -0
  145. data/website/yard/Celerity/Frames.html +103 -0
  146. data/website/yard/Celerity/H1.html +198 -0
  147. data/website/yard/Celerity/H1s.html +103 -0
  148. data/website/yard/Celerity/H2.html +198 -0
  149. data/website/yard/Celerity/H2s.html +103 -0
  150. data/website/yard/Celerity/H3.html +198 -0
  151. data/website/yard/Celerity/H3s.html +103 -0
  152. data/website/yard/Celerity/H4.html +198 -0
  153. data/website/yard/Celerity/H4s.html +103 -0
  154. data/website/yard/Celerity/H5.html +198 -0
  155. data/website/yard/Celerity/H5s.html +103 -0
  156. data/website/yard/Celerity/H6.html +198 -0
  157. data/website/yard/Celerity/H6s.html +103 -0
  158. data/website/yard/Celerity/Hidden.html +285 -0
  159. data/website/yard/Celerity/Hiddens.html +103 -0
  160. data/website/yard/Celerity/Image.html +645 -0
  161. data/website/yard/Celerity/Images.html +103 -0
  162. data/website/yard/Celerity/InputElement.html +271 -0
  163. data/website/yard/Celerity/Label.html +210 -0
  164. data/website/yard/Celerity/Labels.html +103 -0
  165. data/website/yard/Celerity/Li.html +198 -0
  166. data/website/yard/Celerity/Link.html +295 -0
  167. data/website/yard/Celerity/Links.html +103 -0
  168. data/website/yard/Celerity/Lis.html +103 -0
  169. data/website/yard/Celerity/Listener.html +821 -0
  170. data/website/yard/Celerity/Map.html +198 -0
  171. data/website/yard/Celerity/Maps.html +103 -0
  172. data/website/yard/Celerity/Meta.html +196 -0
  173. data/website/yard/Celerity/Metas.html +103 -0
  174. data/website/yard/Celerity/MethodGenerator.html +195 -0
  175. data/website/yard/Celerity/NonControlElement.html +212 -0
  176. data/website/yard/Celerity/Ol.html +198 -0
  177. data/website/yard/Celerity/Ols.html +103 -0
  178. data/website/yard/Celerity/Option.html +348 -0
  179. data/website/yard/Celerity/Options.html +103 -0
  180. data/website/yard/Celerity/P.html +198 -0
  181. data/website/yard/Celerity/Pre.html +198 -0
  182. data/website/yard/Celerity/Pres.html +103 -0
  183. data/website/yard/Celerity/Ps.html +103 -0
  184. data/website/yard/Celerity/Radio.html +339 -0
  185. data/website/yard/Celerity/RadioCheckCommon.html +453 -0
  186. data/website/yard/Celerity/Radios.html +103 -0
  187. data/website/yard/Celerity/SelectList.html +1122 -0
  188. data/website/yard/Celerity/SelectLists.html +103 -0
  189. data/website/yard/Celerity/ShortInspect.html +108 -0
  190. data/website/yard/Celerity/Span.html +198 -0
  191. data/website/yard/Celerity/Spans.html +103 -0
  192. data/website/yard/Celerity/Strong.html +198 -0
  193. data/website/yard/Celerity/Strongs.html +103 -0
  194. data/website/yard/Celerity/Table.html +1287 -0
  195. data/website/yard/Celerity/TableBodies.html +103 -0
  196. data/website/yard/Celerity/TableBody.html +203 -0
  197. data/website/yard/Celerity/TableCell.html +279 -0
  198. data/website/yard/Celerity/TableCells.html +103 -0
  199. data/website/yard/Celerity/TableElement.html +437 -0
  200. data/website/yard/Celerity/TableFooter.html +203 -0
  201. data/website/yard/Celerity/TableFooters.html +103 -0
  202. data/website/yard/Celerity/TableHeader.html +203 -0
  203. data/website/yard/Celerity/TableHeaders.html +103 -0
  204. data/website/yard/Celerity/TableRow.html +478 -0
  205. data/website/yard/Celerity/TableRows.html +103 -0
  206. data/website/yard/Celerity/Tables.html +103 -0
  207. data/website/yard/Celerity/TextField.html +938 -0
  208. data/website/yard/Celerity/TextFields.html +103 -0
  209. data/website/yard/Celerity/Th.html +208 -0
  210. data/website/yard/Celerity/Ul.html +209 -0
  211. data/website/yard/Celerity/Uls.html +103 -0
  212. data/website/yard/Celerity/Util.html +264 -0
  213. data/website/yard/Celerity/VERSION.html +44 -0
  214. data/website/yard/HtmlUnit.html +23 -0
  215. data/website/yard/HtmlUnit/Html.html +23 -0
  216. data/website/yard/HtmlUnit/Util.html +23 -0
  217. data/website/yard/Java/ComGargoylesoftwareHtmlunitHtml/HtmlPage.html +90 -0
  218. data/website/yard/Java/JavaLang/Iterable.html +103 -0
  219. data/website/yard/Java/OrgW3cDom/NamedNodeMap.html +97 -0
  220. data/website/yard/README.txt.html +116 -0
  221. data/website/yard/String.html +103 -0
  222. data/website/yard/all-files.html +22 -0
  223. data/website/yard/all-methods.html +3276 -0
  224. data/website/yard/all-namespaces.html +258 -0
  225. data/website/yard/app.js +18 -0
  226. data/website/yard/index.html +19 -0
  227. data/website/yard/jquery.js +11 -0
  228. data/website/yard/style.css +68 -0
  229. data/website/yard/syntax_highlight.css +21 -0
  230. metadata +307 -0
@@ -0,0 +1,48 @@
1
+ module Celerity
2
+
3
+ #
4
+ # Module to search by xpath
5
+ #
6
+
7
+ module XpathSupport
8
+
9
+ #
10
+ # Get the first element found matching the given XPath.
11
+ #
12
+ # @param [String] xpath
13
+ # @return [Celerity::Element] An element subclass (or Element if none is found)
14
+ #
15
+
16
+ def element_by_xpath(xpath)
17
+ assert_exists
18
+ obj = @page.getFirstByXPath(xpath)
19
+ element_from_dom_node(obj)
20
+ end
21
+
22
+ #
23
+ # Get all the elements matching the given XPath.
24
+ #
25
+ # @param [String] xpath
26
+ # @return [Array<Celerity::Element>] array of elements
27
+ #
28
+
29
+ def elements_by_xpath(xpath)
30
+ assert_exists
31
+ objects = @page.getByXPath(xpath)
32
+ # should use an ElementCollection here?
33
+ objects.map { |o| element_from_dom_node(o) }.compact
34
+ end
35
+
36
+ #
37
+ # Convert the given HtmlUnit DomNode to a Celerity object
38
+ #
39
+
40
+ def element_from_dom_node(obj)
41
+ element_class = Util.htmlunit2celerity(obj.class) || Element
42
+ element_class.new(self, :object, obj)
43
+ end
44
+
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/watirspec/spec_helper'
2
+
3
+ describe "Browser" do
4
+
5
+ describe "#credentials=" do
6
+ it "sets the basic authentication credentials" do
7
+ browser.goto(WatirSpec.host + "/authentication")
8
+ browser.text.should_not include("ok")
9
+
10
+ browser.credentials = "foo:bar"
11
+
12
+ browser.goto(WatirSpec.host + "/authentication")
13
+ browser.text.should include("ok")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,300 @@
1
+ require File.dirname(__FILE__) + '/watirspec/spec_helper'
2
+
3
+ describe "Browser" do
4
+ describe "#new" do
5
+ it "raises TypeError if argument is not a Hash" do
6
+ lambda { Browser.new(:foo) }.should raise_error(TypeError)
7
+ end
8
+
9
+ it "raises ArgumentError if given bad arguments for :render key" do
10
+ lambda { Browser.new(:render => :foo) }.should raise_error(ArgumentError)
11
+ end
12
+
13
+ it "raises ArgumentError if given bad arguments for :browser key" do
14
+ lambda { Browser.new(:browser => 'foo') }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "raises ArgumentError if given an unknown option" do
18
+ lambda { Browser.new(:foo => 1) }.should raise_error(ArgumentError)
19
+ end
20
+
21
+ it "should hold the init options" do
22
+ browser.options.should == WatirSpec.browser_args.first
23
+ end
24
+
25
+ it "should use the specified proxy" do
26
+ # TODO: find a better way to test this with rack
27
+ require 'webrick/httpproxy'
28
+
29
+ received = false
30
+ blk = lambda { received = true }
31
+ s = WEBrick::HTTPProxyServer.new(:Port => 2001, :ProxyContentHandler => blk)
32
+ Thread.new { s.start }
33
+
34
+ b = Browser.new(WatirSpec.browser_args.first.merge(:proxy => "localhost:2001"))
35
+ b.goto(WatirSpec.host)
36
+ s.shutdown
37
+
38
+ received.should be_true
39
+ end
40
+
41
+ it "should use the specified user agent" do
42
+ b = Browser.new(WatirSpec.browser_args.first.merge(:user_agent => "Celerity"))
43
+ b.goto(WatirSpec.host + "/header_echo")
44
+ b.text.should include('"HTTP_USER_AGENT"=>"Celerity"')
45
+ b.close
46
+ end
47
+
48
+ it "does not try to find a viewer if created with :viewer => false" do
49
+ ViewerConnection.should_not_receive(:create)
50
+
51
+ b = Browser.new(:viewer => false)
52
+ b.close
53
+ end
54
+
55
+ it "tries to find a viewer if created with :viewer => nil" do
56
+ ViewerConnection.should_receive(:create).with("127.0.0.1", 6429)
57
+
58
+ b = Browser.new(:viewer => nil)
59
+ b.close
60
+ end
61
+
62
+ it "tries to find a viewer on the specified host/port with :viewer => String" do
63
+ ViewerConnection.should_receive(:create).with("localhost", 1234)
64
+
65
+ b = Browser.new(:viewer => "localhost:1234")
66
+ b.close
67
+ end
68
+ end
69
+
70
+ describe "#html" do
71
+ %w(shift_jis iso-2022-jp euc-jp).each do |charset|
72
+ it "returns decoded #{charset.upcase} when :charset specified" do
73
+ browser = Browser.new(WatirSpec.browser_args.first.merge(:charset => charset.upcase))
74
+ browser.goto(WatirSpec.files + "/#{charset}_text.html")
75
+ # Browser#text is automagically transcoded into the right charset, but Browser#html isn't.
76
+ browser.html.should =~ /本日は晴天なり。/
77
+ browser.close
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#response_headers" do
83
+ it "returns the response headers (as a hash)" do
84
+ browser.goto(WatirSpec.host + "/non_control_elements.html")
85
+ browser.response_headers.should be_kind_of(Hash)
86
+ browser.response_headers['Date'].should be_kind_of(String)
87
+ browser.response_headers['Content-Type'].should be_kind_of(String)
88
+ end
89
+ end
90
+
91
+ describe "#content_type" do
92
+ it "returns the content type" do
93
+ browser.goto(WatirSpec.host + "/non_control_elements.html")
94
+ browser.content_type.should =~ /\w+\/\w+/
95
+ end
96
+ end
97
+
98
+ describe "#io" do
99
+ it "returns the io object of the content" do
100
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
101
+ browser.io.should be_kind_of(IO)
102
+ browser.io.read.should == File.read("#{WatirSpec.html}/non_control_elements.html")
103
+ end
104
+ end
105
+
106
+ describe "#goto" do
107
+ it "raises UnexpectedPageException if the content type is not understood" do
108
+ lambda { browser.goto(WatirSpec.host + "/octet_stream") }.should raise_error(UnexpectedPageException)
109
+ end
110
+ end
111
+
112
+ describe "#cookies" do
113
+ it "returns set cookies as a Ruby hash" do
114
+ cookies = browser.cookies
115
+ cookies.should be_instance_of(Hash)
116
+ cookies.should be_empty
117
+
118
+ browser.goto(WatirSpec.host + "/set_cookie")
119
+
120
+ cookies = browser.cookies
121
+ cookies.size.should == 1
122
+ cookies[WatirSpec::Server.host]['monster'].should == "/"
123
+ end
124
+ end
125
+
126
+ describe "#clear_cookies" do
127
+ it "clears all cookies" do
128
+ b = WatirSpec.new_browser
129
+ b.cookies.should be_empty
130
+
131
+ b.goto(WatirSpec.host + "/set_cookie")
132
+ b.cookies.size.should == 1
133
+ b.clear_cookies
134
+ b.cookies.should be_empty
135
+
136
+ b.close
137
+ end
138
+ end
139
+
140
+ describe "add_cookie" do
141
+ it "adds a cookie with the given domain, name and value" do
142
+ browser.add_cookie("example.com", "foo", "bar")
143
+ cookies = browser.cookies
144
+ cookies.should be_instance_of(Hash)
145
+ cookies.should have_key('example.com')
146
+ cookies['example.com']['foo'].should == 'bar'
147
+
148
+ browser.clear_cookies
149
+ end
150
+
151
+ it "adds a cookie with the specified options" do
152
+ browser.add_cookie("example.com", "foo", "bar", :path => "/foobar", :max_age => 1000)
153
+ cookies = browser.cookies
154
+ cookies.should be_instance_of(Hash)
155
+ cookies['example.com']['foo'].should == 'bar'
156
+ end
157
+ end
158
+
159
+ describe "remove_cookie" do
160
+ it "removes the cookie for the given domain and name" do
161
+ b = WatirSpec.new_browser
162
+ b.goto(WatirSpec.host + "/set_cookie")
163
+
164
+ b.remove_cookie(WatirSpec::Server.host, "monster")
165
+ b.cookies.should be_empty
166
+
167
+ b.close
168
+ end
169
+
170
+ it "raises an error if no such cookie exists" do
171
+ lambda { browser.remove_cookie("bogus.com", "bar") }.should raise_error(CookieNotFoundError)
172
+ end
173
+ end
174
+
175
+ describe "#wait" do
176
+ it "should wait for javascript timers to finish" do
177
+ alerts = 0
178
+ browser.add_listener(:alert) { alerts += 1 }
179
+ browser.goto(WatirSpec.files + "/timeout.html")
180
+ browser.div(:id, 'alert').click
181
+ browser.wait.should be_true
182
+ alerts.should == 1
183
+ end
184
+ end
185
+
186
+ describe "#wait_while" do
187
+ it "waits until the specified condition becomes false" do
188
+ browser.goto(WatirSpec.files + "/timeout.html")
189
+ browser.div(:id, "change").click
190
+ browser.wait_while { browser.contains_text("Trigger change") }
191
+ browser.div(:id, "change").text.should == "all done"
192
+ end
193
+
194
+ it "returns the value returned from the block" do
195
+ browser.wait_while { false }.should == false
196
+ end
197
+ end
198
+
199
+ describe "#wait_until" do
200
+ it "waits until the condition becomes true" do
201
+ browser.goto(WatirSpec.files + "/timeout.html")
202
+ browser.div(:id, "change").click
203
+ browser.wait_until { browser.contains_text("all done") }
204
+ end
205
+
206
+ it "returns the value returned from the block" do
207
+ browser.wait_until { true }.should == true
208
+ end
209
+ end
210
+
211
+ describe "#element_by_xpath" do
212
+ it "returns usable elements even though they're not supported" do
213
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
214
+
215
+ el = browser.element_by_xpath("//link")
216
+ el.should be_instance_of(Celerity::Element)
217
+ el.rel.should == "stylesheet"
218
+ end
219
+ end
220
+
221
+ describe "#focused_element" do
222
+ it "returns the element that currently has the focus" do
223
+ b = WatirSpec.new_browser
224
+ b.goto(WatirSpec.files + "/forms_with_input_elements.html")
225
+ b.focused_element.id.should == "new_user_first_name"
226
+
227
+ b.close
228
+ end
229
+ end
230
+
231
+ describe "#status_code" do
232
+ it "returns the status code of the last request" do
233
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
234
+ browser.status_code.should == 200
235
+
236
+ browser.goto(WatirSpec.host + "/doesnt_exist")
237
+ browser.status_code.should == 404
238
+ end
239
+ end
240
+
241
+ describe "#status_code_exceptions" do
242
+ it "raises status code exceptions if set to true" do
243
+ browser.status_code_exceptions = true
244
+ lambda do
245
+ browser.goto(WatirSpec.host + "/doesnt_exist")
246
+ end.should raise_error(NavigationException)
247
+ end
248
+ end
249
+
250
+ describe "#javascript_exceptions" do
251
+ it "raises javascript exceptions if set to true" do
252
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
253
+ browser.javascript_exceptions = true
254
+ lambda do
255
+ browser.execute_script("no_such_function()")
256
+ end.should raise_error
257
+ end
258
+ end
259
+
260
+ describe "#add_listener" do
261
+ it "should click OK for confirm() calls" do
262
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
263
+ browser.add_listener(:confirm) { }
264
+ browser.execute_script("confirm()").should == true
265
+ end
266
+ end
267
+
268
+ describe "#add_checker" do
269
+
270
+ # watir only supports a lambda instance as argument, celerity supports both
271
+ it "runs the given block on each page load" do
272
+ output = ''
273
+
274
+ browser.add_checker { |browser| output << browser.text }
275
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
276
+
277
+ output.should include('Dubito, ergo cogito, ergo sum')
278
+ end
279
+ end
280
+
281
+
282
+ describe "#confirm" do
283
+ it "clicks 'OK' for a confirm() call" do
284
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
285
+
286
+ browser.confirm(true) do
287
+ browser.execute_script('confirm()').should be_true
288
+ end
289
+ end
290
+
291
+ it "clicks 'cancel' for a confirm() call" do
292
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
293
+
294
+ browser.confirm(false) do
295
+ browser.execute_script('confirm()').should be_false
296
+ end
297
+ end
298
+ end
299
+
300
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/watirspec/spec_helper'
2
+
3
+ describe "ClickableElement" do
4
+
5
+ before :each do
6
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
7
+ end
8
+
9
+ describe "#click_and_attach" do
10
+ it 'opens a page in a new browser with the same options' do
11
+ b = browser.link(:name, /bad_attribute/).click_and_attach
12
+ b.text.include?("User administration").should be_true # to make sure it is open.
13
+ b.options.should == browser.options
14
+ b.cookies.should == browser.cookies
15
+ end
16
+
17
+ it "opens the page in a new browser with the same cookies" do
18
+ browser.add_cookie("localhost", "foo", "bar")
19
+ old_cookies = browser.cookies
20
+ old_cookies.should_not be_empty
21
+
22
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
23
+ b = browser.link(:name, /bad_attribute/).click_and_attach
24
+
25
+ b.should_not == browser
26
+ b.cookies.should == old_cookies
27
+ end
28
+ end
29
+
30
+ describe "#download" do
31
+ it 'returns a click-opened page as io' do
32
+ expected = File.read "#{WatirSpec.files}/forms_with_input_elements.html".sub("file://", '')
33
+
34
+ browser.link(:name, /bad_attribute/).download.read.should == expected
35
+ browser.link(:name, /bad_attribute/).should exist
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/watirspec/spec_helper'
2
+
3
+ describe "DefaultViewer" do
4
+
5
+ before :all do
6
+ browser.goto(WatirSpec.files + "/definition_lists.html")
7
+ end
8
+
9
+ describe ".save" do
10
+ it "saves the default image to the given path" do
11
+ fail("don't run specs with CelerityViewer") if browser.viewer != Celerity::DefaultViewer
12
+ fname = File.expand_path "default_viewer_test.png"
13
+ default = "#{File.dirname(__FILE__)}/../lib/celerity/resources/no_viewer.png"
14
+
15
+ browser.viewer.save(fname)
16
+ File.exist?(fname).should be_true
17
+ File.read(fname).should == File.read(default)
18
+
19
+ File.delete(fname)
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Element" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#identifier_string" do
11
+ it "doesn't make the next locate find the wrong element" do
12
+ elem = browser.div(:id, 'hidden_parent')
13
+ elem.should exist
14
+ def elem.public_identifier_string; identifier_string end # method is private
15
+ elem.public_identifier_string
16
+ elem.id.should == 'hidden_parent'
17
+ end
18
+ end
19
+
20
+ describe "#method_missing" do
21
+ it "magically returns the requested attribute if the attribute is defined in the attribute list" do
22
+ browser.form(:index, 1).action.should == 'post_to_me'
23
+ end
24
+
25
+ it "raises NoMethodError if the requested method isn't among the attributes" do
26
+ lambda { browser.button(:index, 1).no_such_attribute_or_method }.should raise_error(NoMethodError)
27
+ end
28
+ end
29
+
30
+ describe "#xpath" do
31
+ it "gets the canonical xpath of this element" do
32
+ browser.text_field(:id, "new_user_email").xpath.should == '/html/body/form[1]/fieldset[1]/input[3]'
33
+ end
34
+ end
35
+
36
+ describe "#javascript_object" do
37
+ it "should return the JavaScript object representing the receiver" do
38
+ obj = browser.div(:id, "onfocus_test").javascript_object
39
+ obj.should be_kind_of(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)
40
+ obj.should be_instance_of(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDivElement)
41
+ obj.client_width.should be_kind_of(Integer)
42
+ end
43
+ end
44
+
45
+ describe "#locate" do
46
+ it "raises ArgumentError when used with :object and the object given isn't an HtmlElement subclass" do
47
+ lambda { Link.new(browser, :object, "foo").locate }.should raise_error(ArgumentError)
48
+ end
49
+ end
50
+
51
+ end