jasmine-selenium-sauce 1.1.1 → 1.2.0

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 (30) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +65 -44
  4. data/jasmine-selenium-sauce.gemspec +5 -4
  5. data/lib/jasmine-selenium-sauce.rb +19 -1
  6. data/lib/jasmine-selenium-sauce/drivers/selenium_browser_driver.rb +0 -2
  7. data/lib/jasmine-selenium-sauce/drivers/selenium_saucelabs_driver.rb +0 -2
  8. data/lib/jasmine-selenium-sauce/local_sauce_config.rb +19 -0
  9. data/lib/jasmine-selenium-sauce/tasks/jasmine_selenium_sauce.rake +16 -0
  10. data/lib/jasmine-selenium-sauce/tasks/rake_browser_runner.rb +1 -1
  11. data/lib/jasmine-selenium-sauce/tasks/rake_local_sauce_runner.rb +22 -0
  12. data/lib/jasmine-selenium-sauce/tasks/rake_sauce_runner.rb +1 -1
  13. data/lib/jasmine-selenium-sauce/version.rb +1 -1
  14. data/lib/localtunnel_patch.rb +28 -0
  15. data/spec/fixtures/config_fixtures.rb +79 -0
  16. data/spec/fixtures/vcr_cassettes/jasmine_browser_success.yml +8 -8
  17. data/spec/fixtures/vcr_cassettes/jasmine_local_saucelabs_failures.yml +352 -0
  18. data/spec/fixtures/vcr_cassettes/jasmine_local_saucelabs_success.yml +340 -0
  19. data/spec/fixtures/vcr_cassettes/jasmine_saucelabs_failures.yml +55 -52
  20. data/spec/fixtures/vcr_cassettes/jasmine_saucelabs_success.yml +43 -41
  21. data/spec/jasmine-selenium-sauce/browser_config_spec.rb +41 -0
  22. data/spec/jasmine-selenium-sauce/drivers/selenium_browser_driver_spec.rb +1 -0
  23. data/spec/jasmine-selenium-sauce/local_sauce_config_spec.rb +61 -0
  24. data/spec/jasmine-selenium-sauce/sauce_config_spec.rb +3 -70
  25. data/spec/jasmine-selenium-sauce/selenium_runner_spec.rb +3 -3
  26. data/spec/jasmine-selenium-sauce_spec.rb +67 -36
  27. data/spec/support/reporter_fake.rb +2 -2
  28. data/spec/vcr_helper.rb +8 -1
  29. metadata +50 -70
  30. data/lib/jasmine-selenium-sauce/drivers.rb +0 -4
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - "1.8.7"
3
4
  - "1.9.2"
4
5
  - "1.9.3"
@@ -0,0 +1,16 @@
1
+ ## 1.2.0
2
+
3
+ - Added rake task for running jasmine suite through SauceLabs against localhost using a tunnel
4
+ - Compatible with Ruby 1.8.7
5
+
6
+ ## 1.1.1
7
+
8
+ - Minor cleanup
9
+
10
+ ## 1.1.0
11
+
12
+ - Added rake task that supports running jasmine suite using local browser
13
+
14
+ ## 1.0.0
15
+
16
+ - Initial release supporting running jasmine suite using SauceLabs
data/README.md CHANGED
@@ -2,26 +2,24 @@
2
2
 
3
3
  # Jasmine::Sauce::Ci
4
4
 
