2012-07-21 20:44:10 +00:00
|
|
|
Capybara::SpecHelper.spec '#has_xpath?' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be true if the given selector is on the page" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_xpath("//p")
|
|
|
|
expect(@session).to have_xpath("//p//a[@id='foo']")
|
|
|
|
expect(@session).to have_xpath("//p[contains(.,'est')]")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false if the given selector is not on the page" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_xpath("//abbr")
|
|
|
|
expect(@session).not_to have_xpath("//p//a[@id='doesnotexist']")
|
|
|
|
expect(@session).not_to have_xpath("//p[contains(.,'thisstringisnotonpage')]")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use xpath even if default selector is CSS" do
|
|
|
|
Capybara.default_selector = :css
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_xpath("//p//a[@id='doesnotexist']")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respect scopes" do
|
|
|
|
@session.within "//p[@id='first']" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_xpath(".//a[@id='foo']")
|
|
|
|
expect(@session).not_to have_xpath(".//a[@id='red']")
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should wait for content to appear", :requires => [:js] do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_xpath("//input[@type='submit' and @value='New Here']")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2010-01-18 19:33:22 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
context "with count" do
|
2012-09-25 08:47:20 +00:00
|
|
|
it "should be true if the content occurs the given number of times" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_xpath("//p", :count => 3)
|
|
|
|
expect(@session).to have_xpath("//p//a[@id='foo']", :count => 1)
|
|
|
|
expect(@session).to have_xpath("//p[contains(.,'est')]", :count => 1)
|
|
|
|
expect(@session).to have_xpath("//p//a[@id='doesnotexist']", :count => 0)
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
|
|
|
|
2012-09-25 08:47:20 +00:00
|
|
|
it "should be false if the content occurs a different number of times than the given" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_xpath("//p", :count => 6)
|
|
|
|
expect(@session).not_to have_xpath("//p//a[@id='foo']", :count => 2)
|
|
|
|
expect(@session).not_to have_xpath("//p[contains(.,'est')]", :count => 5)
|
|
|
|
expect(@session).not_to have_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
2010-01-28 21:47:35 +00:00
|
|
|
end
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2010-01-28 21:47:35 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
context "with text" do
|
|
|
|
it "should discard all matches where the given string is not contained" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_xpath("//p//a", :text => "Redirect", :count => 1)
|
|
|
|
expect(@session).not_to have_xpath("//p", :text => "Doesnotexist")
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should discard all matches where the given regexp is not matched" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
|
|
|
|
expect(@session).not_to have_xpath("//p//a", :text => /Red$/)
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
Capybara::SpecHelper.spec '#has_no_xpath?' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should be false if the given selector is on the page" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_no_xpath("//p")
|
|
|
|
expect(@session).not_to have_no_xpath("//p//a[@id='foo']")
|
|
|
|
expect(@session).not_to have_no_xpath("//p[contains(.,'est')]")
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
2009-12-30 16:37:56 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should be true if the given selector is not on the page" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_no_xpath("//abbr")
|
|
|
|
expect(@session).to have_no_xpath("//p//a[@id='doesnotexist']")
|
|
|
|
expect(@session).to have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2009-12-30 16:37:56 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should use xpath even if default selector is CSS" do
|
|
|
|
Capybara.default_selector = :css
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_no_xpath("//p//a[@id='doesnotexist']")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2010-01-18 19:33:22 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should respect scopes" do
|
|
|
|
@session.within "//p[@id='first']" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_no_xpath(".//a[@id='foo']")
|
|
|
|
expect(@session).to have_no_xpath(".//a[@id='red']")
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should wait for content to disappear", :requires => [:js] do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_no_xpath("//p[@id='change']")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2010-01-18 19:33:22 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
context "with count" do
|
2012-09-25 08:47:20 +00:00
|
|
|
it "should be false if the content occurs the given number of times" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_no_xpath("//p", :count => 3)
|
|
|
|
expect(@session).not_to have_no_xpath("//p//a[@id='foo']", :count => 1)
|
|
|
|
expect(@session).not_to have_no_xpath("//p[contains(.,'est')]", :count => 1)
|
|
|
|
expect(@session).not_to have_no_xpath("//p//a[@id='doesnotexist']", :count => 0)
|
2010-01-28 21:47:35 +00:00
|
|
|
end
|
|
|
|
|
2012-09-25 08:47:20 +00:00
|
|
|
it "should be true if the content occurs a different number of times than the given" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).to have_no_xpath("//p", :count => 6)
|
|
|
|
expect(@session).to have_no_xpath("//p//a[@id='foo']", :count => 2)
|
|
|
|
expect(@session).to have_no_xpath("//p[contains(.,'est')]", :count => 5)
|
|
|
|
expect(@session).to have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2009-12-30 16:37:56 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
context "with text" do
|
|
|
|
it "should discard all matches where the given string is contained" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_no_xpath("//p//a", :text => "Redirect", :count => 1)
|
|
|
|
expect(@session).to have_no_xpath("//p", :text => "Doesnotexist")
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2009-12-30 16:37:56 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should discard all matches where the given regexp is matched" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session).not_to have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
|
|
|
|
expect(@session).to have_no_xpath("//p//a", :text => /Red$/)
|
2009-12-30 16:37:56 +00:00
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
end
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|