1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/spec/selenium_spec_chrome.rb

68 lines
2.6 KiB
Ruby
Raw Normal View History

2016-03-07 19:52:19 -05:00
# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
require 'spec_helper'
2015-05-21 14:00:36 -04:00
require 'selenium-webdriver'
require 'shared_selenium_session'
2018-01-09 17:05:50 -05:00
require 'rspec/shared_spec_matchers'
2015-07-21 20:43:11 -04:00
2018-02-28 19:11:41 -05:00
CHROME_DRIVER = ENV['HEADLESS'] ? :selenium_chrome_headless : :selenium_chrome
2017-06-15 19:25:01 -04:00
# if ENV['HEADLESS'] && ENV['TRAVIS']
# Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta'
# end
Capybara.register_driver :selenium_chrome_clear_storage do |app|
chrome_options = {
browser: :chrome,
2018-01-09 17:05:50 -05:00
options: ::Selenium::WebDriver::Chrome::Options.new
}
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))
end
module TestSessions
Chrome = Capybara::Session.new(CHROME_DRIVER, TestApp)
end
2018-02-28 19:11:41 -05:00
skipped_tests = %i[response_headers status_code trigger]
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
2018-02-28 19:11:41 -05:00
skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
2018-03-16 14:10:31 -04:00
$stdout.puts `#{Selenium::WebDriver::Chrome.driver_path} --version` if ENV['CI']
2018-03-13 17:22:50 -04:00
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with chrome" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::Chrome, CHROME_DRIVER
2018-01-09 17:05:50 -05:00
include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_DRIVER
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
expect(@session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
expect(@session.evaluate_script('Object.keys(sessionStorage)')).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
expect(@session.evaluate_script('Object.keys(localStorage)')).to be_empty
expect(@session.evaluate_script('Object.keys(sessionStorage)')).to be_empty
end
end
end
end