在 VPN 后面的站点的 BrowserStack 上使用 Cucumber 进行自动测试

Automated testing with Cucumber on BrowserStack of site behind VPN

我正在尝试让我的 Cucumber 测试在 BrowserStack 上运行。问题是我们的测试环境都在 VPN 后面。 BrowserStack 的文档说,只要设置本地测试就可以了!它没有。测试启动,但它们没有通过我的本地机器重新路由以获取我的 vpn 凭据。 我按照 BrowserStack 的指示下载了二进制文件。我用命令

启动它
~ ./BrowserStackLocal <my BS key> -forcelocal

然后我 运行 我的测试(在不同的终端 window):

bundle exec cucumber CURRENT_BROWSER=browserstack features/01_login.feature 

我的 env.rb 看起来像这样:

require 'cucumber/rails'

Capybara.default_selector = :css

cb = ENV['CURRENT_BROWSER']
testbrowser = cb ? cb.downcase.to_sym : :firefox
puts "-------------- current browser: #{testbrowser}........."
Capybara.register_driver :selenium do |app|
  if RbConfig::CONFIG['host_os'][/linux/] && testbrowser.to_s.eql?("CHROME".downcase)
    Capybara::Selenium::Driver.new(app, {:browser => :remote, :url => "http://127.0.0.1:9515"})
  else
    if testbrowser.eql?(:chrome)
      prefs = {
          :download => {
              :prompt_for_download => false,
              :default_directory => DownloadHelpers::PATH.to_s
          }
      }
      Capybara::Selenium::Driver.new(app, :browser => :chrome, :prefs => prefs, :switches => %w[--test-type])
    elsif testbrowser.eql?(:browserstack)
      stackToUse = ENV['BS_STACK'] || 'ie_9'
      json = JSON.load(open(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'browsers.json'))))
      config = json[stackToUse]
      unless config
        puts "invalid BS_STACK specified. Was '#{stackToUse}'"
        return
      end

      # Add default config
      config['name'] = "#{config['os']} #{config['os_version']} - #{Time.now.strftime '%Y-%m-%d %H:%M'}"
      config['acceptSslCert'] = true
      config['browserstack.debug'] = true
      Capybara::Selenium::Driver.new(app, :browser => :remote, :desired_capabilities => config, :url => "http://<BS_USERNAME>:<BS_PASSKEY>@hub.browserstack.com/wd/hub")
    elsif testbrowser.eql?(:internetexplorer)
      Capybara::Selenium::Driver.new(app, :browser => :internetexplorer, :switches => %w[--test-type])
    else
      profile = Selenium::WebDriver::Firefox::Profile.new
      profile
      profile["browser.download.dir"] = DownloadHelpers::PATH.to_s
      profile["browser.download.folderList"] = 2 # 2 - save to user defined location
      profile["browser.download.manager.alertOnEXEOpen"] = false
      profile["browser.helperApps.neverAsk.saveToDisk"] = "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream, data:application/csv"
      profile["browser.helperApps.alwaysAsk.force"] = false
      profile["browser.download.manager.showWhenStarting"] = false
      profile["browser.download.manager.focusWhenStarting"] = false
      profile["browser.download.useDownloadDir"] = true
      profile["browser.download.manager.alertOnEXEOpen"] = false
      profile["browser.download.manager.closeWhenDone"] = true
      profile["browser.download.manager.showAlertOnComplete"] = false
      profile["browser.download.manager.useWindow"] = false

profile["services.sync.prefs.sync.browser.download.manager.showWhenStarting"] = false
      profile["pdfjs.disabled"] = true
      Capybara::Selenium::Driver.new(app, :browser => testbrowser, :profile => profile)
    end
  end
end

ActionController::Base.allow_rescue = false

# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
  DatabaseCleaner.strategy = :transaction
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
#
#   Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
#     # { :except => [:widgets] } may not do what you expect here
#     # as tCucumber::Rails::Database.javascript_strategy overrides
#     # this setting.
#     DatabaseCleaner.strategy = :truncation
#   end
#
#   Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
#     DatabaseCleaner.strategy = :transaction
#   end
#

# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation

其他人使用这些相同的测试,而我们已经编写了数十个,因此确保我仍然可以 运行 在本地进行这些测试是最重要的。 当我进行 运行 测试时,它开始在 browserstack 上 运行,但它无法访问我尝试告诉它访问的任何站点。包括 http://localhost:3000/login 我联系了 BrowserStack 支持,他们问我是否设置了本地测试。 我得到的唯一错误是测试找不到要登录的 CSS 元素。当我通过 browserstack 观看自动化测试时,我可以看到它没有到达页面。它只是说 "Oops! This link appears to be broken." 任何建议将不胜感激。

BrowserStack 的支持回复了我。我必须有另一个配置 属性 就像 env.rb:

config['browserstack.local'] = true

现在我唯一的问题是 none 我们编写的功能似乎可以在 IE 上运行。所以我可以在 browserstack 上测试 chrome 或 firefox,但我已经设置了该功能。