1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/spec/session/has_all_selectors_spec.rb

70 lines
2.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-02-28 19:11:41 -05:00
Capybara::SpecHelper.spec '#have_all_of_selectors' do
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')
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
end
2018-07-10 17:18:39 -04:00
it 'should use default selector' do
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
end
2018-07-10 17:18:39 -04:00
context 'should respect scopes' do
it 'when used with `within`' do
@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
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
end
end
2018-07-10 17:18:39 -04:00
it 'when called on elements' do
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
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
end
end
2018-07-10 17:18:39 -04:00
context 'with options' do
it 'should apply options to all locators' do
expect(@session).to have_all_of_selectors(:field, 'normal', 'additional_newline', type: :textarea)
2018-02-28 19:11:41 -05:00
expect do
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
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
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)
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
end
end