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

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
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 res
rescue *(node.respond_to?(:driver) ? node.driver.invalid_element_errors : [])
return false
end end
def visible def visible

View file

@ -71,6 +71,18 @@ RSpec.describe Capybara::Result do
expect(result[-1].text).to eq 'Delta' expect(result[-1].text).to eq 'Delta'
end 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 #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'