# frozen_string_literal: trueCapybara::SpecHelper.spec'#assert_all_of_selectors'dobeforedo@session.visit('/with_html')endit"should be true if the given selectors are on the page"do@session.assert_all_of_selectors(:css,"p a#foo","h2#h2one","h2#h2two")endit"should be false if any of the given selectors are not on the page"doexpect{@session.assert_all_of_selectors(:css,"p a#foo","h2#h2three","h2#h2one")}.toraise_error(Capybara::ElementNotFound)endit"should use default selector"doCapybara.default_selector=:cssexpect{@session.assert_all_of_selectors("p a#foo","h2#h2three","h2#h2one")}.toraise_error(Capybara::ElementNotFound)@session.assert_all_of_selectors("p a#foo","h2#h2two","h2#h2one")endcontext"should respect scopes"doit"when used with `within`"do@session.within"//p[@id='first']"do@session.assert_all_of_selectors(".//a[@id='foo']")expect{@session.assert_all_of_selectors(".//a[@id='red']")}.toraise_error(Capybara::ElementNotFound)endendit"when called on elements"doel=@session.find"//p[@id='first']"el.assert_all_of_selectors(".//a[@id='foo']")expect{el.assert_all_of_selectors(".//a[@id='red']")}.toraise_error(Capybara::ElementNotFound)endendcontext"with options"doit"should apply options to all locators"do@session.assert_all_of_selectors(:field,'normal','additional_newline',type: :textarea)expect{@session.assert_all_of_selectors(:field,'normal','test_field','additional_newline',type: :textarea)}.toraise_error(Capybara::ElementNotFound)endendcontext"with wait",requires: [:js]doit"should not raise error if all the elements appear before given wait duration"doCapybara.using_wait_time(0.1)do@session.visit('/with_js')@session.click_link('Click me')@session.assert_all_of_selectors(:css,"a#clickable","a#has-been-clicked",'#drag',wait: 0.9)endendendendCapybara::SpecHelper.spec'#assert_none_of_selectors'dobeforedo@session.visit('/with_html')endit"should be false if any of the given locators are on the page"doexpect{@session.assert_none_of_selectors(:xpath,"//p","//a")}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_none_of_selectors(:xpath,"//abbr","//a")}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_none_of_selectors(:css,"p a#foo")}.toraise_error(Capybara::ElementNotFound)endit"should be true if none of the given locators are on the page"do@session.assert_none_of_selectors(:xpath,"//abbr","//td")@session.assert_none_of_selectors(:css,"p a#doesnotexist","abbr")endit"should use default selector"doCapybara.default_selector=:css@session.assert_none_of_selectors("p a#doesnotexist","abbr")expect{@session.assert_none_of_selectors("abbr","p a#foo")}.toraise_error(Capybara::ElementNotFound)endcontext"should respect scopes"doit"when used with `within`"do@session.within"//p[@id='first']"doexpect{@session.assert_none_of_selectors(".//a[@id='foo']")}.toraise_error(Capybara::ElementNotFound)@session.assert_none_of_selectors(".//a[@id='red']")endendit"when called on an element"doel=@session.find"//p[@id='first']"expect{el.assert_none_of_selectors(".//a[@id='foo']")}.toraise_error(Capybara::ElementNotFound)el.assert_none_of_selectors(".//a[@id='red']")endendcontext"with options"doit"should apply the options to all locators"doexpect{@session.assert_none_of_selectors("//p//a",text: "Redirect")}.toraise_error(Capybara::ElementNotFound)@session.assert_none_of_selectors("//p",text: "Doesnotexist")endit"should discard all matches where the given regexp is matched"doexpect{@session.assert_none_of_selectors("//p//a",text: /re[dab]i/i,count: 1)}.toraise_error(Capybara::ElementNotFound)@session.assert_none_of_selectors("//p//a",text: /Red$/)endendcontext"with wait",requires: [:js]doit"should not find elements if they appear after given wait duration"do@session.visit('/with_js')@session.click_link('Click me')@session.assert_none_of_selectors(:css,"#new_field","a#has-been-clicked",wait: 0.1)endendend