2016-09-01 18:46:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
require "selenium-webdriver"
|
|
|
|
require 'shared_selenium_session'
|
2016-10-13 22:50:03 -04:00
|
|
|
require 'rspec/shared_spec_matchers'
|
|
|
|
|
2017-08-11 14:37:43 -04:00
|
|
|
browser_options = ::Selenium::WebDriver::Firefox::Options.new()
|
|
|
|
browser_options.args << '--headless' if ENV['HEADLESS']
|
2017-08-15 14:50:04 -04:00
|
|
|
browser_options.add_preference 'dom.file.createInChild', true
|
2017-08-11 14:37:43 -04:00
|
|
|
# browser_options.add_option("log", {"level": "trace"})
|
2017-08-02 15:10:56 -04:00
|
|
|
|
2016-10-13 22:50:03 -04:00
|
|
|
Capybara.register_driver :selenium_marionette do |app|
|
2017-08-07 16:21:11 -04:00
|
|
|
# ::Selenium::WebDriver.logger.level = "debug"
|
2016-10-13 22:50:03 -04:00
|
|
|
Capybara::Selenium::Driver.new(
|
|
|
|
app,
|
2017-08-11 14:37:43 -04:00
|
|
|
browser: :firefox,
|
2017-10-02 18:39:25 -04:00
|
|
|
desired_capabilities: {marionette: true, 'moz:webdriverClick': true},
|
2017-08-11 14:37:43 -04:00
|
|
|
options: browser_options
|
2017-08-07 16:21:11 -04:00
|
|
|
# Get a trace level log from geckodriver
|
|
|
|
# :driver_opts => { args: ['-vv'] }
|
2016-10-13 22:50:03 -04:00
|
|
|
)
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|
|
|
|
|
2016-10-28 16:08:20 -04:00
|
|
|
Capybara.register_driver :selenium_marionette_clear_storage do |app|
|
|
|
|
Capybara::Selenium::Driver.new(
|
|
|
|
app,
|
|
|
|
browser: :firefox,
|
2017-10-06 17:07:16 -04:00
|
|
|
desired_capabilities: {marionette: true, 'moz:webdriverClick': true},
|
2016-10-28 16:08:20 -04:00
|
|
|
clear_local_storage: true,
|
2017-08-11 14:37:43 -04:00
|
|
|
clear_session_storage: true,
|
|
|
|
options: browser_options
|
2016-10-28 16:08:20 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-08-07 16:21:11 -04:00
|
|
|
|
|
|
|
|
2016-09-01 18:46:56 -04:00
|
|
|
module TestSessions
|
2016-10-13 22:50:03 -04:00
|
|
|
SeleniumMarionette = Capybara::Session.new(:selenium_marionette, TestApp)
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
skipped_tests = [
|
|
|
|
:response_headers,
|
|
|
|
:status_code,
|
|
|
|
:trigger
|
|
|
|
]
|
2017-05-02 12:35:08 -04:00
|
|
|
skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
|
2016-09-01 18:46:56 -04:00
|
|
|
|
2016-10-13 22:50:03 -04:00
|
|
|
Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, "selenium", capybara_skip: skipped_tests
|
2016-09-01 18:46:56 -04:00
|
|
|
|
|
|
|
RSpec.describe "Capybara::Session with firefox" do
|
2017-05-08 18:12:33 -04:00
|
|
|
include Capybara::SpecHelper
|
2016-10-13 22:50:03 -04:00
|
|
|
include_examples "Capybara::Session", TestSessions::SeleniumMarionette, :selenium_marionette
|
|
|
|
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumMarionette, :selenium_marionette
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.describe Capybara::Selenium::Driver do
|
|
|
|
before do
|
2017-10-06 17:07:16 -04:00
|
|
|
@driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox, options: browser_options)
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#quit' do
|
|
|
|
it "should reset browser when quit" do
|
|
|
|
expect(@driver.browser).to be
|
|
|
|
@driver.quit
|
|
|
|
#access instance variable directly so we don't create a new browser instance
|
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
|
|
|
end
|
2016-11-23 14:53:57 -05:00
|
|
|
|
|
|
|
context "with errors" do
|
|
|
|
before do
|
|
|
|
@original_browser = @driver.browser
|
|
|
|
end
|
|
|
|
after do
|
|
|
|
# Ensure browser is actually quit so we don't leave hanging processe
|
|
|
|
RSpec::Mocks.space.proxy_for(@original_browser).reset
|
|
|
|
@original_browser.quit
|
|
|
|
end
|
|
|
|
|
|
|
|
it "warns UnknownError returned during quit because the browser is probably already gone" do
|
|
|
|
expect_any_instance_of(Capybara::Selenium::Driver).to receive(:warn).with(/random message/)
|
|
|
|
allow(@driver.browser).to(
|
|
|
|
receive(:quit)
|
|
|
|
.and_raise(Selenium::WebDriver::Error::UnknownError, "random message")
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { @driver.quit }.not_to raise_error
|
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores silenced UnknownError returned during quit because the browser is almost definitely already gone" do
|
|
|
|
expect_any_instance_of(Capybara::Selenium::Driver).not_to receive(:warn)
|
|
|
|
allow(@driver.browser).to(
|
|
|
|
receive(:quit)
|
|
|
|
.and_raise(Selenium::WebDriver::Error::UnknownError, "Error communicating with the remote browser")
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { @driver.quit }.not_to raise_error
|
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|
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::SeleniumMarionette
|
|
|
|
@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_marionette_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
|
|
|
|
|