2016-09-01 18:46:56 -04:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2016-09-01 18:46:56 -04:00
|
|
|
require 'spec_helper'
|
2018-07-10 17:18:39 -04:00
|
|
|
require 'selenium-webdriver'
|
2016-09-01 18:46:56 -04:00
|
|
|
require 'shared_selenium_session'
|
2016-10-13 22:50:03 -04:00
|
|
|
require 'rspec/shared_spec_matchers'
|
|
|
|
|
2018-02-28 19:11:41 -05:00
|
|
|
browser_options = ::Selenium::WebDriver::Firefox::Options.new
|
2017-08-11 14:37:43 -04:00
|
|
|
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
|
|
|
|
2018-06-17 13:29:46 -04:00
|
|
|
browser_options.profile = Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
|
|
|
|
profile['browser.download.dir'] = Capybara.save_path
|
|
|
|
profile['browser.download.folderList'] = 2
|
|
|
|
profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv'
|
|
|
|
end
|
|
|
|
|
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,
|
2018-02-28 19:11:41 -05:00
|
|
|
desired_capabilities: { marionette: true, 'moz:webdriverClick': true },
|
2018-06-17 13:29:46 -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,
|
2018-02-28 19:11:41 -05:00
|
|
|
desired_capabilities: { marionette: 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
|
|
|
|
|
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
|
|
|
|
|
2018-02-28 19:11:41 -05:00
|
|
|
skipped_tests = %i[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
|
|
|
|
2018-03-16 14:10:31 -04:00
|
|
|
$stdout.puts `#{Selenium::WebDriver::Firefox.driver_path} --version` if ENV['CI']
|
2018-03-13 17:22:50 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, 'selenium', capybara_skip: skipped_tests do |example|
|
2018-07-05 14:50:43 -04:00
|
|
|
case example.metadata[:full_description]
|
|
|
|
when 'Capybara::Session selenium node #click should allow multiple modifiers'
|
|
|
|
pending "Firefox doesn't generate an event for shift+control+click" if marionette_gte?(62, @session)
|
|
|
|
when /^Capybara::Session selenium node #double_click/
|
|
|
|
pending "selenium-webdriver/geckodriver doesn't generate double click event" if marionette_lt?(59, @session)
|
|
|
|
when 'Capybara::Session selenium #accept_prompt should accept the prompt with a blank response when there is a default'
|
2018-08-31 16:33:42 -04:00
|
|
|
pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if marionette_lt?(63, @session)
|
2018-07-24 17:13:03 -04:00
|
|
|
when 'Capybara::Session selenium #attach_file with multipart form should fire change once for each set of files uploaded'
|
|
|
|
pending 'Gekcodriver appends files so we have to first call clear for multiple files which creates an extra change ' \
|
|
|
|
'if files are already set'
|
|
|
|
when 'Capybara::Session selenium #attach_file with multipart form should fire change once when uploading multiple files from empty'
|
|
|
|
pending "FF < 62 doesn't support setting all files at once" if marionette_lt?(62, @session)
|
2018-09-05 21:19:07 -04:00
|
|
|
when 'Capybara::Session selenium #accept_confirm should work with nested modals'
|
|
|
|
skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if marionette_gte?(63, @session)
|
2018-07-05 14:50:43 -04:00
|
|
|
end
|
|
|
|
end
|
2016-09-01 18:46:56 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
RSpec.describe 'Capybara::Session with firefox' do # rubocop:disable RSpec/MultipleDescribes
|
2017-05-08 18:12:33 -04:00
|
|
|
include Capybara::SpecHelper
|
2018-07-10 17:18:39 -04:00
|
|
|
include_examples 'Capybara::Session', TestSessions::SeleniumMarionette, :selenium_marionette
|
2016-10-13 22:50:03 -04:00
|
|
|
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
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should reset browser when quit' do
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(@driver.browser).to be_truthy
|
2016-09-01 18:46:56 -04:00
|
|
|
@driver.quit
|
2018-02-28 19:11:41 -05:00
|
|
|
# access instance variable directly so we don't create a new browser instance
|
2016-09-01 18:46:56 -04:00
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
|
|
|
end
|
2016-11-23 14:53:57 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with errors' do
|
2016-11-23 14:53:57 -05:00
|
|
|
before do
|
|
|
|
@original_browser = @driver.browser
|
|
|
|
end
|
2018-06-19 16:57:42 -04:00
|
|
|
|
2016-11-23 14:53:57 -05:00
|
|
|
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
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'warns UnknownError returned during quit because the browser is probably already gone' do
|
2018-04-27 14:01:47 -04:00
|
|
|
allow(@driver).to receive(:warn)
|
2016-11-23 14:53:57 -05:00
|
|
|
allow(@driver.browser).to(
|
|
|
|
receive(:quit)
|
2018-07-10 17:18:39 -04:00
|
|
|
.and_raise(Selenium::WebDriver::Error::UnknownError, 'random message')
|
2016-11-23 14:53:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect { @driver.quit }.not_to raise_error
|
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(@driver).to have_received(:warn).with(/random message/)
|
2016-11-23 14:53:57 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'ignores silenced UnknownError returned during quit because the browser is almost definitely already gone' do
|
2018-04-27 14:01:47 -04:00
|
|
|
allow(@driver).to receive(:warn)
|
2016-11-23 14:53:57 -05:00
|
|
|
allow(@driver.browser).to(
|
|
|
|
receive(:quit)
|
2018-07-10 17:18:39 -04:00
|
|
|
.and_raise(Selenium::WebDriver::Error::UnknownError, 'Error communicating with the remote browser')
|
2016-11-23 14:53:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect { @driver.quit }.not_to raise_error
|
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(@driver).not_to have_received(:warn)
|
2016-11-23 14:53:57 -05:00
|
|
|
end
|
|
|
|
end
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|
2016-10-28 16:08:20 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'storage' do
|
|
|
|
describe '#reset!' do
|
|
|
|
it 'does not clear either storage by default' do
|
2016-10-28 16:08:20 -04:00
|
|
|
@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
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'clears storage when set' do
|
2016-10-28 16:08:20 -04:00
|
|
|
@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
|
2018-06-06 16:21:33 -04:00
|
|
|
|
|
|
|
RSpec.describe Capybara::Selenium::Node do
|
2018-07-10 17:18:39 -04:00
|
|
|
context '#click' do
|
|
|
|
it 'warns when attempting on a table row' do
|
2018-06-06 16:21:33 -04:00
|
|
|
session = TestSessions::SeleniumMarionette
|
|
|
|
session.visit('/tables')
|
|
|
|
tr = session.find(:css, '#agent_table tr:first-child')
|
|
|
|
allow(tr.base).to receive(:warn)
|
|
|
|
tr.click
|
2018-06-06 19:11:47 -04:00
|
|
|
expect(tr.base).to have_received(:warn).with(/Clicking the first cell in the row instead/)
|
2018-06-06 16:21:33 -04:00
|
|
|
end
|
2018-07-03 16:31:31 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should allow multiple modifiers', requires: [:js] do
|
2018-07-03 16:31:31 -04:00
|
|
|
session = TestSessions::SeleniumMarionette
|
|
|
|
session.visit('with_js')
|
2018-07-05 19:29:26 -04:00
|
|
|
# Firefox v62+ doesn't generate an event for control+shift+click
|
2018-07-03 16:31:31 -04:00
|
|
|
session.find(:css, '#click-test').click(:alt, :ctrl, :meta)
|
2018-07-05 19:29:26 -04:00
|
|
|
# it also triggers a contextmenu event when control is held so don't check click type
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(session).to have_link('Has been alt control meta')
|
2018-07-03 16:31:31 -04:00
|
|
|
end
|
2018-06-06 16:21:33 -04:00
|
|
|
end
|
|
|
|
end
|