Sha256: 33635bf0291b9eb22946c8cf28f28d2a655a0961d8f5ed27f7b242f589439f34

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

require 'capybara'
require 'testingbot/config'
require 'testingbot/tunnel'
require 'testingbot/selenium'
require 'capybara/dsl'

@tunnel = nil

module TestingBot
  module Capybara

    def self.start_tunnel
      return @tunnel unless @tunnel.nil?

      @tunnel = TestingBot::Tunnel.new(TestingBot.get_config[:tunnel_options] || {})
      @tunnel.start
    end

    class CustomDriver < ::Capybara::Selenium::Driver

        def session_id
          @browser.session_id
        end

        def browser
          unless @browser
            if TestingBot.get_config[:require_tunnel]
              TestingBot::Capybara.start_tunnel
            end

            @browser = TestingBot::SeleniumWebdriver.new(@options || {})

            main = Process.pid
            at_exit do
              if @browser
                begin
                  @browser.quit 
                rescue
                end
              end
              if TestingBot.get_config[:require_tunnel]
                @tunnel.stop unless @tunnel.nil?
              end
            end
          end
          @browser
        end
    end
  end
end

module Capybara
  class Session
    def stop
      driver.quit
    end

    def session_id
      driver.session_id
    end
  end
end

Capybara.register_driver :testingbot do |app|
  TestingBot::Capybara::CustomDriver.new(app)
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
testingbot-0.1.7 lib/testingbot/capybara.rb
testingbot-0.1.6 lib/testingbot/capybara.rb
testingbot-0.1.5 lib/testingbot/capybara.rb
testingbot-0.1.4 lib/testingbot/capybara.rb
testingbot-0.1.3 lib/testingbot/capybara.rb
testingbot-0.1.2 lib/testingbot/capybara.rb
testingbot-0.1.1 lib/testingbot/capybara.rb