/ / Test automatici con Cucumber su BrowserStack del sito dietro VPN - ruby, cetriolo, vpn, test automatici, browserstack

Test automatici con Cucumber su BrowserStack del sito dietro VPN - ruby, cetriolo, vpn, test automatici, browsstack

Sto cercando di far funzionare i miei test su CetrioloBrowserStack. Il problema è che i nostri ambienti di test sono tutti dietro una VPN. I documenti di BrowserStack dicono, basta installare test locali e funzionerà! Non funziona. I test si avviano, ma non vengono reindirizzati attraverso la mia macchina locale per raccogliere le mie credenziali VPN. Ho scaricato il file binario come indicato da BrowserStack. L'ho avviato con il comando

~ ./BrowserStackLocal <my BS key> -forcelocal

Quindi eseguo il test con (in una finestra di terminale diversa):

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

il mio env.rb ha questo aspetto:

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

Altre persone usano questi stessi test e noi abbiamoHo scritto dozzine, quindi assicurarmi di poter eseguire questi test localmente è fondamentale. Quando eseguo i test, inizia a funzionare su Browserstack, ma non può raggiungere nessuno dei siti che ho provato a dirgli di raggiungere. http://localhost:3000/login Ho contattato il supporto di BrowserStack e loroha chiesto se avessi impostato test locali. L'unico errore che ho riscontrato è che il test non riesce a trovare l'elemento CSS per l'accesso. Quando ho visto il test automatizzato attraverso il browser, posso vedere che non sta raggiungendo la pagina. Dice solo "Oops! Questo link sembra essere rotto". Qualunque suggerimento è ben accetto.

risposte:

2 per risposta № 1

Il supporto di BrowserStack mi è tornato in mente. Ho dovuto avere un'altra proprietà di configurazione simile a quella di env.rb:

config["browserstack.local"] = true

Ora il mio unico problema è che nessuna delle funzionalità che abbiamo scritto sembra funzionare su IE. Quindi posso testare chrome o firefox su browsstack, ma ho già avuto questa funzionalità.