`sauce_whisk`宝石是否与水豚兼容

时间:2015-09-09 13:04:31

标签: ruby-on-rails capybara rspec-rails capybara-webkit saucelabs

我正在运行一个rails应用程序并将我的测试用例写在capybara中。 我需要用酱汁实验室来运行所有这些。 我尝试使用sauce_whisk,但那些用水豚写的东西不起作用。

.... it "should google", :run_on_sauce => true do visit "http://google.com" end ...不起作用

,而

... it "should google too", :run_on_sauce => true do driver = Selenium::WebDriver.for :firefox driver.get "http://google.com" end ...有效。

有人可以帮忙解决这个问题吗? 我点了这个链接:https://docs.saucelabs.com/tutorials/ruby/

1 个答案:

答案 0 :(得分:2)

这是一个使用sauce_whisk和Capybara的几个工作实现的例子。

以下是使用Capybara和RSpec的简单示例:

jobname = scenario.full_description
sessionid = ::Capybara.current_session.driver.browser.session_id
::Capybara.current_session.driver.quit

job = SauceWhisk::Jobs.fetch sessionid
job.name = jobname
job.save

if scenario.exception
  SauceWhisk::Jobs.fail_job sessionid
else
  SauceWhisk::Jobs.pass_job sessionid
end

使用Cucumber的实现稍微复杂一些:

require "capybara/cucumber"
require "selenium/webdriver"
require 'sauce_whisk'

Around do |scenario, block|
  block.call
  sessionid = ::Capybara.current_session.driver.browser.session_id
  ::Capybara.current_session.driver.quit

  jobname = "#{scenario.feature.name} - #{scenario.name}"

  job = SauceWhisk::Jobs.fetch sessionid
  job.name = jobname
  job.passed = scenario.passed? ? true : false
  job.save
end

Before do | scenario |
  Capybara.register_driver :selenium do |app|
    capabilities = {
      :version => "48.0",
      :browserName => "chrome",
      :platform => "OS X 10.11"
    }

    url = "http://<username>:<access_key>@ondemand.saucelabs.com:80/wd/hub".strip
    Capybara::Selenium::Driver.new(app,
                                   :browser => :remote, :url => url,
                                   :desired_capabilities => capabilities)
  end
  Capybara.default_wait_time = 10
  Capybara.current_driver = :selenium

  job = SauceWhisk::Jobs.fetch ::Capybara.current_session.driver.browser.session_id
  job.name = "#{scenario.feature.name} - #{scenario.name}"
  job.save
end

来源:

https://github.com/saucelabs-sample-test-frameworks?utf8=%E2%9C%93&query=Capybara