From 302f3a489693982aa456c2e2fd7eb4e2a37b83ea Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 26 Feb 2018 09:21:30 +0100 Subject: [PATCH] Add Selenium support file for specs and include headless for Vagrant Signed-off-by: Sebastian Serth --- Gemfile | 3 ++- Gemfile.lock | 7 ++++++- spec/support/selenium.rb | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 spec/support/selenium.rb diff --git a/Gemfile b/Gemfile index 8482ca69..a1b2494e 100644 --- a/Gemfile +++ b/Gemfile @@ -66,12 +66,13 @@ end group :test do gem 'autotest-rails' gem 'capybara' + gem 'capybara-selenium' + gem 'headless' gem 'codeclimate-test-reporter', require: false gem 'database_cleaner' gem 'nyan-cat-formatter' gem 'rake' gem 'rspec-autotest' gem 'rspec-rails' - gem 'selenium-webdriver' gem 'simplecov', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 43737a82..04ff4e15 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,6 +91,9 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) + capybara-selenium (0.0.6) + capybara + selenium-webdriver carrierwave (1.2.2) activemodel (>= 4.0.0) activesupport (>= 4.0.0) @@ -144,6 +147,7 @@ GEM forgery (0.7.0) globalid (0.4.1) activesupport (>= 4.2.0) + headless (2.3.1) highline (1.7.10) http-cookie (1.0.3) domain_name (~> 0.5) @@ -404,6 +408,7 @@ DEPENDENCIES capistrano-upload-config capistrano3-puma capybara + capybara-selenium carrierwave codeclimate-test-reporter coffee-rails @@ -416,6 +421,7 @@ DEPENDENCIES factory_bot_rails faye-websocket forgery + headless highline ims-lti (= 1.1.10) jbuilder @@ -444,7 +450,6 @@ DEPENDENCIES rubyzip sass-rails sdoc - selenium-webdriver simplecov slim sorcery diff --git a/spec/support/selenium.rb b/spec/support/selenium.rb new file mode 100644 index 00000000..4aeb28de --- /dev/null +++ b/spec/support/selenium.rb @@ -0,0 +1,21 @@ +require 'capybara/rspec' +require 'selenium/webdriver' + +if ENV['HEADLESS_TEST'] == 'true' || ENV['USER'] == 'vagrant' + require 'headless' + + headless = Headless.new + headless.start +end + +Capybara.register_driver :selenium do |app| + profile = Selenium::WebDriver::Firefox::Profile.new + profile['intl.accept_languages'] = 'en' + capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(elementScrollBehavior: 1) + options = Selenium::WebDriver::Firefox::Options.new + options.profile = profile + driver = Capybara::Selenium::Driver.new(app, browser: :firefox, desired_capabilities: capabilities, options: options) + driver.browser.manage.window.resize_to(1280, 960) + driver +end +Capybara.javascript_driver = :selenium