2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2010-09-17 19:56:32 -04:00
|
|
|
require 'spec_helper'
|
2018-07-10 17:18:39 -04:00
|
|
|
require 'selenium-webdriver'
|
2013-11-14 16:25:00 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
RSpec.shared_examples 'Capybara::Session' do |session, mode|
|
2018-02-28 19:11:41 -05:00
|
|
|
let(:session) { session }
|
2016-07-26 14:15:35 -04:00
|
|
|
|
2009-11-14 04:44:46 -05:00
|
|
|
context 'with selenium driver' do
|
|
|
|
describe '#driver' do
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be a selenium driver' do
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(session.driver).to be_an_instance_of(Capybara::Selenium::Driver)
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-11 16:40:23 -05:00
|
|
|
|
2009-11-14 04:44:46 -05:00
|
|
|
describe '#mode' do
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should remember the mode' do
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(session.mode).to eq(mode)
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-11 16:40:23 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe '#reset!' do
|
|
|
|
it 'freshly reset session should not be touched' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.instance_variable_set(:@touched, true)
|
|
|
|
session.reset!
|
|
|
|
expect(session.instance_variable_get(:@touched)).to eq false
|
2014-01-17 02:57:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe 'exit codes' do
|
2012-07-13 07:15:44 -04:00
|
|
|
before do
|
|
|
|
@current_dir = Dir.getwd
|
2012-07-13 07:28:33 -04:00
|
|
|
Dir.chdir(File.join(File.dirname(__FILE__), '..'))
|
2018-04-27 14:01:47 -04:00
|
|
|
@env = { 'SELENIUM_BROWSER' => session.driver.options[:browser].to_s }
|
2012-07-13 07:15:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Dir.chdir(@current_dir)
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should have return code 1 when running selenium_driver_rspec_failure.rb' do
|
2018-08-01 17:25:08 -04:00
|
|
|
skip 'only setup for local non-headless' if headless_or_remote?
|
2018-04-24 18:47:53 -04:00
|
|
|
|
2017-05-04 15:35:46 -04:00
|
|
|
system(@env, 'rspec spec/fixtures/selenium_driver_rspec_failure.rb', out: File::NULL, err: File::NULL)
|
2018-02-28 19:11:41 -05:00
|
|
|
expect($CHILD_STATUS.exitstatus).to eq(1)
|
2012-07-13 07:15:44 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should have return code 0 when running selenium_driver_rspec_success.rb' do
|
2018-08-01 17:25:08 -04:00
|
|
|
skip 'only setup for local non-headless' if headless_or_remote?
|
2018-04-24 18:47:53 -04:00
|
|
|
|
2017-05-04 15:35:46 -04:00
|
|
|
system(@env, 'rspec spec/fixtures/selenium_driver_rspec_success.rb', out: File::NULL, err: File::NULL)
|
2018-02-28 19:11:41 -05:00
|
|
|
expect($CHILD_STATUS.exitstatus).to eq(0)
|
2012-07-13 07:15:44 -04:00
|
|
|
end
|
|
|
|
end
|
2015-04-12 23:32:12 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe '#accept_alert', requires: [:modals] do
|
|
|
|
it 'supports a blockless mode' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_js')
|
|
|
|
session.click_link('Open alert')
|
|
|
|
session.accept_alert
|
|
|
|
expect { session.driver.browser.switch_to.alert }.to raise_error(session.driver.send(:modal_error))
|
2014-07-02 22:10:30 -04:00
|
|
|
end
|
2017-08-14 19:25:57 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'can be called before visiting' do
|
|
|
|
session.accept_alert 'Initial alert' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/initial_alert')
|
2018-02-12 13:07:06 -05:00
|
|
|
end
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(session).to have_text('Initial alert page')
|
2017-08-14 19:25:57 -04:00
|
|
|
end
|
2014-07-02 22:10:30 -04:00
|
|
|
end
|
2015-04-12 23:32:12 -04:00
|
|
|
|
2017-09-07 12:58:14 -04:00
|
|
|
context '#fill_in_with empty string and no options' do
|
|
|
|
it 'should trigger change when clearing a field' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_js')
|
|
|
|
session.fill_in('with_change_event', with: '')
|
2017-09-07 12:58:14 -04:00
|
|
|
# click outside the field to trigger the change event
|
2018-04-27 14:01:47 -04:00
|
|
|
session.find(:css, 'body').click
|
|
|
|
expect(session).to have_selector(:css, '.change_event_triggered', match: :one)
|
2017-09-07 12:58:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context '#fill_in with { :clear => :backspace } fill_option', requires: [:js] do
|
2018-07-11 13:05:45 -04:00
|
|
|
before do
|
|
|
|
# Firefox has an issue with change events if the main window doesn't think it's focused
|
|
|
|
session.execute_script('window.focus()')
|
|
|
|
end
|
|
|
|
|
2015-04-12 23:32:12 -04:00
|
|
|
it 'should fill in a field, replacing an existing value' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
session.fill_in('form_first_name',
|
|
|
|
with: 'Harry',
|
|
|
|
fill_options: { clear: :backspace })
|
|
|
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
2015-04-12 23:32:12 -04:00
|
|
|
end
|
|
|
|
|
2018-07-16 12:19:35 -04:00
|
|
|
it 'should fill in a field, replacing an existing value, even with caret position' do
|
|
|
|
session.visit('/form')
|
2018-07-10 17:18:39 -04:00
|
|
|
session.find(:css, '#form_first_name').execute_script <<-JS
|
2018-07-16 12:19:35 -04:00
|
|
|
this.focus();
|
|
|
|
this.setSelectionRange(0, 0);
|
|
|
|
JS
|
|
|
|
|
|
|
|
session.fill_in('form_first_name',
|
2018-07-10 17:18:39 -04:00
|
|
|
with: 'Harry',
|
|
|
|
fill_options: { clear: :backspace })
|
2018-07-16 12:19:35 -04:00
|
|
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
|
|
|
end
|
|
|
|
|
2018-05-18 13:29:53 -04:00
|
|
|
it 'should fill in if the option is set via global option' do
|
|
|
|
Capybara.default_set_options = { clear: :backspace }
|
|
|
|
session.visit('/form')
|
|
|
|
session.fill_in('form_first_name', with: 'Thomas')
|
|
|
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('Thomas')
|
|
|
|
end
|
|
|
|
|
2015-04-12 23:32:12 -04:00
|
|
|
it 'should only trigger onchange once' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_js')
|
|
|
|
session.fill_in('with_change_event',
|
|
|
|
with: 'some value',
|
|
|
|
fill_options: { clear: :backspace })
|
2015-04-12 23:32:12 -04:00
|
|
|
# click outside the field to trigger the change event
|
2018-07-11 13:05:45 -04:00
|
|
|
session.find(:css, '#with_focus_event').click
|
2018-07-05 20:14:36 -04:00
|
|
|
expect(session.find(:css, '.change_event_triggered', match: :one, wait: 5)).to have_text 'some value'
|
2015-04-12 23:32:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should trigger change when clearing field' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_js')
|
|
|
|
session.fill_in('with_change_event',
|
|
|
|
with: '',
|
|
|
|
fill_options: { clear: :backspace })
|
2015-04-12 23:32:12 -04:00
|
|
|
# click outside the field to trigger the change event
|
2018-07-11 13:05:45 -04:00
|
|
|
session.find(:css, '#with_focus_event').click
|
2018-07-05 20:14:36 -04:00
|
|
|
expect(session).to have_selector(:css, '.change_event_triggered', match: :one, wait: 5)
|
2015-04-12 23:32:12 -04:00
|
|
|
end
|
2017-09-07 12:58:14 -04:00
|
|
|
|
|
|
|
it 'should trigger input event field_value.length times' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_js')
|
|
|
|
session.fill_in('with_change_event',
|
|
|
|
with: '',
|
|
|
|
fill_options: { clear: :backspace })
|
2017-09-07 12:58:14 -04:00
|
|
|
# click outside the field to trigger the change event
|
2018-04-27 14:01:47 -04:00
|
|
|
session.find(:css, 'body').click
|
|
|
|
expect(session).to have_xpath('//p[@class="input_event_triggered"]', count: 13)
|
2017-09-07 12:58:14 -04:00
|
|
|
end
|
2015-04-12 23:32:12 -04:00
|
|
|
end
|
2015-08-09 12:55:56 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context '#fill_in with { clear: :none } fill_options' do
|
2015-04-13 00:25:13 -04:00
|
|
|
it 'should append to content in a field' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
session.fill_in('form_first_name',
|
|
|
|
with: 'Harry',
|
|
|
|
fill_options: { clear: :none })
|
|
|
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('JohnHarry')
|
2015-04-13 00:25:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-09 15:44:47 -04:00
|
|
|
context '#fill_in with Date' do
|
|
|
|
before do
|
|
|
|
session.visit('/form')
|
2018-07-10 17:18:39 -04:00
|
|
|
session.find(:css, '#form_date').execute_script <<-JS
|
2018-05-09 15:44:47 -04:00
|
|
|
window.capybara_formDateFiredEvents = [];
|
2018-07-12 15:32:41 -04:00
|
|
|
var fd = this;
|
2018-05-09 15:44:47 -04:00
|
|
|
['focus', 'input', 'change'].forEach(function(eventType) {
|
2018-07-12 15:32:41 -04:00
|
|
|
fd.addEventListener(eventType, function() { window.capybara_formDateFiredEvents.push(eventType); });
|
2018-05-09 15:44:47 -04:00
|
|
|
});
|
|
|
|
JS
|
|
|
|
# work around weird FF issue where it would create an extra focus issue in some cases
|
|
|
|
session.find(:css, 'body').click
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should generate standard events on changing value' do
|
2018-07-30 13:37:47 -04:00
|
|
|
pending "IE 11 doesn't support date input type" if ie?(session)
|
2018-05-09 15:44:47 -04:00
|
|
|
session.fill_in('form_date', with: Date.today)
|
|
|
|
expect(session.evaluate_script('window.capybara_formDateFiredEvents')).to eq %w[focus input change]
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should not generate input and change events if the value is not changed' do
|
2018-07-30 13:37:47 -04:00
|
|
|
pending "IE 11 doesn't support date input type" if ie?(session)
|
2018-05-09 15:44:47 -04:00
|
|
|
session.fill_in('form_date', with: Date.today)
|
|
|
|
session.fill_in('form_date', with: Date.today)
|
|
|
|
# Chrome adds an extra focus for some reason - ok for now
|
|
|
|
expect(session.evaluate_script('window.capybara_formDateFiredEvents')).to eq(%w[focus input change])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context '#fill_in with { clear: Array } fill_options' do
|
2016-04-05 12:33:19 -04:00
|
|
|
it 'should pass the array through to the element' do
|
2018-02-28 19:11:41 -05:00
|
|
|
# this is mainly for use with [[:control, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
session.fill_in('form_first_name',
|
|
|
|
with: 'Harry',
|
|
|
|
fill_options: { clear: [[:shift, 'abc'], :backspace] })
|
|
|
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('JohnABHarry')
|
2015-04-13 00:25:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe '#path' do
|
|
|
|
it 'returns xpath' do
|
2015-08-20 17:35:15 -04:00
|
|
|
# this is here because it is testing for an XPath that is specific to the algorithm used in the selenium driver
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/path')
|
|
|
|
element = session.find(:link, 'Second Link')
|
2018-06-13 16:15:18 -04:00
|
|
|
expect(element.path).to eq('/HTML/BODY/DIV[2]/A[1]')
|
2015-08-09 12:55:56 -04:00
|
|
|
end
|
2018-06-12 16:06:25 -04:00
|
|
|
|
2018-09-14 13:27:02 -04:00
|
|
|
it 'handles namespaces in xhtml' do
|
2018-07-30 13:37:47 -04:00
|
|
|
pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)
|
2018-07-10 17:18:39 -04:00
|
|
|
session.visit '/with_namespace'
|
2018-07-30 13:37:47 -04:00
|
|
|
rect = session.find(:css, 'div svg rect:first-of-type')
|
2018-06-13 16:15:18 -04:00
|
|
|
expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]")
|
2018-06-12 16:06:25 -04:00
|
|
|
expect(session.find(:xpath, rect.path)).to eq rect
|
|
|
|
end
|
2018-06-13 16:15:18 -04:00
|
|
|
|
2018-09-14 13:27:02 -04:00
|
|
|
it 'handles default namespaces in html5' do
|
|
|
|
pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)
|
|
|
|
session.visit '/with_html5_svg'
|
|
|
|
rect = session.find(:css, 'div svg rect:first-of-type')
|
|
|
|
expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]")
|
|
|
|
expect(session.find(:xpath, rect.path)).to eq rect
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'handles case sensitive element names' do
|
2018-07-30 13:37:47 -04:00
|
|
|
pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)
|
2018-07-10 17:18:39 -04:00
|
|
|
session.visit '/with_namespace'
|
|
|
|
els = session.all(:css, 'div *', visible: :all)
|
2018-06-13 16:15:18 -04:00
|
|
|
expect { els.map(&:path) }.not_to raise_error
|
2018-07-10 17:18:39 -04:00
|
|
|
lg = session.find(:css, 'div linearGradient', visible: :all)
|
2018-06-13 16:15:18 -04:00
|
|
|
expect(session.find(:xpath, lg.path, visible: :all)).to eq lg
|
|
|
|
end
|
2015-08-09 12:55:56 -04:00
|
|
|
end
|
2017-01-27 14:11:13 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe 'all with disappearing elements' do
|
|
|
|
it 'ignores stale elements in results' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/path')
|
|
|
|
elements = session.all(:link) { |_node| raise Selenium::WebDriver::Error::StaleElementReferenceError }
|
2017-05-31 17:07:34 -04:00
|
|
|
expect(elements.size).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe '#evaluate_script' do
|
|
|
|
it 'can return an element' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
element = session.evaluate_script("document.getElementById('form_title')")
|
|
|
|
expect(element).to eq session.find(:id, 'form_title')
|
2017-01-27 14:11:13 -05:00
|
|
|
end
|
2017-01-28 17:34:44 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'can return arrays of nested elements' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
elements = session.evaluate_script('document.querySelectorAll("#form_city option")')
|
|
|
|
expect(elements).to all(be_instance_of Capybara::Node::Element)
|
|
|
|
expect(elements).to eq session.find(:css, '#form_city').all(:css, 'option').to_a
|
2017-01-28 17:34:44 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'can return hashes with elements' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
result = session.evaluate_script("{ a: document.getElementById('form_title'), b: {c: document.querySelectorAll('#form_city option')}}")
|
2018-02-28 19:11:41 -05:00
|
|
|
expect(result).to eq(
|
2018-04-27 14:01:47 -04:00
|
|
|
'a' => session.find(:id, 'form_title'),
|
2017-01-28 17:34:44 -05:00
|
|
|
'b' => {
|
2018-04-27 14:01:47 -04:00
|
|
|
'c' => session.find(:css, '#form_city').all(:css, 'option').to_a
|
2017-01-28 17:34:44 -05:00
|
|
|
}
|
2018-02-28 19:11:41 -05:00
|
|
|
)
|
2017-01-28 17:34:44 -05:00
|
|
|
end
|
2017-10-25 20:09:32 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe '#evaluate_async_script' do
|
|
|
|
it 'will timeout if the script takes too long' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_js')
|
2017-10-25 20:09:32 -04:00
|
|
|
expect do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.using_wait_time(1) do
|
2018-07-10 17:18:39 -04:00
|
|
|
session.evaluate_async_script('var cb = arguments[0]; setTimeout(function(){ cb(null) }, 3000)')
|
2017-10-25 20:09:32 -04:00
|
|
|
end
|
|
|
|
end.to raise_error Selenium::WebDriver::Error::ScriptTimeoutError
|
|
|
|
end
|
|
|
|
end
|
2017-01-27 14:11:13 -05:00
|
|
|
end
|
2017-03-21 18:34:18 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe 'Element#inspect' do
|
|
|
|
it 'outputs obsolete elements' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/form')
|
|
|
|
el = session.find(:button, 'Click me!').click
|
|
|
|
expect(session).to have_no_button('Click me!')
|
|
|
|
allow(el).to receive(:synchronize)
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(el.inspect).to eq 'Obsolete #<Capybara::Node::Element>'
|
2018-04-27 14:01:47 -04:00
|
|
|
expect(el).not_to have_received(:synchronize)
|
2017-03-21 18:34:18 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-02 14:55:13 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
describe 'Element#click' do
|
|
|
|
it 'should handle fixed headers/footers' do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.visit('/with_fixed_header_footer')
|
|
|
|
# session.click_link('Go to root')
|
|
|
|
session.find(:link, 'Go to root').click
|
|
|
|
expect(session).to have_current_path('/')
|
2017-10-02 14:55:13 -04:00
|
|
|
end
|
|
|
|
end
|
2018-03-15 15:48:19 -04:00
|
|
|
|
2018-08-13 14:14:56 -04:00
|
|
|
describe 'Element#drag_to' do
|
2018-08-10 13:40:58 -04:00
|
|
|
it 'should HTML5 drag and drop an object' do
|
|
|
|
pending "Firefox < 62 doesn't support a DataTransfer constuctor" if marionette_lt?(62.0, session)
|
|
|
|
session.visit('/with_js')
|
|
|
|
element = session.find('//div[@id="drag_html5"]')
|
|
|
|
target = session.find('//div[@id="drop_html5"]')
|
|
|
|
element.drag_to(target)
|
|
|
|
expect(session).to have_xpath('//div[contains(., "HTML5 Dropped drag_html5")]')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not HTML5 drag and drop on a non HTML5 drop element' do
|
|
|
|
session.visit('/with_js')
|
|
|
|
element = session.find('//div[@id="drag_html5"]')
|
|
|
|
target = session.find('//div[@id="drop_html5"]')
|
|
|
|
target.execute_script("$(this).removeClass('drop');")
|
|
|
|
element.drag_to(target)
|
|
|
|
sleep 1
|
|
|
|
expect(session).not_to have_xpath('//div[contains(., "HTML5 Dropped drag_html5")]')
|
|
|
|
end
|
|
|
|
|
2018-08-20 19:14:14 -04:00
|
|
|
it 'should HTML5 drag and drop when scrolling needed' do
|
2018-08-10 13:40:58 -04:00
|
|
|
pending "Firefox < 62 doesn't support a DataTransfer constuctor" if marionette_lt?(62.0, session)
|
|
|
|
session.visit('/with_js')
|
|
|
|
element = session.find('//div[@id="drag_html5_scroll"]')
|
|
|
|
target = session.find('//div[@id="drop_html5_scroll"]')
|
|
|
|
element.drag_to(target)
|
|
|
|
expect(session).to have_xpath('//div[contains(., "HTML5 Dropped drag_html5_scroll")]')
|
|
|
|
end
|
2018-09-11 16:57:41 -04:00
|
|
|
|
|
|
|
it 'should drag HTML5 default draggable elements' do
|
|
|
|
pending "Firefox < 62 doesn't support a DataTransfer constuctor" if marionette_lt?(62.0, session)
|
|
|
|
session.visit('/with_js')
|
|
|
|
link = session.find_link('drag_link_html5')
|
|
|
|
target = session.find(:id, 'drop_html5')
|
|
|
|
link.drag_to target
|
|
|
|
expect(session).to have_xpath('//div[contains(., "HTML5 Dropped")]')
|
|
|
|
end
|
2018-08-10 13:40:58 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'Windows' do
|
2018-03-15 15:48:19 -04:00
|
|
|
it "can't close the primary window" do
|
|
|
|
expect do
|
2018-04-27 14:01:47 -04:00
|
|
|
session.current_window.close
|
2018-03-15 15:48:19 -04:00
|
|
|
end.to raise_error(ArgumentError, 'Not allowed to close the primary window')
|
|
|
|
end
|
|
|
|
end
|
2018-05-16 23:04:24 -04:00
|
|
|
|
2018-08-17 16:57:12 -04:00
|
|
|
describe 'Capybara#disable_animation' do
|
2018-08-21 12:24:35 -04:00
|
|
|
context 'when set to `true`' do
|
|
|
|
before(:context) do # rubocop:disable RSpec/BeforeAfterAll
|
|
|
|
# NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
|
|
|
|
# it doesn't affect any of these tests because the settings are applied per-session
|
|
|
|
Capybara.disable_animation = true
|
|
|
|
@animation_session = Capybara::Session.new(session.mode, TestApp.new)
|
|
|
|
end
|
2018-05-16 23:04:24 -04:00
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
after(:context) do # rubocop:disable RSpec/BeforeAfterAll
|
|
|
|
@animation_session = nil
|
|
|
|
end
|
2018-05-16 23:04:24 -04:00
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
it 'should disable CSS transitions' do
|
|
|
|
@animation_session.visit('with_animation')
|
|
|
|
@animation_session.click_link('transition me away')
|
|
|
|
expect(@animation_session).to have_no_link('transition me away', wait: 0.5)
|
|
|
|
end
|
2018-05-16 23:04:24 -04:00
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
it 'should disable CSS animations' do
|
|
|
|
@animation_session.visit('with_animation')
|
|
|
|
@animation_session.click_link('animate me away')
|
|
|
|
expect(@animation_session).to have_no_link('animate me away', wait: 0.5)
|
|
|
|
end
|
2018-05-16 23:04:24 -04:00
|
|
|
end
|
2018-08-17 14:07:21 -04:00
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
context 'if we pass in css that matches elements' do
|
2018-08-17 14:07:21 -04:00
|
|
|
before(:context) do # rubocop:disable RSpec/BeforeAfterAll
|
|
|
|
# NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
|
|
|
|
# it doesn't affect any of these tests because the settings are applied per-session
|
|
|
|
Capybara.disable_animation = '#with_animation a'
|
|
|
|
@animation_session_with_matching_css = Capybara::Session.new(session.mode, TestApp.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:context) do # rubocop:disable RSpec/BeforeAfterAll
|
|
|
|
@animation_session_with_matching_css = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should disable CSS transitions' do
|
|
|
|
@animation_session_with_matching_css.visit('with_animation')
|
|
|
|
@animation_session_with_matching_css.click_link('transition me away')
|
|
|
|
expect(@animation_session_with_matching_css).to have_no_link('transition me away', wait: 0.5)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should disable CSS animations' do
|
|
|
|
@animation_session_with_matching_css.visit('with_animation')
|
|
|
|
@animation_session_with_matching_css.click_link('animate me away')
|
|
|
|
expect(@animation_session_with_matching_css).to have_no_link('animate me away', wait: 0.5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
context 'if we pass in css that does not match elements' do
|
2018-08-17 14:07:21 -04:00
|
|
|
before(:context) do # rubocop:disable RSpec/BeforeAfterAll
|
|
|
|
# NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
|
|
|
|
# it doesn't affect any of these tests because the settings are applied per-session
|
|
|
|
Capybara.disable_animation = '.this-class-matches-nothing'
|
|
|
|
@animation_session_without_matching_css = Capybara::Session.new(session.mode, TestApp.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:context) do # rubocop:disable RSpec/BeforeAfterAll
|
|
|
|
@animation_session_without_matching_css = nil
|
|
|
|
end
|
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
it 'should not disable CSS transitions' do
|
2018-08-17 14:07:21 -04:00
|
|
|
@animation_session_without_matching_css.visit('with_animation')
|
|
|
|
@animation_session_without_matching_css.click_link('transition me away')
|
2018-08-21 12:24:35 -04:00
|
|
|
sleep 0.5 # Wait long enough for click to have been processed
|
|
|
|
expect(@animation_session_without_matching_css).to have_link('transition me away', wait: false)
|
|
|
|
expect(@animation_session_without_matching_css).to have_no_link('transition me away', wait: 5)
|
2018-08-17 14:07:21 -04:00
|
|
|
end
|
|
|
|
|
2018-08-21 12:24:35 -04:00
|
|
|
it 'should not disable CSS animations' do
|
2018-08-17 14:07:21 -04:00
|
|
|
@animation_session_without_matching_css.visit('with_animation')
|
|
|
|
@animation_session_without_matching_css.click_link('animate me away')
|
2018-08-21 12:24:35 -04:00
|
|
|
sleep 0.5 # Wait long enough for click to have been processed
|
|
|
|
expect(@animation_session_without_matching_css).to have_link('animate me away', wait: false)
|
|
|
|
expect(@animation_session_without_matching_css).to have_no_link('animate me away', wait: 5)
|
2018-08-17 14:07:21 -04:00
|
|
|
end
|
|
|
|
end
|
2018-05-16 23:04:24 -04:00
|
|
|
end
|
2018-09-14 13:27:02 -04:00
|
|
|
|
|
|
|
describe ":element selector" do
|
|
|
|
it "can find html5 svg elements" do
|
|
|
|
session.visit('with_html5_svg')
|
|
|
|
expect(session).to have_selector(:element, :svg)
|
|
|
|
expect(session).to have_selector(:element, :rect, visible: true)
|
|
|
|
expect(session).to have_selector(:element, :rect, visible: :hidden)
|
|
|
|
expect(session).to have_selector(:element, :circle)
|
|
|
|
expect(session).to have_selector(:element, :linearGradient, visible: false)
|
|
|
|
end
|
|
|
|
end
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
2018-04-24 18:47:53 -04:00
|
|
|
|
|
|
|
def headless_or_remote?
|
|
|
|
!ENV['HEADLESS'].nil? || session.driver.options[:browser] == :remote
|
|
|
|
end
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|