invalid element error while filtering results shold be caught

This commit is contained in:
Thomas Walpole 2017-05-31 11:50:32 -07:00
parent 8e407cc243
commit d8368b783b
2 changed files with 21 additions and 1 deletions

View File

@ -91,8 +91,16 @@ module Capybara
end
end
res &&= node.session.using_wait_time(0){ @filter_block.call(node)} unless @filter_block.nil?
res &&= if node.respond_to?(:session)
node.session.using_wait_time(0){ @filter_block.call(node) }
else
@filter_block.call(node)
end unless @filter_block.nil?
res
rescue *(node.respond_to?(:driver) ? node.driver.invalid_element_errors : [])
return false
end
def visible

View File

@ -71,6 +71,18 @@ RSpec.describe Capybara::Result do
expect(result[-1].text).to eq 'Delta'
end
it 'works with filter blocks' do
result = string.all('//li') { |node| node.text == 'Alpha' }
expect(result.size).to eq 1
end
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(::Selenium::WebDriver::Error::StaleElementReferenceError)
result = string.all('//li') { |node| node.text == 'Alpha' }
expect(result.size).to eq 0
end
#Not a great test but it indirectly tests what is needed
it "should evaluate filters lazily" do
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'