1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Timeout behavior in #evaluate_async_script is only defined for selenium for now

This commit is contained in:
Thomas Walpole 2017-10-25 17:09:32 -07:00
parent 61dd0ac8fa
commit c38f56b45d
2 changed files with 12 additions and 10 deletions

View file

@ -12,20 +12,11 @@ Capybara::SpecHelper.spec "#evaluate_async_script", requires: [:js] do
expect(result).to eq ["This is a draggable element.", "Doodle Funk"]
end
it "should support returning elements after a timeout", requires: [:js, :es_args] do
it "should support returning elements after asynchronous operation", requires: [:js, :es_args] do
@session.visit('/with_js')
@session.find(:css, '#change') # ensure page has loaded and element is available
el = @session.evaluate_async_script("var cb = arguments[0]; setTimeout(function(){ cb(document.getElementById('change')) }, 100)")
expect(el).to be_instance_of(Capybara::Node::Element)
expect(el).to eq(@session.find(:css, '#change'))
end
it "will timeout if the script takes too long" do
@session.visit('/with_js')
expect do
@session.using_wait_time(1) do
@session.evaluate_async_script("var cb = arguments[0]; setTimeout(function(){ cb(null) }, 3000)")
end
end.to raise_error
end
end

View file

@ -180,6 +180,17 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
}
})
end
describe "#evaluate_async_script" do
it "will timeout if the script takes too long" do
@session.visit('/with_js')
expect do
@session.using_wait_time(1) do
@session.evaluate_async_script("var cb = arguments[0]; setTimeout(function(){ cb(null) }, 3000)")
end
end.to raise_error Selenium::WebDriver::Error::ScriptTimeoutError
end
end
end
describe "Element#inspect" do