Pushing changes that should enable BrowserStack. Partly pushing to see if we get these results in Travis.

This commit is contained in:
Jack Walker
2020-04-14 16:21:40 +10:00
parent 7a27db0b3d
commit a271d7656b
7 changed files with 225 additions and 5 deletions

View File

@@ -13,6 +13,10 @@ require 'core/bootstrap.rb'
require 'rack/test'
require 'curb'
require 'rest-client'
require 'yaml'
require 'selenium-webdriver'
require 'browserstack/local'
require 'byebug'
# Require supports
Dir['spec/support/*.rb'].each do |f|
@@ -22,6 +26,13 @@ end
ENV['RACK_ENV'] ||= 'test'
ARGV = []
# BrowserStack config
TASK_ID = (ENV['TASK_ID'] || 0).to_i
CONFIG_NAME = ENV['CONFIG_NAME'] || 'browserstack'
CONFIG = YAML.safe_load(File.read("./spec/support/#{CONFIG_NAME}.config.yml"))
CONFIG['user'] = ENV['BROWSERSTACK_USERNAME'] || CONFIG['user']
CONFIG['key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || CONFIG['key']
ActiveRecord::Base.logger = nil
OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')]
OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:':memory:')
@@ -46,4 +57,30 @@ RSpec.configure do |config|
raise ActiveRecord::Rollback
end
end
# BrowserStack
config.around(:example) do |example|
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
@caps["name"] = ENV['name'] || example.metadata[:name] || example.metadata[:file_path].split('/').last.split('.').first
enable_local = @caps["browserstack.local"] && @caps["browserstack.local"].to_s == "true"
# Code to start browserstack local before start of test
if enable_local
@bs_local = BrowserStack::Local.new
bs_local_args = { "key" => CONFIG['key'], "forcelocal" => true }
@bs_local.start(bs_local_args)
@caps["browserstack.local"] = true
end
@driver = Selenium::WebDriver.for(:remote,
:url => "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
:desired_capabilities => @caps)
begin
example.run
ensure
@driver.quit
# Code to stop browserstack local after end of test
@bs_local.stop if enable_local
end
end
end