2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
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'
|
2019-05-02 21:57:14 -04:00
|
|
|
require 'shared_selenium_node'
|
2018-01-09 17:05:50 -05:00
|
|
|
require 'rspec/shared_spec_matchers'
|
2015-07-21 20:43:11 -04:00
|
|
|
|
2018-10-26 14:59:22 -04:00
|
|
|
CHROME_DRIVER = :selenium_chrome
|
2017-06-15 19:25:01 -04:00
|
|
|
|
2019-06-09 15:05:41 -04:00
|
|
|
Selenium::WebDriver::Chrome.path = '/usr/bin/google-chrome-beta' if ENV['CI'] && ENV['CHROME_BETA']
|
2019-04-18 19:18:04 -04:00
|
|
|
|
2018-10-26 14:59:22 -04:00
|
|
|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
|
|
|
|
browser_options.headless! if ENV['HEADLESS']
|
2019-06-09 15:05:41 -04:00
|
|
|
browser_options.add_option(:w3c, ENV['W3C'] != 'false')
|
2018-06-17 13:29:46 -04:00
|
|
|
|
2018-10-26 14:59:22 -04:00
|
|
|
Capybara.register_driver :selenium_chrome do |app|
|
2018-11-20 17:20:46 -05:00
|
|
|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, timeout: 30).tap do |driver|
|
2018-10-26 14:59:22 -04:00
|
|
|
driver.browser.download_path = Capybara.save_path
|
|
|
|
end
|
2018-06-17 13:29:46 -04:00
|
|
|
end
|
|
|
|
|
2018-11-20 12:44:52 -05:00
|
|
|
Capybara.register_driver :selenium_chrome_not_clear_storage do |app|
|
2017-08-01 14:29:12 -04:00
|
|
|
chrome_options = {
|
|
|
|
browser: :chrome,
|
2018-10-26 14:59:22 -04:00
|
|
|
options: browser_options
|
2017-08-01 14:29:12 -04:00
|
|
|
}
|
2018-11-20 12:44:52 -05:00
|
|
|
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: false, clear_session_storage: false))
|
2016-10-28 16:08:20 -04:00
|
|
|
end
|
|
|
|
|
2019-05-11 07:07:16 -04:00
|
|
|
Capybara.register_driver :selenium_driver_subclass_with_chrome do |app|
|
|
|
|
subclass = Class.new(Capybara::Selenium::Driver)
|
|
|
|
subclass.new(app, browser: :chrome, options: browser_options, timeout: 30)
|
|
|
|
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
|
|
|
|
|
2018-02-28 19:11:41 -05:00
|
|
|
skipped_tests = %i[response_headers status_code trigger]
|
2016-10-13 22:50:03 -04:00
|
|
|
|
2019-04-19 15:22:17 -04:00
|
|
|
Capybara::SpecHelper.log_selenium_driver_version(Selenium::WebDriver::Chrome) if ENV['CI']
|
2018-03-13 17:22:50 -04:00
|
|
|
|
2018-09-14 16:00:29 -04:00
|
|
|
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests do |example|
|
|
|
|
case example.metadata[:full_description]
|
|
|
|
when /#click_link can download a file$/
|
|
|
|
skip 'Need to figure out testing of file downloading on windows platform' if Gem.win_platform?
|
2018-11-26 12:54:00 -05:00
|
|
|
when /Capybara::Session selenium_chrome Capybara::Window#maximize/
|
|
|
|
pending "Chrome headless doesn't support maximize" if ENV['HEADLESS']
|
2018-09-14 16:00:29 -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 chrome' do
|
2017-05-08 18:12:33 -04:00
|
|
|
include Capybara::SpecHelper
|
2019-05-02 21:57:14 -04:00
|
|
|
['Capybara::Session', 'Capybara::Node', Capybara::RSpecMatchers].each do |examples|
|
|
|
|
include_examples examples, TestSessions::Chrome, CHROME_DRIVER
|
|
|
|
end
|
2016-10-28 16:08:20 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'storage' do
|
|
|
|
describe '#reset!' do
|
2018-11-20 12:44:52 -05:00
|
|
|
it 'clears storage by default' do
|
2019-02-25 18:50:24 -05:00
|
|
|
session = TestSessions::Chrome
|
|
|
|
session.visit('/with_js')
|
|
|
|
session.find(:css, '#set-storage').click
|
|
|
|
session.reset!
|
|
|
|
session.visit('/with_js')
|
|
|
|
expect(session.evaluate_script('Object.keys(localStorage)')).to be_empty
|
|
|
|
expect(session.evaluate_script('Object.keys(sessionStorage)')).to be_empty
|
2016-10-28 16:08:20 -04:00
|
|
|
end
|
|
|
|
|
2018-11-20 12:44:52 -05:00
|
|
|
it 'does not clear storage when false' do
|
2019-02-25 18:50:24 -05:00
|
|
|
session = Capybara::Session.new(:selenium_chrome_not_clear_storage, TestApp)
|
|
|
|
session.visit('/with_js')
|
|
|
|
session.find(:css, '#set-storage').click
|
|
|
|
session.reset!
|
|
|
|
session.visit('/with_js')
|
|
|
|
expect(session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
|
|
|
|
expect(session.evaluate_script('Object.keys(sessionStorage)')).not_to be_empty
|
2016-10-28 16:08:20 -04:00
|
|
|
end
|
|
|
|
end
|
2018-11-20 17:20:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'timeout' do
|
|
|
|
it 'sets the http client read timeout' do
|
|
|
|
expect(TestSessions::Chrome.driver.browser.send(:bridge).http.read_timeout).to eq 30
|
|
|
|
end
|
2016-10-28 16:08:20 -04:00
|
|
|
end
|
2018-09-21 14:43:15 -04:00
|
|
|
|
|
|
|
describe 'filling in Chrome-specific date and time fields with keystrokes' do
|
|
|
|
let(:datetime) { Time.new(1983, 6, 19, 6, 30) }
|
2019-02-25 18:50:24 -05:00
|
|
|
let(:session) { TestSessions::Chrome }
|
2018-09-21 14:43:15 -04:00
|
|
|
|
|
|
|
before do
|
2019-02-25 18:50:24 -05:00
|
|
|
session.visit('/form')
|
2018-09-21 14:43:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fill in a date input with a String' do
|
2019-02-25 18:50:24 -05:00
|
|
|
session.fill_in('form_date', with: '06/19/1983')
|
|
|
|
session.click_button('awesome')
|
|
|
|
expect(Date.parse(extract_results(session)['date'])).to eq datetime.to_date
|
2018-09-21 14:43:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fill in a time input with a String' do
|
2019-02-25 18:50:24 -05:00
|
|
|
session.fill_in('form_time', with: '06:30A')
|
|
|
|
session.click_button('awesome')
|
|
|
|
results = extract_results(session)['time']
|
2018-09-21 14:43:15 -04:00
|
|
|
expect(Time.parse(results).strftime('%r')).to eq datetime.strftime('%r')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fill in a datetime input with a String' do
|
2019-02-25 18:50:24 -05:00
|
|
|
session.fill_in('form_datetime', with: "06/19/1983\t06:30A")
|
|
|
|
session.click_button('awesome')
|
|
|
|
expect(Time.parse(extract_results(session)['datetime'])).to eq datetime
|
2018-09-21 14:43:15 -04:00
|
|
|
end
|
|
|
|
end
|
2019-05-11 07:07:16 -04:00
|
|
|
|
|
|
|
describe 'using subclass of selenium driver' do
|
|
|
|
it 'works' do
|
|
|
|
session = Capybara::Session.new(:selenium_driver_subclass_with_chrome, TestApp)
|
|
|
|
session.visit('/form')
|
|
|
|
expect(session).to have_current_path('/form')
|
|
|
|
end
|
|
|
|
end
|
2019-06-09 14:16:37 -04:00
|
|
|
|
|
|
|
describe 'log access' do
|
2019-06-09 15:05:41 -04:00
|
|
|
before { skip 'Only makes sense in W3C mode' if ENV['W3C'] == 'false' }
|
2019-06-09 14:16:37 -04:00
|
|
|
|
2019-06-13 18:32:14 -04:00
|
|
|
it 'does not error getting log types' do
|
|
|
|
skip if Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0]) < Gem::Version.new('75.0.3770.90')
|
2019-06-09 14:16:37 -04:00
|
|
|
expect do
|
|
|
|
session.driver.browser.manage.logs.available_types
|
2019-06-13 18:32:14 -04:00
|
|
|
end.not_to raise_error
|
2019-06-09 14:16:37 -04:00
|
|
|
end
|
|
|
|
|
2019-06-11 14:28:52 -04:00
|
|
|
it 'does not error when getting logs' do
|
2019-06-09 14:16:37 -04:00
|
|
|
expect do
|
|
|
|
session.driver.browser.manage.logs.get(:browser)
|
2019-06-11 14:28:52 -04:00
|
|
|
end.not_to raise_error
|
2019-06-09 14:16:37 -04:00
|
|
|
end
|
|
|
|
end
|
2016-09-01 18:46:56 -04:00
|
|
|
end
|