5
- Rake tasks for running your Jasmine suite via a local browse or through SauceLabs using the
5
+ Rake tasks for running your Jasmine suite via a local browser or through SauceLabs using the
6
6
  [Selenium Webdriver](http://seleniumhq.org/projects/webdriver/).
7
7
 
8
- Can be used in your CI builds to enable running Jasmine suites.
8
+ Can be used in your CI builds to enable running Jasmine suites. The Jasmine results are reported using RSpec to make
9
+ parsing easy.
9
10
 
10
- ## Installation
11
+ # Installation
11
12
 
12
13
  Add this line to your application's Gemfile:
13
14
 
14
15
  gem 'jasmine-selenium-sauce'
15
16
 
16
- And then execute:
17
+ # Running Jasmine via SauceLabs
17
18
 
18
- $ bundle
19
+ ## Remote Jasmine Server
19
20
 
20
- Or install it yourself as:
21
-
22
- $ gem install jasmine-selenium-sauce
23
-
24
- ## Running Jasmine via SauceLabs
21
+ When you want to run a Jasmine suite hosted on a publicly available host. Uses Selenium to connect to SauceLabs, and
22
+ requests a browser instance to run your suite.
25
23
 
26
24
  rake jasmine:sauce
27
25
 
@@ -29,68 +27,91 @@ Or install it yourself as:
29
27
 
30
28
  Requires the following environment variables to be set:
31
29
 
32
- #### SAUCELABS_URL
30
+ ```shell
31
+ SAUCELABS_URL=http://username:password@ondemand.saucelabs.com:80/wd/hub
32
+ ```
33
+ - URL for Saucelabs with your credentials included
34
+
35
+ ```shell
36
+ JASMINE_URL=http://my.server.com/jasmine
37
+ ```
38
+ - Where your Jasmine tests are hosted
33
39
 
34
- URL for Saucelabs with your credentials included:
40
+ ```shell
41
+ SAUCE_BROWSER=chrome
42
+ ```
43
+ - Which browser SauceLabs should use to run your tests
35
44
 
36
- SAUCELABS_URL=http://username:password@ondemand.saucelabs.com:80/wd/hub
45
+ ## Local Jasmine Server behind a Firewall
37
46
 
38
- #### JASMINE_URL
47
+ When you want to run a Jasmine suite hosted on an internal host. Uses [LocalTunnel](http://progrium.com/localtunnel/)
48
+ to make localhost available through a tunnel. It then uses Selenium to connect to SauceLabs, and requests a
49
+ browser instance to run your suite.
39
50
 
40
- Where your Jasmine tests are hosted:
51
+ rake jasmine:local_sauce
41
52
 
42
- JASMINE_URL=http://my.server.com/jasmine
53
+ ### Required Environment Variables
43
54
 
44
- #### SAUCE_BROWSER
55
+ Requires the following environment variables to be set:
45
56
 
46
- Which browser SauceLabs should use to run your tests:
57
+ ```shell
58
+ SAUCELABS_URL=http://username:password@ondemand.saucelabs.com:80/wd/hub
59
+ ```
60
+ - URL for Saucelabs with your credentials included
47
61
 
48
- SAUCE_BROWSER=chrome
62
+ ```shell
63
+ JASMINE_PORT=3000
64
+ ```
65
+ - Port on localhost where jasmine tests are located
49
66
 
50
- ### Optional Configuration
67
+ ```shell
68
+ SAUCE_BROWSER=chrome
69
+ ```
70
+ - Which browser SauceLabs should use to run your tests
51
71
 
52
- #### RSpec
72
+ ## Optional Configuration
53
73
 
54
- You can specify the format of the RSpec report with:
74
+ ### RSpec
55
75
 
56
- JASMINE_SPEC_FORMAT=documentation
76
+ ```shell
77
+ JASMINE_SPEC_FORMAT=documentation
78
+ ```
79
+ - Allows you to control the format of the RSpec report
57
80
 
58
- #### Sauce Labs Configuration
81
+ ### Additional Sauce Labs Configuration
59
82
 
60
83
  See [sauce_config.rb](https://github.com/darend/jasmine-selenium-sauce/tree/master/lib/jasmine-selenium-sauce/sauce_config.rb)
61
84
 
62
- ## Running Jasmine via local browser
85
+ # Running Jasmine via local browser
63
86
 
64
87
  rake jasmine:browser
65
88
 
66
- ### Required Environment Variables
89
+ ## Required Environment Variables
67
90
 
68
91
  Requires the following environment variables to be set:
69
92
 
70
- #### JASMINE_URL
71
-
72
- Where your Jasmine tests are hosted:
73
-
74
- JASMINE_URL=http://my.server.com/jasmine
75
-
76
- #### LOCAL_BROWSER
77
-
78
- Which browser that will be used to run your tests. Selenium may require a driver be installed depending the driver. See
79
- the Selenium documentation for more details.
80
-
81
- LOCAL_BROWSER=firefox
93
+ ```shell
94
+ JASMINE_URL=http://my.server.com/jasmine
95
+ ```
96
+ - Where your Jasmine tests are hosted
82
97
 
98
+ ```shell
99
+ LOCAL_BROWSER=firefox
100
+ ```
101
+ - Which browser that will be used to run your tests. Selenium may require a driver be installed depending the driver. See
102
+ the Selenium documentation for more details
83
103
  See [Which browsers does WebDriver support?](http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_Which_browsers_does_WebDriver_support?).
84
104
 
85
- ### Optional Configuration
86
-
87
- #### RSpec
105
+ ## Optional Configuration
88
106
 
89
- You can specify the format of the RSpec report with:
107
+ ### RSpec
90
108
 
91
- JASMINE_SPEC_FORMAT=documentation
109
+ ```shell
110
+ JASMINE_SPEC_FORMAT=documentation
111
+ ```
112
+ - Allows you to control the format of the RSpec report
92
113
 
93
- ## Contributing
114
+ # Contributing
94
115
 
95
116
  1. Fork it
96
117
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -2,10 +2,10 @@
2
2
  require File.expand_path('../lib/jasmine-selenium-sauce/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Daren"]
5
+ gem.authors = ["Daren Desjardins"]
6
6
  gem.email = ["darend@gmail.com"]
7
- gem.description = %q{Rake tasks for running your Jasmine suite via a local browse or through SauceLabs}
8
- gem.summary = %q{Rake tasks for running your Jasmine suite via a local browse or through SauceLabs. Can be used in your CI builds to enable running Jasmine suites}
7
+ gem.description = %q{Rake tasks for running your Jasmine suite via a local browser or through SauceLabs}
8
+ gem.summary = %q{Rake tasks for running your Jasmine suite via a local browser or through SauceLabs. Can be used in your CI builds to enable running Jasmine suites}
9
9
  gem.homepage = "https://github.com/darend/jasmine-selenium-sauce"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency 'rb-fsevent'
24
24
  gem.add_development_dependency 'vcr'
25
25
 
26
+ gem.add_dependency 'localtunnel', "~> 0.3"
26
27
  gem.add_dependency 'rspec', ">= 2.0"
27
- gem.add_dependency 'selenium-webdriver'
28
+ gem.add_dependency 'selenium-webdriver', "> 2.0.0"
28
29
  end
@@ -3,8 +3,14 @@ require 'jasmine-selenium-sauce/jasmine_results'
3
3
  require 'jasmine-selenium-sauce/rspec_reporter'
4
4
  require 'jasmine-selenium-sauce/browser_config'
5
5
  require 'jasmine-selenium-sauce/sauce_config'
6
+ require 'jasmine-selenium-sauce/local_sauce_config'
6
7
  require 'jasmine-selenium-sauce/selenium_runner'
7
- require 'jasmine-selenium-sauce/drivers'
8
+ require 'jasmine-selenium-sauce/drivers/selenium_driver'
9
+ require 'jasmine-selenium-sauce/drivers/selenium_browser_driver'
10
+ require 'jasmine-selenium-sauce/drivers/selenium_saucelabs_driver'
11
+
12
+ require 'localtunnel/tunnel'
13
+ require 'localtunnel_patch'
8
14
 
9
15
  module Jasmine
10
16
  module Sauce
@@ -12,13 +18,25 @@ module Jasmine
12
18
 
13
19
  class Main
14
20
  def self.run_via_saucelabs(sauce_config, reporter = RspecReporter.new)
21
+ puts "Using SauceLabs to run Jasmine suite located at #{sauce_config.jasmine_server_url}"
15
22
  driver = SeleniumSauceLabsDriver.new(sauce_config)
16
23
  selenium_runner = SeleniumRunner.new(driver)
17
24
  results = selenium_runner.run(sauce_config.jasmine_server_url)
18
25
  reporter.report(results)
19
26
  end
20
27
 
28
+ def self.run_local_via_saucelabs(local_sauce_config, reporter = RspecReporter.new)
29
+ puts "Establishing tunnel to port #{local_sauce_config.jasmine_server_port}"
30
+ tunnel = LocalTunnel::Tunnel.new(local_sauce_config.jasmine_server_port,nil)
31
+ response = tunnel.register_tunnel
32
+ tunnel.start_tunnel do
33
+ ENV['JASMINE_URL'] = "http://#{response['host']}/jasmine"
34
+ run_via_saucelabs(local_sauce_config, reporter)
35
+ end
36
+ end
37
+
21
38
  def self.run_via_browser(browser_config, reporter = RspecReporter.new)
39
+ puts "Running Jasmine suite against #{browser_config.jasmine_server_url} using #{browser_config.browser}"
22
40
  driver = SeleniumBrowserDriver.new(browser_config.browser)
23
41
  selenium_runner = SeleniumRunner.new(driver)
24
42
  results = selenium_runner.run(browser_config.jasmine_server_url)
@@ -1,5 +1,3 @@
1
- require_relative 'selenium_driver'
2
-
3
1
  module Jasmine
4
2
  module Sauce
5
3
  module CI
@@ -1,5 +1,3 @@
1
- require_relative 'selenium_driver'
2
-
3
1
  module Jasmine
4
2
  module Sauce
5
3
  module CI
@@ -0,0 +1,19 @@
1
+ module Jasmine
2
+ module Sauce
3
+ module CI
4
+
5
+ class LocalSauceConfig < SauceConfig
6
+
7
+ def validate
8
+ raise ArgumentError.new("SAUCELABS_URL was not set") unless saucelabs_server_url
9
+ raise ArgumentError.new("JASMINE_PORT was not set") unless jasmine_server_port
10
+ raise ArgumentError.new("SAUCE_BROWSER was not set") unless browser
11
+ end
12
+
13
+ def jasmine_server_port
14
+ ENV['JASMINE_PORT']
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -14,6 +14,20 @@ namespace :jasmine do
14
14
  Rake::Task["jasmine_sauce_runner"].invoke
15
15
  end
16
16
 
17
+ desc "Run Jasmine via SauceLabs against localhost using a tunnel"
18
+ task :local_sauce do
19
+ require "rspec/core/rake_task"
20
+
21
+ RSpec::Core::RakeTask.new(:jasmine_local_sauce_runner) do |t|
22
+ t.rspec_opts = ["--colour", "--format", ENV['JASMINE_SPEC_FORMAT'] || "progress"]
23
+ t.verbose = true
24
+ runner_path = File.expand_path(File.join(File.dirname(__FILE__), "rake_local_sauce_runner.rb"))
25
+ t.pattern = [runner_path]
26
+ end
27
+
28
+ Rake::Task["jasmine_local_sauce_runner"].invoke
29
+ end
30
+
17
31
  desc "Run Jasmine via local browser"
18
32
  task :browser do
19
33
  require "rspec/core/rake_task"
@@ -27,4 +41,6 @@ namespace :jasmine do
27
41
 
28
42
  Rake::Task["jasmine_browser_runner"].invoke
29
43
  end
44
+
45
+
30
46
  end
@@ -1,4 +1,4 @@
1
- require_relative '../../jasmine-selenium-sauce'
1
+ require File.join(File.dirname(__FILE__), '../../jasmine-selenium-sauce')
2
2
 
3
3
  config = Jasmine::Sauce::CI::BrowserConfig.new
4
4
  begin
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), '../../jasmine-selenium-sauce')
2
+
3
+ begin
4
+ config = Jasmine::Sauce::CI::LocalSauceConfig.new
5
+ config.validate
6
+ Jasmine::Sauce::CI::Main.run_local_via_saucelabs(config)
7
+ rescue ArgumentError => e
8
+ STDERR << "\nError: #{e.message}\n\n"
9
+ STDERR << "The following environment variables are required:\n"
10
+ STDERR << "\n"
11
+ STDERR << " SAUCELABS_URL - Your SauceLabs OnDemand URL with Basic Auth (http://username:password@ondemand.saucelabs.com:80/wd/hub)\n"
12
+ STDERR << " JASMINE_PORT - Port on localhost where server is running\n"
13
+ STDERR << " SAUCE_BROWSER - Which Browser SauceLabs should use\n"
14
+ STDERR << "\n"
15
+ exit -1
16
+ rescue StandardError => e
17
+ STDERR << "\nError: #{e.message}\n\n"
18
+ if e.message.include?("jsApiReporter is not defined")
19
+ STDERR << "Unable to find Jasmine tests, ensure server is running and #{config.jasmine_server_url} is correct\n\n"
20
+ end
21
+ exit -1
22
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../../jasmine-selenium-sauce'
1
+ require File.join(File.dirname(__FILE__), '../../jasmine-selenium-sauce')
2
2
 
3
3
  begin
4
4
  config = Jasmine::Sauce::CI::SauceConfig.new
@@ -1,7 +1,7 @@
1
1
  module Jasmine
2
2
  module Sauce
3
3
  module Ci
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,28 @@
1
+ class LocalTunnel::Tunnel
2
+
3
+ #
4
+ # Replace sleep call in start_tunnel with a yield to a block to be executed
5
+ # once the tunnel is established.
6
+ #
7
+ def start_tunnel
8
+ port = @port
9
+ tunnel = @tunnel
10
+ gateway = Net::SSH::Gateway.new(tunnel['host'], tunnel['user'])
11
+ gateway.open_remote(port.to_i, '127.0.0.1', tunnel['through_port'].to_i) do |rp,rh|
12
+ puts " " << tunnel['banner'] if tunnel.has_key? 'banner'
13
+ puts " Port #{port} is now publicly accessible from http://#{tunnel['host']} ..."
14
+ begin
15
+ yield
16
+ rescue Interrupt
17
+ gateway.close_remote(rp, rh)
18
+ exit
19
+ end
20
+ end
21
+ rescue Net::SSH::AuthenticationFailed
22
+ possible_key = Dir[File.expand_path('~/.ssh/*.pub')].first
23
+ puts " Failed to authenticate. If this is your first tunnel, you need to"
24
+ puts " upload a public key using the -k option. Try this:\n\n"
25
+ puts " localtunnel -k #{possible_key ? possible_key : '~/path/to/key'} #{port}"
26
+ exit
27
+ end
28
+ end
@@ -0,0 +1,79 @@
1
+
2
+ shared_examples_for "overridable configuration setting" do |env_setting, default|
3
+ context "when not specified" do
4
+ it { should eq(default) }
5
+ end
6
+
7
+ context "when specified" do
8
+ let(:value) { "random value" }
9
+ before { ENV[env_setting] = value }
10
+ after { ENV.delete(env_setting) }
11
+ it { should eq(value) }
12
+ end
13
+ end
14
+
15
+ shared_examples_for "jasmine server url" do
16
+ describe "#jasmine_server_url" do
17
+ let(:url) { "http://my.host.com/jasmine" }
18
+ before { ENV['JASMINE_URL'] = url }
19
+ after { ENV.delete('JASMINE_URL') }
20
+ its(:jasmine_server_url) { should eq(url)}
21
+ end
22
+ end
23
+
24
+ shared_examples_for "sauce config" do
25
+
26
+ include_context "jasmine server url"
27
+
28
+ describe "#saucelabs_server_url" do
29
+ let(:url) { "http://user:password@ondemand.saucelabs.com:80/wd/hub" }
30
+ before { ENV['SAUCELABS_URL'] = url }
31
+ after { ENV.delete('SAUCELABS_URL') }
32
+ its(:saucelabs_server_url) { should eq(url)}
33
+ end
34
+
35
+ describe "#sauce_browser" do
36
+ let(:browser) { "Chrome" }
37
+ before { ENV['SAUCE_BROWSER'] = browser }
38
+ after { ENV.delete('SAUCE_BROWSER') }
39
+ its(:browser) { should eq(browser)}
40
+ end
41
+
42
+ describe "#sauce_platform" do
43
+ context "when not specified" do
44
+ its(:platform) { should eq(:VISTA) }
45
+ end
46
+
47
+ context "when specified" do
48
+ let(:platform) { "WIN_7" }
49
+ before { ENV['SAUCE_PLATFORM'] = platform }
50
+ after { ENV.delete('SAUCE_PLATFORM') }
51
+ its(:platform) { should eq(platform.to_sym) }
52
+ end
53
+ end
54
+
55
+ describe "#browser_version" do
56
+ subject { under_test.browser_version }
57
+ it_behaves_like "overridable configuration setting", 'SAUCE_BROWSER_VERSION', nil
58
+ end
59
+
60
+ describe "#record_screenshots" do
61
+ subject { under_test.record_screenshots }
62
+ it_behaves_like "overridable configuration setting", 'SAUCE_SCREENSHOTS', false
63
+ end
64
+
65
+ describe "#record_video" do
66
+ subject { under_test.record_video }
67
+ it_behaves_like "overridable configuration setting", 'SAUCE_VIDEO', false
68
+ end
69
+
70
+ describe "#idle_timeout" do
71
+ subject { under_test.idle_timeout }
72
+ it_behaves_like "overridable configuration setting", 'SAUCE_IDLE_TIMEOUT', 90
73
+ end
74
+
75
+ describe "#max_duration" do
76
+ subject { under_test.max_duration }
77
+ it_behaves_like "overridable configuration setting", 'SAUCE_MAX_DURATION', 180
78
+ end
79
+ end