teamcapybara--capybara/spec/selenium_spec_chrome.rb

63 lines
2.2 KiB
Ruby
Raw Normal View History

2016-03-08 00:52:19 +00:00
# frozen_string_literal: true
require 'spec_helper'
2015-05-21 18:00:36 +00:00
require 'selenium-webdriver'
require 'shared_selenium_session'
2015-07-22 00:43:11 +00:00
2017-06-15 23:25:01 +00:00
chrome_options = {
browser: :chrome,
options: ::Selenium::WebDriver::Chrome::Options.new(args: ENV['TRAVIS'] ? ['no-sandbox' ] : [])
}
if ENV['CAPYBARA_CHROME_HEADLESS']
chrome_options[:options].args << 'headless'
Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta' if ENV['TRAVIS']
end
Capybara.register_driver :selenium_chrome do |app|
2017-06-15 23:25:01 +00:00
Capybara::Selenium::Driver.new(app, chrome_options)
end
Capybara.register_driver :selenium_chrome_clear_storage do |app|
2017-06-15 23:25:01 +00:00
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: true, clear_session_storage: true))
end
module TestSessions
2015-05-21 18:00:36 +00:00
Chrome = Capybara::Session.new(:selenium_chrome, TestApp)
end
2016-10-20 16:53:42 +00:00
skipped_tests = [:response_headers, :status_code, :trigger]
skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
# 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-20 16:53:42 +00:00
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with chrome" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
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
end