2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2013-02-25 14:13:03 -05:00
|
|
|
require 'spec_helper'
|
2015-05-21 14:00:36 -04:00
|
|
|
require 'selenium-webdriver'
|
2016-09-01 18:46:56 -04:00
|
|
|
require 'shared_selenium_session'
|
2015-07-21 20:43:11 -04:00
|
|
|
|
2013-02-25 14:13:03 -05:00
|
|
|
Capybara.register_driver :selenium_chrome do |app|
|
2013-11-18 15:47:05 -05:00
|
|
|
args = ENV['TRAVIS'] ? ['no-sandbox' ] : []
|
2017-05-03 18:21:07 -04:00
|
|
|
if ENV['CAPYBARA_CHROME_HEADLESS']
|
|
|
|
args << 'headless'
|
|
|
|
Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta' if ENV['TRAVIS']
|
|
|
|
end
|
2013-11-18 15:47:05 -05:00
|
|
|
Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)
|
2013-02-25 14:13:03 -05:00
|
|
|
end
|
|
|
|
|
2016-10-28 16:08:20 -04:00
|
|
|
Capybara.register_driver :selenium_chrome_clear_storage do |app|
|
|
|
|
args = ENV['TRAVIS'] ? ['no-sandbox' ] : []
|
2017-05-03 18:21:07 -04:00
|
|
|
if ENV['CAPYBARA_CHROME_HEADLESS']
|
|
|
|
args << 'headless'
|
|
|
|
Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta' if ENV['TRAVIS']
|
|
|
|
end
|
2016-10-28 16:08:20 -04:00
|
|
|
Capybara::Selenium::Driver.new(app, :browser => :chrome,
|
|
|
|
:args => args,
|
|
|
|
clear_local_storage: true,
|
|
|
|
clear_session_storage: true)
|
|
|
|
end
|
|
|
|
|
2013-02-25 14:13:03 -05:00
|
|
|
module TestSessions
|
2015-05-21 14:00:36 -04:00
|
|
|
Chrome = Capybara::Session.new(:selenium_chrome, TestApp)
|
2013-02-25 14:13:03 -05:00
|
|
|
end
|
|
|
|
|
2016-10-20 12:53:42 -04:00
|
|
|
skipped_tests = [:response_headers, :status_code, :trigger]
|
2017-05-02 12:35:08 -04:00
|
|
|
skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
|
2017-05-03 17:29:49 -04:00
|
|
|
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
|
|
|
|
skipped_tests << :windows if ENV['TRAVIS'] && ENV['CAPYBARA_CHROME_HEADLESS']
|
2016-10-13 22:50:03 -04:00
|
|
|
|
2016-10-20 12:53:42 -04:00
|
|
|
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: skipped_tests
|
2016-09-01 18:46:56 -04:00
|
|
|
|
|
|
|
RSpec.describe "Capybara::Session with chrome" do
|
2017-05-08 18:12:33 -04:00
|
|
|
include Capybara::SpecHelper
|
2016-09-01 18:46:56 -04:00
|
|
|
include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
|
2016-10-28 16:08:20 -04:00
|
|
|
|
|
|
|
context "storage" do
|
|
|
|
describe "#reset!" do
|
|
|
|
it "does not clear either storage by default" do
|
|
|
|
@session = TestSessions::Chrome
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.find(:css, '#set-storage').click
|
|
|
|
@session.reset!
|
|
|
|
@session.visit('/with_js')
|
|
|
|
expect(@session.driver.browser.local_storage.keys).not_to be_empty
|
|
|
|
expect(@session.driver.browser.session_storage.keys).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "clears storage when set" do
|
|
|
|
@session = Capybara::Session.new(:selenium_chrome_clear_storage, TestApp)
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.find(:css, '#set-storage').click
|
|
|
|
@session.reset!
|
|
|
|
@session.visit('/with_js')
|
|
|
|
expect(@session.driver.browser.local_storage.keys).to be_empty
|
|
|
|
expect(@session.driver.browser.session_storage.keys).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|