jarib-celerity 0.0.6.18 → 0.0.6.19
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +82 -0
- data/{README.markdown → README.rdoc} +17 -25
- data/Rakefile +25 -10
- data/celerity.gemspec +40 -0
- data/lib/celerity.rb +1 -1
- data/lib/celerity/browser.rb +4 -0
- data/lib/celerity/htmlunit.rb +12 -8
- data/lib/celerity/version.rb +3 -10
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +300 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +51 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +56 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +8 -0
- data/tasks/benchmark.rake +4 -0
- data/tasks/deployment.rake +43 -0
- data/tasks/environment.rake +7 -0
- data/tasks/fix.rake +25 -0
- data/tasks/jar.rake +4 -6
- data/tasks/rspec.rake +43 -0
- data/tasks/simple_ci.rake +94 -0
- data/tasks/snapshot.rake +22 -0
- data/tasks/website.rake +17 -0
- data/tasks/yard.rake +9 -0
- metadata +35 -18
data/Manifest.txt
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
celerity.gemspec
|
7
|
+
lib/celerity.rb
|
8
|
+
lib/celerity/browser.rb
|
9
|
+
lib/celerity/clickable_element.rb
|
10
|
+
lib/celerity/collections.rb
|
11
|
+
lib/celerity/container.rb
|
12
|
+
lib/celerity/default_viewer.rb
|
13
|
+
lib/celerity/disabled_element.rb
|
14
|
+
lib/celerity/element.rb
|
15
|
+
lib/celerity/element_collection.rb
|
16
|
+
lib/celerity/element_locator.rb
|
17
|
+
lib/celerity/elements/button.rb
|
18
|
+
lib/celerity/elements/file_field.rb
|
19
|
+
lib/celerity/elements/form.rb
|
20
|
+
lib/celerity/elements/frame.rb
|
21
|
+
lib/celerity/elements/image.rb
|
22
|
+
lib/celerity/elements/label.rb
|
23
|
+
lib/celerity/elements/link.rb
|
24
|
+
lib/celerity/elements/meta.rb
|
25
|
+
lib/celerity/elements/non_control_elements.rb
|
26
|
+
lib/celerity/elements/option.rb
|
27
|
+
lib/celerity/elements/radio_check.rb
|
28
|
+
lib/celerity/elements/select_list.rb
|
29
|
+
lib/celerity/elements/table.rb
|
30
|
+
lib/celerity/elements/table_cell.rb
|
31
|
+
lib/celerity/elements/table_elements.rb
|
32
|
+
lib/celerity/elements/table_row.rb
|
33
|
+
lib/celerity/elements/text_field.rb
|
34
|
+
lib/celerity/exception.rb
|
35
|
+
lib/celerity/htmlunit.rb
|
36
|
+
lib/celerity/htmlunit/commons-codec-1.4.jar
|
37
|
+
lib/celerity/htmlunit/commons-collections-3.2.1.jar
|
38
|
+
lib/celerity/htmlunit/commons-httpclient-3.1.jar
|
39
|
+
lib/celerity/htmlunit/commons-io-1.4.jar
|
40
|
+
lib/celerity/htmlunit/commons-lang-2.4.jar
|
41
|
+
lib/celerity/htmlunit/commons-logging-1.1.1.jar
|
42
|
+
lib/celerity/htmlunit/cssparser-0.9.5.jar
|
43
|
+
lib/celerity/htmlunit/htmlunit-2.6-SNAPSHOT.jar
|
44
|
+
lib/celerity/htmlunit/htmlunit-core-js-2.6-SNAPSHOT.jar
|
45
|
+
lib/celerity/htmlunit/nekohtml-1.9.13-20090820.100833-15.jar
|
46
|
+
lib/celerity/htmlunit/sac-1.3.jar
|
47
|
+
lib/celerity/htmlunit/serializer-2.7.1.jar
|
48
|
+
lib/celerity/htmlunit/xalan-2.7.1.jar
|
49
|
+
lib/celerity/htmlunit/xercesImpl-2.9.1.jar
|
50
|
+
lib/celerity/htmlunit/xml-apis-1.3.04.jar
|
51
|
+
lib/celerity/identifier.rb
|
52
|
+
lib/celerity/ignoring_web_connection.rb
|
53
|
+
lib/celerity/input_element.rb
|
54
|
+
lib/celerity/listener.rb
|
55
|
+
lib/celerity/resources/no_viewer.png
|
56
|
+
lib/celerity/short_inspect.rb
|
57
|
+
lib/celerity/util.rb
|
58
|
+
lib/celerity/version.rb
|
59
|
+
lib/celerity/viewer_connection.rb
|
60
|
+
lib/celerity/watir_compatibility.rb
|
61
|
+
lib/celerity/xpath_support.rb
|
62
|
+
spec/browser_authentication_spec.rb
|
63
|
+
spec/browser_spec.rb
|
64
|
+
spec/clickable_element_spec.rb
|
65
|
+
spec/default_viewer_spec.rb
|
66
|
+
spec/element_spec.rb
|
67
|
+
spec/filefield_spec.rb
|
68
|
+
spec/htmlunit_spec.rb
|
69
|
+
spec/index_offset_spec.rb
|
70
|
+
spec/listener_spec.rb
|
71
|
+
spec/spec_helper.rb
|
72
|
+
tasks/benchmark.rake
|
73
|
+
tasks/deployment.rake
|
74
|
+
tasks/environment.rake
|
75
|
+
tasks/fix.rake
|
76
|
+
tasks/jar.rake
|
77
|
+
tasks/rdoc.rake
|
78
|
+
tasks/rspec.rake
|
79
|
+
tasks/simple_ci.rake
|
80
|
+
tasks/snapshot.rake
|
81
|
+
tasks/website.rake
|
82
|
+
tasks/yard.rake
|
@@ -1,17 +1,16 @@
|
|
1
|
-
Celerity
|
2
|
-
========
|
1
|
+
= Celerity
|
3
2
|
|
4
|
-
*
|
3
|
+
* http://celerity.rubyforge.org/
|
5
4
|
|
6
|
-
Description
|
7
|
-
------------
|
5
|
+
== Description
|
8
6
|
|
9
|
-
Celerity is a JRuby
|
7
|
+
Celerity is a JRuby library for easy and fast functional test automation for web applications.
|
8
|
+
|
9
|
+
It is a JRuby wrapper around HtmlUnit – a headless Java browser with
|
10
10
|
JavaScript support. It provides a simple API for programmatic navigation through
|
11
11
|
web applications. Celerity aims at being API compatible with Watir.
|
12
12
|
|
13
|
-
Features
|
14
|
-
--------
|
13
|
+
== Features
|
15
14
|
|
16
15
|
* *Fast*: No time-consuming GUI rendering or unessential downloads
|
17
16
|
* *Scalable*: Java threads lets you run tests in parallel
|
@@ -19,24 +18,21 @@ Features
|
|
19
18
|
* *Portable*: Cross-platform thanks to the JVM
|
20
19
|
* *Unintrusive*: No browser window interrupting your workflow (runs in background)
|
21
20
|
|
22
|
-
Requirements
|
23
|
-
------------
|
21
|
+
== Requirements
|
24
22
|
|
25
23
|
* JRuby 1.2.0 or higher
|
26
24
|
* Java 6
|
27
25
|
|
28
|
-
Install
|
29
|
-
-------
|
26
|
+
== Install
|
30
27
|
|
31
|
-
|
28
|
+
jruby -S gem install celerity
|
32
29
|
|
33
|
-
|
30
|
+
or from GitHub (updated frequently)
|
34
31
|
|
35
|
-
|
32
|
+
jruby -S gem install jarib-celerity
|
36
33
|
|
37
34
|
|
38
|
-
Example
|
39
|
-
-------
|
35
|
+
== Example
|
40
36
|
|
41
37
|
require "rubygems"
|
42
38
|
require "celerity"
|
@@ -48,26 +44,22 @@ Example
|
|
48
44
|
|
49
45
|
puts "yay" if browser.text.include? 'celerity.rubyforge.org'
|
50
46
|
|
51
|
-
Source
|
52
|
-
------
|
47
|
+
== Source
|
53
48
|
|
54
49
|
The source code is available on [GitHub](http://github.com/jarib/celerity/tree/master).
|
55
50
|
|
56
51
|
|
57
|
-
Wiki & Bug Tracker
|
58
|
-
-------------------
|
52
|
+
== Wiki & Bug Tracker
|
59
53
|
|
60
54
|
* [Wiki](http://github.com/jarib/celerity/wikis)
|
61
55
|
* [Bug Tracker](http://github.com/jarib/celerity/issues)
|
62
56
|
|
63
|
-
Related projects
|
64
|
-
----------------
|
57
|
+
== Related projects
|
65
58
|
|
66
59
|
* [WatirSpec](http://github.com/jarib/watirspec/tree/master)
|
67
60
|
* [Celerity Viewers](http://github.com/jarib/celerity-viewers)
|
68
61
|
|
69
|
-
License
|
70
|
-
-------
|
62
|
+
== License
|
71
63
|
|
72
64
|
Celerity - JRuby wrapper for HtmlUnit
|
73
65
|
Copyright (c) 2008 FINN.no AS
|
data/Rakefile
CHANGED
@@ -1,12 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
else # in gem dir
|
8
|
-
load 'tasks/jar.rake'
|
9
|
-
load 'tasks/rdoc.rake'
|
10
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.3.0'
|
3
|
+
require 'hoe'
|
4
|
+
%w[fileutils rubigen].each { |f| require f }
|
5
|
+
|
6
|
+
require "lib/celerity/version"
|
11
7
|
|
8
|
+
Hoe.plugin :newgem # newgem 1.5.2+
|
9
|
+
Hoe.plugin :website
|
12
10
|
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
Hoe.spec 'celerity' do
|
14
|
+
author << "Jari Bakken" << "T. Alexander Lystad" << "Knut Johannes Dahle"
|
15
|
+
email << "jari.bakken@finn.no"
|
16
|
+
extra_dev_deps << ['sinatra', '>= 0.9.4']
|
17
|
+
version = Celerity::VERSION
|
18
|
+
end
|
19
|
+
|
20
|
+
Dir['tasks/**/*.rake'].each do |rake|
|
21
|
+
begin
|
22
|
+
load rake
|
23
|
+
rescue LoadError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
# load 'tasks/jar.rake'
|
27
|
+
# load 'tasks/rdoc.rake'
|
data/celerity.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{celerity}
|
5
|
+
s.version = "0.0.6.19"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jari Bakken", "T. Alexander Lystad", "Knut Johannes Dahle"]
|
9
|
+
s.date = %q{2009-09-04}
|
10
|
+
s.description = %q{Celerity is a JRuby library for easy and fast functional test automation for web applications.
|
11
|
+
|
12
|
+
It is a JRuby wrapper around HtmlUnit – a headless Java browser with
|
13
|
+
JavaScript support. It provides a simple API for programmatic navigation through
|
14
|
+
web applications. Celerity aims at being API compatible with Watir.}
|
15
|
+
s.email = ["jari.bakken@finn.no"]
|
16
|
+
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt"]
|
17
|
+
s.files = ["History.txt", "License.txt", "Manifest.txt", "README.rdoc", "Rakefile", "celerity.gemspec", "lib/celerity.rb", "lib/celerity/browser.rb", "lib/celerity/clickable_element.rb", "lib/celerity/collections.rb", "lib/celerity/container.rb", "lib/celerity/default_viewer.rb", "lib/celerity/disabled_element.rb", "lib/celerity/element.rb", "lib/celerity/element_collection.rb", "lib/celerity/element_locator.rb", "lib/celerity/elements/button.rb", "lib/celerity/elements/file_field.rb", "lib/celerity/elements/form.rb", "lib/celerity/elements/frame.rb", "lib/celerity/elements/image.rb", "lib/celerity/elements/label.rb", "lib/celerity/elements/link.rb", "lib/celerity/elements/meta.rb", "lib/celerity/elements/non_control_elements.rb", "lib/celerity/elements/option.rb", "lib/celerity/elements/radio_check.rb", "lib/celerity/elements/select_list.rb", "lib/celerity/elements/table.rb", "lib/celerity/elements/table_cell.rb", "lib/celerity/elements/table_elements.rb", "lib/celerity/elements/table_row.rb", "lib/celerity/elements/text_field.rb", "lib/celerity/exception.rb", "lib/celerity/htmlunit.rb", "lib/celerity/htmlunit/commons-codec-1.4.jar", "lib/celerity/htmlunit/commons-collections-3.2.1.jar", "lib/celerity/htmlunit/commons-httpclient-3.1.jar", "lib/celerity/htmlunit/commons-io-1.4.jar", "lib/celerity/htmlunit/commons-lang-2.4.jar", "lib/celerity/htmlunit/commons-logging-1.1.1.jar", "lib/celerity/htmlunit/cssparser-0.9.5.jar", "lib/celerity/htmlunit/htmlunit-2.6-SNAPSHOT.jar", "lib/celerity/htmlunit/htmlunit-core-js-2.6-SNAPSHOT.jar", "lib/celerity/htmlunit/nekohtml-1.9.13-20090820.100833-15.jar", "lib/celerity/htmlunit/sac-1.3.jar", "lib/celerity/htmlunit/serializer-2.7.1.jar", "lib/celerity/htmlunit/xalan-2.7.1.jar", "lib/celerity/htmlunit/xercesImpl-2.9.1.jar", "lib/celerity/htmlunit/xml-apis-1.3.04.jar", "lib/celerity/identifier.rb", "lib/celerity/ignoring_web_connection.rb", "lib/celerity/input_element.rb", "lib/celerity/listener.rb", "lib/celerity/resources/no_viewer.png", "lib/celerity/short_inspect.rb", "lib/celerity/util.rb", "lib/celerity/version.rb", "lib/celerity/viewer_connection.rb", "lib/celerity/watir_compatibility.rb", "lib/celerity/xpath_support.rb", "spec/browser_authentication_spec.rb", "spec/browser_spec.rb", "spec/clickable_element_spec.rb", "spec/default_viewer_spec.rb", "spec/element_spec.rb", "spec/filefield_spec.rb", "spec/htmlunit_spec.rb", "spec/index_offset_spec.rb", "spec/listener_spec.rb", "spec/spec_helper.rb", "tasks/benchmark.rake", "tasks/deployment.rake", "tasks/environment.rake", "tasks/fix.rake", "tasks/jar.rake", "tasks/rdoc.rake", "tasks/rspec.rake", "tasks/simple_ci.rake", "tasks/snapshot.rake", "tasks/website.rake", "tasks/yard.rake"]
|
18
|
+
s.homepage = %q{http://celerity.rubyforge.org/}
|
19
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.rubyforge_project = %q{celerity}
|
22
|
+
s.rubygems_version = %q{1.3.5}
|
23
|
+
s.summary = %q{Celerity is a JRuby library for easy and fast functional test automation for web applications}
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 3
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
s.add_development_dependency(%q<sinatra>, [">= 0.9.4"])
|
31
|
+
s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
34
|
+
s.add_dependency(%q<hoe>, [">= 2.3.3"])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
38
|
+
s.add_dependency(%q<hoe>, [">= 2.3.3"])
|
39
|
+
end
|
40
|
+
end
|
data/lib/celerity.rb
CHANGED
@@ -32,8 +32,8 @@ module Celerity
|
|
32
32
|
DIR = File.expand_path(File.dirname(__FILE__) + "/celerity")
|
33
33
|
end
|
34
34
|
|
35
|
-
require "celerity/htmlunit"
|
36
35
|
require "celerity/version"
|
36
|
+
require "celerity/htmlunit"
|
37
37
|
require "celerity/exception"
|
38
38
|
require "celerity/clickable_element"
|
39
39
|
require "celerity/disabled_element"
|
data/lib/celerity/browser.rb
CHANGED
@@ -520,6 +520,10 @@ module Celerity
|
|
520
520
|
listener.add_listener(type, &block)
|
521
521
|
end
|
522
522
|
|
523
|
+
def remove_listener(type, &block)
|
524
|
+
listener.remove_listener(type, &block)
|
525
|
+
end
|
526
|
+
|
523
527
|
#
|
524
528
|
# Specify a boolean value to click either 'OK' or 'Cancel' in any confirm
|
525
529
|
# dialogs that might show up during the duration of the given block.
|
data/lib/celerity/htmlunit.rb
CHANGED
@@ -3,6 +3,13 @@ module Celerity
|
|
3
3
|
Jars.each { |jar| require(jar) }
|
4
4
|
|
5
5
|
include_class org.apache.commons.httpclient.Cookie
|
6
|
+
|
7
|
+
module JsxHelper
|
8
|
+
def method_missing(meth, *args, &blk)
|
9
|
+
m = ["jsxGet_#{meth}", "jsx_get_#{meth}"].find { |m| respond_to?(m) }
|
10
|
+
m ? __send__(m) : super
|
11
|
+
end
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
15
|
module HtmlUnit
|
@@ -50,12 +57,9 @@ class Java::ComGargoylesoftwareHtmlunitHtml::HtmlElement
|
|
50
57
|
end
|
51
58
|
|
52
59
|
class Java::ComGargoylesoftwareHtmlunitJavascriptHostHtml::HTMLElement
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
super
|
59
|
-
end
|
60
|
-
end
|
60
|
+
include Celerity::JsxHelper
|
61
|
+
end
|
62
|
+
|
63
|
+
class Java::ComGargoylesoftwareHtmlunitJavascriptHostCss::CSSStyleDeclaration
|
64
|
+
include Celerity::JsxHelper
|
61
65
|
end
|
data/lib/celerity/version.rb
CHANGED
@@ -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
|