support :wait option in `assert_selector` and `has_text?` matcher
closes #1105
This commit is contained in:
parent
519bbb1806
commit
04b99e1634
|
@ -85,7 +85,8 @@ module Capybara
|
|||
# @raise [Capybara::ExpectationNotMet] If the selector does not exist
|
||||
#
|
||||
def assert_selector(*args)
|
||||
synchronize do
|
||||
query = Capybara::Query.new(*args)
|
||||
synchronize(query.wait) do
|
||||
result = all(*args)
|
||||
result.matches_count? or raise Capybara::ExpectationNotMet, result.failure_message
|
||||
end
|
||||
|
@ -101,7 +102,8 @@ module Capybara
|
|||
# @raise [Capybara::ExpectationNotMet] If the selector exists
|
||||
#
|
||||
def assert_no_selector(*args)
|
||||
synchronize do
|
||||
query = Capybara::Query.new(*args)
|
||||
synchronize(query.wait) do
|
||||
result = all(*args)
|
||||
result.matches_count? and raise Capybara::ExpectationNotMet, result.negative_failure_message
|
||||
end
|
||||
|
@ -215,7 +217,8 @@ module Capybara
|
|||
# @return [Boolean] Whether it exists
|
||||
#
|
||||
def has_text?(*args)
|
||||
synchronize do
|
||||
query = Capybara::Query.new(*args)
|
||||
synchronize(query.wait) do
|
||||
raise ExpectationNotMet unless text_found?(*args)
|
||||
end
|
||||
return true
|
||||
|
@ -233,7 +236,8 @@ module Capybara
|
|||
# @return [Boolean] Whether it doesn't exist
|
||||
#
|
||||
def has_no_text?(*args)
|
||||
synchronize do
|
||||
query = Capybara::Query.new(*args)
|
||||
synchronize(query.wait) do
|
||||
raise ExpectationNotMet if text_found?(*args)
|
||||
end
|
||||
return true
|
||||
|
|
|
@ -58,6 +58,16 @@ Capybara::SpecHelper.spec '#assert_selector' do
|
|||
expect { @session.assert_selector("//p//a", :text => /Red$/) }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
it "should find element if it appears before given wait duration" do
|
||||
Capybara.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 => 0.9)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.spec '#assert_no_selector' do
|
||||
|
@ -120,4 +130,13 @@ Capybara::SpecHelper.spec '#assert_no_selector' do
|
|||
@session.assert_no_selector("//p//a", :text => /Red$/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
it "should not find element if it appears after given wait duration" do
|
||||
p Capybara.default_wait_time
|
||||
@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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -190,6 +190,16 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|||
@session.should_not have_text('count', minimum: '3')
|
||||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
it "should find element if it appears before given wait duration" do
|
||||
Capybara.using_wait_time(0.1) do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.should have_text('Has been clicked', :wait => 0.9)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.spec '#has_no_text?' do
|
||||
|
@ -288,4 +298,12 @@ Capybara::SpecHelper.spec '#has_no_text?' do
|
|||
@session.click_link('Click me')
|
||||
@session.should have_no_text("I changed it")
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
it "should not find element if it appears after given wait duration" do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.should have_no_text('Has been clicked', :wait => 0.1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue