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

get invalid element errors from session.driver

This commit is contained in:
Thomas Walpole 2017-05-31 14:07:34 -07:00
parent d8368b783b
commit 9ebb7fca0b
3 changed files with 20 additions and 4 deletions

View file

@ -99,7 +99,7 @@ module Capybara
res res
rescue *(node.respond_to?(:driver) ? node.driver.invalid_element_errors : []) rescue *(node.respond_to?(:session) ? node.session.driver.invalid_element_errors : [])
return false return false
end end

View file

@ -77,12 +77,20 @@ RSpec.describe Capybara::Result do
end end
it 'should catch invalid element errors during filtering' do it 'should catch invalid element errors during filtering' do
allow_any_instance_of(Capybara::Node::Simple).to receive(:driver).and_return(double("driver", invalid_element_errors: [::Selenium::WebDriver::Error::StaleElementReferenceError])) allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(::Selenium::WebDriver::Error::StaleElementReferenceError) allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [StandardError] )))
result = string.all('//li') { |node| node.text == 'Alpha' } result = string.all('//li', text: 'Alpha')
expect(result.size).to eq 0 expect(result.size).to eq 0
end end
it 'should return non-invalid element errors during filtering' do
allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [ArgumentError] )))
expect do
string.all('//li', text: 'Alpha').to_a
end.to raise_error(StandardError)
end
#Not a great test but it indirectly tests what is needed #Not a great test but it indirectly tests what is needed
it "should evaluate filters lazily" do it "should evaluate filters lazily" do
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java' skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'

View file

@ -119,6 +119,14 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
end end
end end
describe "all with disappearing elements" do
it "ignores stale elements in results" do
@session.visit('/path')
elements = @session.all(:link) { |node| raise Selenium::WebDriver::Error::StaleElementReferenceError }
expect(elements.size).to eq 0
end
end
describe "#evaluate_script" do describe "#evaluate_script" do
it "can return an element" do it "can return an element" do
@session.visit('/form') @session.visit('/form')