Added has_css? to session
This commit is contained in:
parent
05c2de19bb
commit
68f7c01a1f
|
@ -1,3 +1,5 @@
|
|||
require 'nokogiri'
|
||||
|
||||
module Webcat
|
||||
VERSION = '0.1'
|
||||
|
||||
|
|
|
@ -71,6 +71,10 @@ class Webcat::Session
|
|||
end
|
||||
end
|
||||
|
||||
def has_css?(path, options={})
|
||||
has_xpath?(Nokogiri::CSS.xpath_for(path).first, options)
|
||||
end
|
||||
|
||||
def within(scope)
|
||||
scopes.push(scope)
|
||||
yield
|
||||
|
|
|
@ -345,6 +345,47 @@ shared_examples_for "session" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#has_css?' do
|
||||
before do
|
||||
@session.visit('/with_html')
|
||||
end
|
||||
|
||||
it "should be true if the given selector is on the page" do
|
||||
@session.should have_css("p")
|
||||
@session.should have_css("p a#foo")
|
||||
end
|
||||
|
||||
it "should be false if the given selector is not on the page" do
|
||||
@session.should_not have_css("abbr")
|
||||
@session.should_not have_css("p a#doesnotexist")
|
||||
@session.should_not have_css("p.nosuchclass")
|
||||
end
|
||||
|
||||
it "should respect scopes" do
|
||||
@session.within "//p[@id='first']" do
|
||||
@session.should have_css("a#foo")
|
||||
@session.should_not have_css("a#red")
|
||||
end
|
||||
end
|
||||
|
||||
context "with count" do
|
||||
it "should be true if the content is on the page the given number of times" do
|
||||
@session.should have_css("p", :count => 3)
|
||||
@session.should have_css("p a#foo", :count => 1)
|
||||
end
|
||||
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
@session.should_not have_css("p", :count => 6)
|
||||
@session.should_not have_css("p a#foo", :count => 2)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
@session.should_not have_css("abbr", :count => 2)
|
||||
@session.should_not have_css("p a.doesnotexist", :count => 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#attach_file" do
|
||||
before do
|
||||
|
|
Loading…
Reference in New Issue