Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

DRAFT: Allow Capybara/Cucumber tests to use one tunnel and multiple drivers #33

Merged

Conversation

rtyler
Copy link
Contributor

@rtyler rtyler commented Mar 6, 2012

Note: This pull request builds on top of/requires the contents of pull request #32


There is no need for us to tear-down the Sauce::Connect tunnel more than once per-process-lifetime when testing with cucumber and capybara, but introducing the $sauce_tunnel global we can ensure that the test will run a bajillion times faster by not tearing down the tunnel every time it closes/quits a Sauce::Selenium2 driver.

Currently I still have some custom-code locally that handles wrapping each "Scenario" (in cucumber parlance) with something that creates a new job on Sauce and handles closing the browser when it's completed. Effectively this:

Around('@selenium') do |scenario, block|
  session_id = nil

  if sauce?
    Sauce.config do |config|
      config.build = ENV['BUILD_NUMBER'] || 0
      config.name = "#{scenario.feature.file} - #{scenario.name}"
      config.browser_url = ENV['BASE_URL'] || 'http://127.0.0.1:3000'
    end

    Capybara.current_driver = :sauce
    # I will need this for later, driver.browser should be an instance of
    # Sauce::Selenium2 at this point
    driver = Capybara.current_session.driver
    session_id = driver.browser.session_id
  end

  block.call

  if sauce? and !session_id.nil?
    driver.browser.quit # finish the job in Sauce Labs
    driver.instance_variable_set(:@browser, nil) # This is necessary to generate a new @browser in the "next" scenario

    config = Sauce::Config.new
    sauce_url = "http://#{config.username}:#{config.access_key}@saucelabs.com/rest/v1/#{config.username}/jobs/#{session_id}"

    data = {
            :passed => !scenario.failed?,
            'custom-data' => {:commit => ENV['GIT_COMMIT'],
                              :node_name => ENV['NODE_NAME'],
                              :job_name => ENV['JOB_NAME']}}
    response = Typhoeus::Request.put(sauce_url,
                                      :headers => {:Content_Type => "application/json"},
                                      :body => JSON::dump(data))
    puts "Sending meta-data to Sauce Labs returned: #{response.code}"
  end
end

I'm still thinking of how to integrate portions of this into the sauce gem itself, but I wanted to get the rest of the code in front of some more eyes.

@ghost ghost assigned santiycr Mar 13, 2012
@rtyler
Copy link
Contributor Author

rtyler commented Mar 13, 2012

I'm going to go ahead an assign @santiycr to get some eyeballs on this :)

@santiycr
Copy link
Contributor

checking...

@rtyler
Copy link
Contributor Author

rtyler commented Mar 15, 2012

I know you're busy, but have you had a chance to look at this yet? I'm going to base my work on #35 and #36 off of this so I can use rspec and some cleaner connection code

:port => uri.port,
:domain => uri.host})

$sauce_tunnel = Sauce::Connect.new(options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rtyler should url.host and uri.port be set to the capybara.app_host? Isn't this the REST host and port that Connect will use to ask sauce for a tunnel box?
Also, Connect 2 doesn't need a :domain anymore

santiycr added a commit that referenced this pull request Mar 17, 2012
DRAFT: Allow Capybara/Cucumber tests to use one tunnel and multiple drivers
@santiycr santiycr merged commit 41d2ec4 into sauce-archives:master Mar 17, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants