pivotal-screw-unit-server 0.5.3
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.
- data/CHANGES +27 -0
- data/README.markdown +354 -0
- data/Rakefile +42 -0
- data/VERSION.yml +4 -0
- data/bin/screw_unit +6 -0
- data/bin/screw_unit_server +20 -0
- data/core/CHANGES +10 -0
- data/core/EXAMPLE.html +68 -0
- data/core/LICENSE +22 -0
- data/core/README.markdown +307 -0
- data/core/example/models/cat.js +5 -0
- data/core/example/models/man.js +17 -0
- data/core/example/spec/matchers/have.js +8 -0
- data/core/example/spec/models/cat_spec.js +31 -0
- data/core/example/spec/models/man_spec.js +34 -0
- data/core/example/spec/spec_helper.js +5 -0
- data/core/example/spec/suite.html +25 -0
- data/core/lib/jquery-1.3.2.js +4376 -0
- data/core/lib/jquery.fn.js +30 -0
- data/core/lib/jquery.print.js +109 -0
- data/core/lib/screw.behaviors.js +93 -0
- data/core/lib/screw.builder.js +95 -0
- data/core/lib/screw.css +90 -0
- data/core/lib/screw.events.js +45 -0
- data/core/lib/screw.matchers.js +244 -0
- data/core/spec/behaviors_spec.js +188 -0
- data/core/spec/matchers_spec.js +372 -0
- data/core/spec/print_spec.js +158 -0
- data/core/spec/spec_helper.js +0 -0
- data/core/spec/suite.html +19 -0
- data/core/spec/with_screw_context_spec.js +9 -0
- data/init.rb +0 -0
- data/lib/screw_unit.rb +23 -0
- data/lib/screw_unit/representations.rb +2 -0
- data/lib/screw_unit/representations/spec.html.rb +117 -0
- data/spec/functional/functional_spec.rb +25 -0
- data/spec/functional/functional_spec_helper.rb +43 -0
- data/spec/functional/functional_spec_server_starter.rb +68 -0
- data/spec/functional_suite.rb +10 -0
- data/spec/spec_suite.rb +3 -0
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +68 -0
- data/spec/unit/unit_spec_helper.rb +51 -0
- data/spec/unit_suite.rb +10 -0
- data/vendor/js-test-core/CHANGES +28 -0
- data/vendor/js-test-core/README +12 -0
- data/vendor/js-test-core/Rakefile +73 -0
- data/vendor/js-test-core/lib/js_test_core.rb +46 -0
- data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +129 -0
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
- data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
- data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
- data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
- data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
- data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
- data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +62 -0
- data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
- data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
- data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
- data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
- data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
- data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
- data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
- data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
- data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
- data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
- data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
- data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
- data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
- data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
- data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
- data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/vendor/js-test-core/spec/spec_suite.rb +2 -0
- data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +192 -0
- data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
- data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +81 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/selenium_session_spec.rb +362 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +28 -0
- data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +28 -0
- data/vendor/js-test-core/spec/unit_suite.rb +10 -0
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- metadata +198 -0
data/spec/spec_suite.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
|
+
|
3
|
+
module JsTestCore
|
4
|
+
module Resources
|
5
|
+
module Specs
|
6
|
+
describe SpecFile do
|
7
|
+
describe "File" do
|
8
|
+
describe "GET /specs/failing_spec" do
|
9
|
+
attr_reader :html, :doc
|
10
|
+
before do
|
11
|
+
response = get(SpecFile.path("/failing_spec"))
|
12
|
+
response.should be_http(
|
13
|
+
200,
|
14
|
+
{},
|
15
|
+
""
|
16
|
+
)
|
17
|
+
|
18
|
+
@doc = Nokogiri::HTML(response.body)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns script tags for the test javascript file" do
|
22
|
+
doc.at("script[@src='/specs/failing_spec.js']").should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns the screw unit template" do
|
26
|
+
doc.at("link[@href='/core/screw.css']").should_not be_nil
|
27
|
+
doc.at("script[@src='/core/screw.builder.js']").should_not be_nil
|
28
|
+
doc.at("script[@src='/core/screw.events.js']").should_not be_nil
|
29
|
+
doc.at("script[@src='/core/screw.behaviors.js']").should_not be_nil
|
30
|
+
doc.at("body/#screw_unit_content").should_not be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Directory" do
|
36
|
+
describe "GET /specs" do
|
37
|
+
attr_reader :dir, :html, :doc
|
38
|
+
|
39
|
+
before do
|
40
|
+
response = get(SpecFile.path("/"))
|
41
|
+
response.should be_http(
|
42
|
+
200,
|
43
|
+
{},
|
44
|
+
""
|
45
|
+
)
|
46
|
+
|
47
|
+
@doc = Nokogiri::HTML(response.body)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns script tags for each test javascript file" do
|
51
|
+
doc.at("script[@src='/specs/failing_spec.js']").should_not be_nil
|
52
|
+
doc.at("script[@src='/specs/foo/failing_spec.js']").should_not be_nil
|
53
|
+
doc.at("script[@src='/specs/foo/passing_spec.js']").should_not be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns the screw unit template" do
|
57
|
+
doc.at("link[@href='/core/screw.css']").should_not be_nil
|
58
|
+
doc.at("script[@src='/core/screw.builder.js']").should_not be_nil
|
59
|
+
doc.at("script[@src='/core/screw.events.js']").should_not be_nil
|
60
|
+
doc.at("script[@src='/core/screw.behaviors.js']").should_not be_nil
|
61
|
+
doc.at("body/#screw_unit_content").should_not be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "spec"
|
3
|
+
require "spec/autorun"
|
4
|
+
require "rack/test"
|
5
|
+
ARGV.push("-b")
|
6
|
+
|
7
|
+
dir = File.dirname(__FILE__)
|
8
|
+
LIBRARY_ROOT_DIR = File.expand_path("#{dir}/../..")
|
9
|
+
$LOAD_PATH.unshift File.expand_path("#{LIBRARY_ROOT_DIR}/lib")
|
10
|
+
require "screw_unit"
|
11
|
+
require "nokogiri"
|
12
|
+
require "guid"
|
13
|
+
require "#{LIBRARY_ROOT_DIR}/vendor/js-test-core/spec/spec_helpers/be_http"
|
14
|
+
require "#{LIBRARY_ROOT_DIR}/vendor/js-test-core/spec/spec_helpers/show_test_exceptions"
|
15
|
+
|
16
|
+
Spec::Runner.configure do |config|
|
17
|
+
config.mock_with :rr
|
18
|
+
end
|
19
|
+
|
20
|
+
Sinatra::Application.use ShowTestExceptions
|
21
|
+
Sinatra::Application.set :raise_errors, true
|
22
|
+
Sinatra::Application.set :show_exceptions, false
|
23
|
+
JsTestCore::App.set :raise_errors, true
|
24
|
+
JsTestCore::App.set :show_exceptions, false
|
25
|
+
|
26
|
+
Sinatra::Application.use(ScrewUnit::App)
|
27
|
+
|
28
|
+
class Spec::ExampleGroup
|
29
|
+
include Rack::Test::Methods
|
30
|
+
include BeHttp
|
31
|
+
|
32
|
+
attr_reader :spec_root_path, :public_path, :server, :connection
|
33
|
+
before(:all) do
|
34
|
+
dir = File.dirname(__FILE__)
|
35
|
+
@spec_root_path = File.expand_path("#{dir}/../example_specs")
|
36
|
+
@public_path = File.expand_path("#{dir}/../example_public")
|
37
|
+
end
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
JsTestCore::Configuration.instance.spec_root_path = spec_root_path
|
41
|
+
JsTestCore::Configuration.instance.public_path = public_path
|
42
|
+
end
|
43
|
+
|
44
|
+
def app
|
45
|
+
Sinatra::Application
|
46
|
+
end
|
47
|
+
|
48
|
+
def core_path
|
49
|
+
JsTestCore::Server.core_path
|
50
|
+
end
|
51
|
+
end
|
data/spec/unit_suite.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
- No longer using the /implementanions directory. Replace all cases of /implementations with /javascripts.
|
2
|
+
- Added support for custom suite files
|
3
|
+
- Added dependency on Erector
|
4
|
+
- Better error messages
|
5
|
+
- Changed dependency from Selenium to selenium-client
|
6
|
+
- Renamed Resources::Runner to Resources::SeleniumSession
|
7
|
+
- Changed /runners to /selenium_sessions
|
8
|
+
|
9
|
+
0.2.0
|
10
|
+
- Renamed Suite to Session to follow Selenium conventions
|
11
|
+
- Renamed SuiteFinish to SessionFinish to follow Selenium conventions
|
12
|
+
- Added /session, which uses the session_id cookie to derive the current session.
|
13
|
+
- Added /session/finished to be used to simplify client/server interactions.
|
14
|
+
- Remove File caching because it doesn't cause a noticable performance benefit over a local network and because it sometimes doesn't write over stale files.
|
15
|
+
- Client accepts selenium_browser_start_command parameter, which allows the user to parameterize the selenium_browser_start_command
|
16
|
+
- Added support for running specs in Internet Explorer via POST /runners/iexplore
|
17
|
+
- Resource file download performance improvements via caching and chunked sending
|
18
|
+
- Fixed false positive bug when Client connection times out
|
19
|
+
|
20
|
+
0.1.1
|
21
|
+
- SuiteFinish#post immediately closes the connection
|
22
|
+
|
23
|
+
0.1.0
|
24
|
+
- Initial Release extracted from JsTestCore.
|
25
|
+
- Added JsTestCore::WebRoot.dispatch_specs and .dispatch_strategy
|
26
|
+
- Extracted JsTestCore::Resources::Specs::SpecDir
|
27
|
+
- Extracted JsTestCore::Resources::Specs::SpecFile
|
28
|
+
- No longer depending on Guid. The child libraries are responsible for obtaining the Selenium session_id from the client by using top.runOptions.getSessionId().
|
@@ -0,0 +1,12 @@
|
|
1
|
+
= JsTestCore
|
2
|
+
The JsTestCore library is the core javascript test server library used by several JS Test server libraries.
|
3
|
+
|
4
|
+
To hook up your own JS Test framework:
|
5
|
+
* You will need to call either JsTestCore::Resources::WebRoot.dispatch_specs or JsTestCore::Resources::WebRoot.dispatch_tests
|
6
|
+
depending if you are serving specs or tests.
|
7
|
+
* Set JsTestCore.core_path to the directory of the client side test framework (javascript files)
|
8
|
+
* Override JsTestCore::Resources::Specs::SpecFile#get or JsTestCore::Resources::Specs::TestFile#get
|
9
|
+
* Override JsTestCore::Resources::Specs::SpecDir#get or JsTestCore::Resources::Specs::TestDir#get
|
10
|
+
|
11
|
+
NOTE: The current version of JsTestCore does not yet support tests. Support will be added soon.
|
12
|
+
I just wanted the test stuff to be in the docs to establish the current architectural direction.
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "rake"
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/contrib/rubyforgepublisher'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
|
8
|
+
desc "Runs the Rspec suite"
|
9
|
+
task(:default) do
|
10
|
+
run_suite
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Runs the Rspec suite"
|
14
|
+
task(:spec) do
|
15
|
+
run_suite
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Copies the trunk to a tag with the name of the current release"
|
19
|
+
task(:tag_release) do
|
20
|
+
tag_release
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_suite
|
24
|
+
dir = File.dirname(__FILE__)
|
25
|
+
system("ruby #{dir}/spec/spec_suite.rb") || raise("Example Suite failed")
|
26
|
+
end
|
27
|
+
|
28
|
+
PKG_NAME = "js_test_core"
|
29
|
+
PKG_VERSION = "0.2.0"
|
30
|
+
PKG_FILES = FileList[
|
31
|
+
'[A-Z]*',
|
32
|
+
'*.rb',
|
33
|
+
'lib/**/*.rb',
|
34
|
+
'core/**',
|
35
|
+
'bin/**',
|
36
|
+
'spec/**/*.rb'
|
37
|
+
]
|
38
|
+
|
39
|
+
spec = Gem::Specification.new do |s|
|
40
|
+
s.name = PKG_NAME
|
41
|
+
s.version = PKG_VERSION
|
42
|
+
s.summary = "The JsTestCore library is the core javascript test server library used by several JS Test server libraries."
|
43
|
+
s.test_files = "spec/spec_suite.rb"
|
44
|
+
s.description = s.summary
|
45
|
+
|
46
|
+
s.files = PKG_FILES.to_a
|
47
|
+
s.require_path = 'lib'
|
48
|
+
|
49
|
+
s.has_rdoc = true
|
50
|
+
s.extra_rdoc_files = [ "README", "CHANGES" ]
|
51
|
+
s.rdoc_options = ["--main", "README", "--inline-source", "--line-numbers"]
|
52
|
+
|
53
|
+
s.test_files = Dir.glob('spec/*_spec.rb')
|
54
|
+
s.require_path = 'lib'
|
55
|
+
s.author = "Brian Takita"
|
56
|
+
s.email = "brian@pivotallabs.com"
|
57
|
+
s.homepage = "http://pivotallabs.com"
|
58
|
+
s.rubyforge_project = "pivotalrb"
|
59
|
+
s.add_dependency('Selenium')
|
60
|
+
s.add_dependency('thin', '=0.8.1')
|
61
|
+
s.add_dependency('erector')
|
62
|
+
end
|
63
|
+
|
64
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
65
|
+
pkg.need_zip = true
|
66
|
+
pkg.need_tar = true
|
67
|
+
end
|
68
|
+
|
69
|
+
def tag_release
|
70
|
+
dashed_version = PKG_VERSION.gsub('.', '-')
|
71
|
+
svn_user = "#{ENV["SVN_USER"]}@" || ""
|
72
|
+
`svn cp svn+ssh://#{svn_user}rubyforge.org/var/svn/pivotalrb/js_test_core/trunk svn+ssh://#{svn_user}rubyforge.org/var/svn/pivotalrb/js_test_core/tags/REL-#{dashed_version} -m 'Version #{PKG_VERSION}'`
|
73
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
gem "thin", ">=1.2.1"
|
3
|
+
gem "erector", ">=0.6.6"
|
4
|
+
gem "selenium-client"
|
5
|
+
|
6
|
+
dir = File.dirname(__FILE__)
|
7
|
+
$LOAD_PATH.unshift File.expand_path("#{dir}/../vendor/lucky-luciano/lib")
|
8
|
+
require "lucky_luciano"
|
9
|
+
|
10
|
+
require "fileutils"
|
11
|
+
require "tmpdir"
|
12
|
+
require "timeout"
|
13
|
+
require "cgi"
|
14
|
+
require "net/http"
|
15
|
+
require "selenium/client"
|
16
|
+
require "optparse"
|
17
|
+
require "erector"
|
18
|
+
|
19
|
+
require "#{dir}/js_test_core/configuration"
|
20
|
+
|
21
|
+
require "#{dir}/js_test_core/extensions"
|
22
|
+
require "#{dir}/js_test_core/models"
|
23
|
+
require "#{dir}/js_test_core/resources"
|
24
|
+
require "#{dir}/js_test_core/representations"
|
25
|
+
|
26
|
+
require "#{dir}/js_test_core/client"
|
27
|
+
require "#{dir}/js_test_core/selenium_server_configuration"
|
28
|
+
|
29
|
+
require "#{dir}/js_test_core/app"
|
30
|
+
|
31
|
+
module JsTestCore
|
32
|
+
DEFAULT_HOST = "0.0.0.0"
|
33
|
+
DEFAULT_PORT = 8080
|
34
|
+
|
35
|
+
class << self
|
36
|
+
Configuration.instance = Configuration.new
|
37
|
+
|
38
|
+
def method_missing(method_name, *args, &block)
|
39
|
+
if Configuration.instance.respond_to?(method_name)
|
40
|
+
Configuration.instance.send(method_name, *args, &block)
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
class App < Sinatra::Base
|
3
|
+
set :logging, true
|
4
|
+
register(JsTestCore::Resources::WebRoot.route_handler)
|
5
|
+
register(JsTestCore::Resources::SeleniumSession.route_handler)
|
6
|
+
register(JsTestCore::Resources::CoreFile.route_handler)
|
7
|
+
register(JsTestCore::Resources::SpecFile.route_handler)
|
8
|
+
register(JsTestCore::Resources::File.route_handler)
|
9
|
+
register(JsTestCore::Resources::ImplementationsDeprecation.route_handler)
|
10
|
+
register(JsTestCore::Resources::NotFound.route_handler)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module JsTestCore
|
2
|
+
class Client
|
3
|
+
class ClientException < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class InvalidStatusResponse < ClientException
|
7
|
+
end
|
8
|
+
|
9
|
+
class SessionNotFound < ClientException
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def run(parameters={})
|
14
|
+
new(parameters).run
|
15
|
+
end
|
16
|
+
|
17
|
+
def run_argv(argv)
|
18
|
+
params = {}
|
19
|
+
parser = OptionParser.new do |o|
|
20
|
+
o.banner = "JsTestCore Runner"
|
21
|
+
o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]"
|
22
|
+
|
23
|
+
o.on
|
24
|
+
o.on('-s', '--selenium_browser_start_command=selenium_browser_start_command', "The Selenium server command to start the browser. See http://selenium-rc.openqa.org/") do |selenium_browser_start_command|
|
25
|
+
params[:selenium_browser_start_command] = selenium_browser_start_command
|
26
|
+
end
|
27
|
+
|
28
|
+
o.on('-h', '--selenium_host=SELENIUM_HOST', "The host name of the Selenium Server relative to where this file is executed") do |host|
|
29
|
+
params[:selenium_host] = host
|
30
|
+
end
|
31
|
+
|
32
|
+
o.on('-p', '--selenium_port=SELENIUM_PORT', "The port of the Selenium Server relative to where this file is executed") do |port|
|
33
|
+
params[:selenium_port] = port
|
34
|
+
end
|
35
|
+
|
36
|
+
o.on('-u', '--spec_url=SPEC_URL', "The url of the js spec server, relative to the browsers running via the Selenium Server") do |spec_url|
|
37
|
+
params[:spec_url] = spec_url
|
38
|
+
end
|
39
|
+
|
40
|
+
o.on('-t', '--timeout=TIMEOUT', "The timeout limit of the test run") do |timeout|
|
41
|
+
params[:timeout] = Integer(timeout)
|
42
|
+
end
|
43
|
+
|
44
|
+
o.on_tail
|
45
|
+
end
|
46
|
+
parser.order!(argv)
|
47
|
+
run params
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_reader :parameters, :query_string, :http, :session_start_response, :last_poll_status, :last_poll_reason, :last_poll
|
52
|
+
def initialize(parameters)
|
53
|
+
@parameters = parameters
|
54
|
+
@query_string = SeleniumServerConfiguration.query_string_from(parameters)
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
if parameters[:timeout]
|
59
|
+
Timeout.timeout(parameters[:timeout]) {do_run}
|
60
|
+
else
|
61
|
+
do_run
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parts_from_query(query)
|
66
|
+
query.split('&').inject({}) do |acc, key_value_pair|
|
67
|
+
key, value = key_value_pair.split('=')
|
68
|
+
acc[key] = value
|
69
|
+
acc
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
def do_run
|
75
|
+
Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) do |@http|
|
76
|
+
start_runner
|
77
|
+
wait_for_session_to_finish
|
78
|
+
end
|
79
|
+
report_result
|
80
|
+
end
|
81
|
+
|
82
|
+
def start_runner
|
83
|
+
@session_start_response = http.post(Resources::SeleniumSession.path, query_string)
|
84
|
+
end
|
85
|
+
|
86
|
+
def wait_for_session_to_finish
|
87
|
+
while session_not_completed?
|
88
|
+
poll
|
89
|
+
sleep 0.25
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def report_result
|
94
|
+
case last_poll_status
|
95
|
+
when Resources::SeleniumSession::SUCCESSFUL_COMPLETION
|
96
|
+
STDOUT.puts "SUCCESS"
|
97
|
+
true
|
98
|
+
when Resources::SeleniumSession::FAILURE_COMPLETION
|
99
|
+
STDOUT.puts "FAILURE"
|
100
|
+
STDOUT.puts last_poll_reason
|
101
|
+
false
|
102
|
+
else
|
103
|
+
raise InvalidStatusResponse, "Invalid Status: #{last_poll_status}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def session_not_completed?
|
108
|
+
last_poll_status.nil? || last_poll_status == Resources::SeleniumSession::RUNNING
|
109
|
+
end
|
110
|
+
|
111
|
+
def poll
|
112
|
+
@last_poll = http.get(Resources::SeleniumSession.path("/:session_id", :session_id => session_id))
|
113
|
+
ensure_session_exists!
|
114
|
+
parts = parts_from_query(last_poll.body)
|
115
|
+
@last_poll_status = parts['status']
|
116
|
+
@last_poll_reason = parts['reason']
|
117
|
+
end
|
118
|
+
|
119
|
+
def ensure_session_exists!
|
120
|
+
if (400..499).include?(Integer(last_poll.code))
|
121
|
+
raise SessionNotFound, "Could not find session with id #{session_id}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def session_id
|
126
|
+
@session_id ||= parts_from_query(session_start_response.body)['session_id']
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|