# frozen_string_literal: trueCapybara::SpecHelper.spec'#assert_selector'dobeforedo@session.visit('/with_html')endit"should be true if the given selector is on the page"do@session.assert_selector(:xpath,"//p")@session.assert_selector(:css,"p a#foo")@session.assert_selector("//p[contains(.,'est')]")endit"should be false if the given selector is not on the page"doexpect{@session.assert_selector(:xpath,"//abbr")}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_selector(:css,"p a#doesnotexist")}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_selector("//p[contains(.,'thisstringisnotonpage')]")}.toraise_error(Capybara::ElementNotFound)endit"should use default selector"doCapybara.default_selector=:cssexpect{@session.assert_selector("p a#doesnotexist")}.toraise_error(Capybara::ElementNotFound)@session.assert_selector("p a#foo")endit"should respect scopes"do@session.within"//p[@id='first']"do@session.assert_selector(".//a[@id='foo']")expect{@session.assert_selector(".//a[@id='red']")}.toraise_error(Capybara::ElementNotFound)endendcontext"with count"doit"should be true if the content is on the page the given number of times"do@session.assert_selector("//p",count: 3)@session.assert_selector("//p//a[@id='foo']",count: 1)@session.assert_selector("//p[contains(.,'est')]",count: 1)endit"should be false if the content is on the page the given number of times"doexpect{@session.assert_selector("//p",count: 6)}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_selector("//p//a[@id='foo']",count: 2)}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_selector("//p[contains(.,'est')]",count: 5)}.toraise_error(Capybara::ElementNotFound)endit"should be false if the content isn't on the page at all"doexpect{@session.assert_selector("//abbr",count: 2)}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_selector("//p//a[@id='doesnotexist']",count: 1)}.toraise_error(Capybara::ElementNotFound)endendcontext"with text"doit"should discard all matches where the given string is not contained"do@session.assert_selector("//p//a",text: "Redirect",count: 1)expect{@session.assert_selector("//p",text: "Doesnotexist")}.toraise_error(Capybara::ElementNotFound)endit"should discard all matches where the given regexp is not matched"do@session.assert_selector("//p//a",text: /re[dab]i/i,count: 1)expect{@session.assert_selector("//p//a",text: /Red$/)}.toraise_error(Capybara::ElementNotFound)endendcontext"with wait",requires: [:js]doit"should find element if it appears before given wait duration"doCapybara.using_wait_time(0.1)do@session.visit('/with_js')@session.click_link('Click me')@session.assert_selector(:css,"a#has-been-clicked",text: "Has been clicked",wait: 2)endendendendCapybara::SpecHelper.spec'#refute_selector'doit"should be an alias of #assert_no_selector"doexpect(Capybara::Node::Matchers.instance_method(:refute_selector)).toeqCapybara::Node::Matchers.instance_method(:assert_no_selector)endendCapybara::SpecHelper.spec'#assert_no_selector'dobeforedo@session.visit('/with_html')endit"should be false if the given selector is on the page"doexpect{@session.assert_no_selector(:xpath,"//p")}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_no_selector(:css,"p a#foo")}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_no_selector("//p[contains(.,'est')]")}.toraise_error(Capybara::ElementNotFound)endit"should be true if the given selector is not on the page"do@session.assert_no_selector(:xpath,"//abbr")@session.assert_no_selector(:css,"p a#doesnotexist")@session.assert_no_selector("//p[contains(.,'thisstringisnotonpage')]")endit"should use default selector"doCapybara.default_selector=:css@session.assert_no_selector("p a#doesnotexist")expect{@session.assert_no_selector("p a#foo")}.toraise_error(Capybara::ElementNotFound)endit"should respect scopes"do@session.within"//p[@id='first']"doexpect{@session.assert_no_selector(".//a[@id='foo']")}.toraise_error(Capybara::ElementNotFound)@session.assert_no_selector(".//a[@id='red']")endendcontext"with count"doit"should be false if the content is on the page the given number of times"doexpect{@session.assert_no_selector("//p",count: 3)}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_no_selector("//p//a[@id='foo']",count: 1)}.toraise_error(Capybara::ElementNotFound)expect{@session.assert_no_selector("//p[contains(.,'est')]",count: 1)}.toraise_error(Capybara::ElementNotFound)endit"should be true if the content is on the page the wrong number of times"do@session.assert_no_selector("//p",count: 6)@session.assert_no_selector("//p//a[@id='foo']",count: 2)@session.assert_no_selector("//p[contains(.,'est')]",count: 5)endit"should be true if the content isn't on the page at all"do@session.assert_no_selector("//abbr",count: 2)@session.assert_no_selector("//p//a[@id='doesnotexist']",count: 1)endendcontext"with text"doit"should discard all matches where the given string is contained"doexpect{@session.assert_no_selector("//p//a",text: "Redirect",count: 1)}.toraise_error(Capybara::ElementNotFound)@session.assert_no_selector("//p",text: "Doesnotexist")endit"should discard all matches where the given regexp is matched"doexpect{@session.assert_no_selector("//p//a",text: /re[dab]i/i,count: 1)}.toraise_error(Capybara::ElementNotFound)@session.assert_no_selector("//p//a",text: /Red$/)endendcontext"with wait",requires: [:js]doit"should not find element if it appears after given wait duration"do@session.visit('/with_js')@session.click_link('Click me')@session.assert_no_selector(:css,"a#has-been-clicked",text: "Has been clicked",wait: 0.1)endendend