Sha256: 9e41e9d0ead1c81c1144b93377301771173bc7cfb43e900429f947bdb71a91e4

Contents?: true

Size: 1.35 KB

Versions: 13

Compression:

Stored size: 1.35 KB

Contents

require 'capybara'

module Sauce
  module Capybara
    class Driver < ::Capybara::Driver::Selenium
      def browser
        unless @browser
          puts "[Connecting to Sauce OnDemand...]"
          config = Sauce::Config.new
          @domain = "#{rand(10000)}.test"
          @sauce_tunnel = Sauce::Connect.new(:host => "127.0.0.1",
                                             :port => rack_server.port,
                                             :domain => @domain,
                                             :quiet => true)
          @sauce_tunnel.wait_until_ready
          @browser = Sauce::Selenium2.new(:name => "Capybara", :browser_url => "http://#{@domain}")
          at_exit do
            @browser.quit
            @sauce_tunnel.disconnect
          end
        end
        @browser
      end

      private

      def url(path)
        if path =~ /^http/
          path
        else
          "http://#{@domain}#{path}"
        end
      end
    end
  end
end

Capybara.register_driver :sauce do |app|
  Sauce::Capybara::Driver.new(app)
end

# Monkeypatch Capybara to not use :selenium driver
require 'capybara/dsl'
module Capybara
  def self.javascript_driver
    @javascript_driver || :sauce
  end
end

# Switch Cucumber stories tagged with @selenium to use sauce
begin
  Before("@selenium") do
    Capybara.current_driver = :sauce
  end
rescue NoMethodError
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sauce-1.0.1 lib/sauce/capybara.rb
sauce-1.0.0 lib/sauce/capybara.rb
sauce-0.20.0 lib/sauce/capybara.rb
sauce-0.19.1 lib/sauce/capybara.rb
sauce-0.19.0 lib/sauce/capybara.rb
sauce-0.18.3 lib/sauce/capybara.rb
sauce-0.18.2 lib/sauce/capybara.rb
sauce-0.18.1 lib/sauce/capybara.rb
sauce-0.18.0 lib/sauce/capybara.rb
sauce-0.17.8 lib/sauce/capybara.rb
sauce-0.17.7 lib/sauce/capybara.rb
sauce-0.17.6 lib/sauce/capybara.rb
sauce-0.17.5 lib/sauce/capybara.rb