lib/sauce/cucumber.rb in sauce-cucumber-2.4.1 vs lib/sauce/cucumber.rb in sauce-cucumber-3.0.0
- old
+ new
@@ -1,9 +1,10 @@
require 'capybara'
require 'cucumber'
require 'sauce/job'
require 'sauce/capybara'
+require 'sauce/utilities'
module Sauce
module Capybara
module Cucumber
def use_sauce_driver
@@ -21,10 +22,20 @@
scenario, feature = _scenario_and_feature_name(scenario)
return "#{feature} - #{scenario}"
end
module_function :name_from_scenario
+ def file_name_from_scenario(scenario)
+ if scenario.instance_of? ::Cucumber::Ast::OutlineTable::ExampleRow
+ table = scenario.instance_variable_get(:@table)
+ outline = table.instance_variable_get(:@scenario_outline)
+ return outline.feature.file
+ end
+ return scenario.location.file
+ end
+ module_function :file_name_from_scenario
+
def jenkins_name_from_scenario(scenario)
# Special behavior to handle Scenario Outlines
if scenario.instance_of? ::Cucumber::Ast::OutlineTable::ExampleRow
table = scenario.instance_variable_get(:@table)
outline = table.instance_variable_get(:@scenario_outline)
@@ -53,29 +64,25 @@
ENV['JENKINS_SERVER_COOKIE']
end
module_function :using_jenkins?
def around_hook(scenario, block)
+ if Sauce::Config.new[:start_tunnel]
+ Sauce::Utilities::Connect.start(:quiet => true)
+ end
+
::Capybara.current_driver = :sauce
- driver = ::Capybara.current_session.driver
- # This session_id is the job ID used by Sauce Labs, we're pulling it
- # off of the driver now to make sure we have it after `block.call`
- session_id = driver.browser.session_id
+
job_name = Sauce::Capybara::Cucumber.name_from_scenario(scenario)
custom_data = {}
if using_jenkins?
custom_data.merge!({:commit => ENV['GIT_COMMIT'] || ENV['SVN_COMMIT'],
:jenkins_node => ENV['NODE_NAME'],
:jenkins_job => ENV['JOB_NAME']})
end
- job = Sauce::Job.new('id' => session_id,
- 'name' => job_name,
- 'custom-data' => custom_data)
- job.save unless job.nil?
-
Sauce.config do |c|
c[:name] = Sauce::Capybara::Cucumber.name_from_scenario(scenario)
end
if using_jenkins?
@@ -90,19 +97,38 @@
# OnDemand plugin for Jenkins to co-operate, we need to double it up as
# well
output << "job-name=#{Sauce::Capybara::Cucumber.jenkins_name_from_scenario(scenario)}"
puts output.join(' ')
end
+ filename = file_name_from_scenario(scenario)
+ Sauce::Config.new.browsers_for_file("./#{filename}").each do |os, browser, version|
+ @selenium = Sauce::Selenium2.new({:os => os,
+ :browser => browser,
+ :browser_version => version,
+ :job_name => job_name})
- block.call
+ Sauce.driver_pool[Thread.current.object_id] = @selenium
- # Quit the driver to allow for the generation of a new session_id
- driver.finish!
+ driver = ::Capybara.current_session.driver
+ # This session_id is the job ID used by Sauce Labs, we're pulling it
+ # off of the driver now to make sure we have it after `block.call`
+ session_id = driver.browser.session_id
- unless job.nil?
- job.passed = !scenario.failed?
- job.save
+ job = Sauce::Job.new('id' => session_id,
+ 'name' => job_name,
+ 'custom-data' => custom_data)
+ job.save unless job.nil?
+
+ block.call
+
+ # Quit the driver to allow for the generation of a new session_id
+ driver.finish!
+
+ unless job.nil?
+ job.passed = !scenario.failed?
+ job.save
+ end
end
end
module_function :around_hook
end
end
@@ -115,7 +141,12 @@
end
Around('@selenium') do |scenario, block|
Sauce::Capybara::Cucumber.around_hook(scenario, block)
end
+
+ at_exit do
+ Sauce::Utilities::Connect.close
+ end
+
rescue NoMethodError # This makes me sad
end