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
|
|
|
|
2017-08-02 15:10:56 -04:00
|
|
|
CHROME_DRIVER = if ENV['HEADLESS'] then :selenium_chrome_headless else :selenium_chrome end
|
2017-06-15 19:25:01 -04:00
|
|
|
|
2017-08-02 15:10:56 -04:00
|
|
|
if ENV['HEADLESS'] && ENV['TRAVIS']
|
2017-08-01 14:29:12 -04:00
|
|
|
Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta'
|
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|
|
2017-08-01 14:29:12 -04:00
|
|
|
chrome_options = {
|
|
|
|
browser: :chrome,
|
|
|
|
options: ::Selenium::WebDriver::Chrome::Options.new()
|
|
|
|
}
|
2017-08-02 15:10:56 -04:00
|
|
|
chrome_options[:options].args << 'headless' if ENV['HEADLESS']
|
2017-06-15 19:25:01 -04:00
|
|
|
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: true, clear_session_storage: true))
|
2016-10-28 16:08:20 -04:00
|
|
|
end
|
|
|
|
|
2013-02-25 14:13:03 -05:00
|
|
|
module TestSessions
|
2017-08-01 14:29:12 -04:00
|
|
|
Chrome = Capybara::Session.new(CHROME_DRIVER, 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-03 17:29:49 -04:00
|
|
|
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
|
2017-08-02 15:10:56 -04:00
|
|
|
skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
|
2016-10-13 22:50:03 -04:00
|
|
|
|
2017-08-01 14:29:12 -04:00
|
|
|
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, 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
|
2017-08-01 14:29:12 -04:00
|
|
|
include_examples "Capybara::Session", TestSessions::Chrome, CHROME_DRIVER
|
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
|