diff --git a/Gemfile b/Gemfile index fd011be10..44bb09887 100644 --- a/Gemfile +++ b/Gemfile @@ -57,7 +57,6 @@ end group :development, :test do gem "rspec-rails", '~> 3.5.2' - gem "capybara", '~> 2.4.4' gem "byebug" end @@ -71,6 +70,8 @@ group :test do gem 'shoulda', ">= 3.5" gem 'fabrication' + gem "capybara", '~> 2.4.4' + gem 'capybara-selenium' gem 'faker' end diff --git a/Gemfile.lock b/Gemfile.lock index de4b59982..ebf5a4ed6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,11 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + capybara-selenium (0.0.6) + capybara + selenium-webdriver + childprocess (0.8.0) + ffi (~> 1.0, >= 1.0.11) chronic (0.10.2) coderay (1.1.0) coffee-rails (4.1.0) @@ -152,6 +157,7 @@ GEM i18n (~> 0.5) faraday (0.9.1) multipart-post (>= 1.2, < 3) + ffi (1.9.23) foreman (0.77.0) dotenv (~> 1.0.2) thor (~> 0.19.1) @@ -312,6 +318,7 @@ GEM rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) ruby-progressbar (1.7.1) + rubyzip (1.2.1) sass (3.4.21) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -321,6 +328,9 @@ GEM tilt (>= 1.1, < 3) select2-rails (4.0.1) thor (~> 0.14) + selenium-webdriver (3.9.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) shoulda (3.5.0) shoulda-context (~> 1.0, >= 1.0.1) shoulda-matchers (>= 1.4.1, < 3.0) @@ -389,6 +399,7 @@ DEPENDENCIES capistrano-rails (~> 1.1) capistrano-rbenv (~> 2.1) capybara (~> 2.4.4) + capybara-selenium coffee-rails dalli database_cleaner (= 1.3.0) diff --git a/spec/features/hello_spec.rb b/spec/features/hello_spec.rb new file mode 100644 index 000000000..460dd1c6b --- /dev/null +++ b/spec/features/hello_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +feature "hello capybara" do + scenario "works" do + visit("/") + expect(page).to have_xpath('/html/body/nav/div/div/div/div[2]/div/ul/li[1]') + end +end diff --git a/spec/features/login_spec.rb b/spec/features/login_spec.rb new file mode 100644 index 000000000..424537a07 --- /dev/null +++ b/spec/features/login_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +feature "login" do + scenario "valid credentials are provided" do + visit("/") + #click_button 'Login' + + #fill_in 'E-mail', 'admin@timeoverflow.org' + #fill_in 'Password', '1234test' + page.save_screenshot("wat.png") + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f88136616..0b42904fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,9 +6,11 @@ require 'rspec/rails' require 'rspec/autorun' require 'capybara/rails' +require 'capybara/rspec' require 'database_cleaner' require 'fabrication' require 'faker' +require 'selenium/webdriver' I18n.reload! # Requires supporting ruby files with custom matchers and macros, etc, @@ -91,3 +93,20 @@ def set_browser_locale(locale) end RSpec.configure(&:infer_spec_type_from_file_location!) + +Capybara.register_driver :chrome do |app| + Capybara::Selenium::Driver.new(app, browser: :chrome) +end + +Capybara.register_driver :headless_chrome do |app| + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( + chromeOptions: { args: %w(headless disable-gpu) } + ) + + Capybara::Selenium::Driver.new app, + browser: :chrome, + desired_capabilities: capabilities +end + +Capybara.javascript_driver = :headless_chrome +Capybara.default_driver = :headless_chrome