2017-12-12 18:52:34 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2018-10-23 13:02:34 -04:00
|
|
|
Capybara::SpecHelper.spec '#have_all_of_selectors' do
|
2017-12-12 18:52:34 -05:00
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true if the given selectors are on the page' do
|
|
|
|
expect(@session).to have_all_of_selectors(:css, 'p a#foo', 'h2#h2one', 'h2#h2two')
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false if any of the given selectors are not on the page' do
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_all_of_selectors(:css, 'p a#foo', 'h2#h2three', 'h2#h2one')
|
2018-02-28 19:11:41 -05:00
|
|
|
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should use default selector' do
|
2017-12-12 18:52:34 -05:00
|
|
|
Capybara.default_selector = :css
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_all_of_selectors('p a#foo', 'h2#h2two', 'h2#h2one')
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_all_of_selectors('p a#foo', 'h2#h2three', 'h2#h2one')
|
2018-02-28 19:11:41 -05:00
|
|
|
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'should respect scopes' do
|
|
|
|
it 'when used with `within`' do
|
2017-12-12 18:52:34 -05:00
|
|
|
@session.within "//p[@id='first']" do
|
|
|
|
expect(@session).to have_all_of_selectors(".//a[@id='foo']")
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-12-12 18:52:34 -05:00
|
|
|
expect(@session).to have_all_of_selectors(".//a[@id='red']")
|
2018-02-28 19:11:41 -05:00
|
|
|
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'when called on elements' do
|
2017-12-12 18:52:34 -05:00
|
|
|
el = @session.find "//p[@id='first']"
|
|
|
|
expect(el).to have_all_of_selectors(".//a[@id='foo']")
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-12-12 18:52:34 -05:00
|
|
|
expect(el).to have_all_of_selectors(".//a[@id='red']")
|
2018-02-28 19:11:41 -05:00
|
|
|
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with options' do
|
|
|
|
it 'should apply options to all locators' do
|
2017-12-12 18:52:34 -05:00
|
|
|
expect(@session).to have_all_of_selectors(:field, 'normal', 'additional_newline', type: :textarea)
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2017-12-12 18:52:34 -05:00
|
|
|
expect(@session).to have_all_of_selectors(:field, 'normal', 'test_field', 'additional_newline', type: :textarea)
|
2018-02-28 19:11:41 -05:00
|
|
|
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with wait', requires: [:js] do
|
|
|
|
it 'should not raise error if all the elements appear before given wait duration' do
|
2017-12-12 18:52:34 -05:00
|
|
|
Capybara.using_wait_time(0.1) do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_all_of_selectors(:css, 'a#clickable', 'a#has-been-clicked', '#drag', wait: 5)
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'cannot be negated' do
|
2018-02-28 19:11:41 -05:00
|
|
|
expect do
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).not_to have_all_of_selectors(:css, 'p a#foo', 'h2#h2one', 'h2#h2two')
|
2018-02-28 19:11:41 -05:00
|
|
|
end.to raise_error ArgumentError
|
2017-12-12 18:52:34 -05:00
|
|
|
end
|
|
|
|
end
|