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:
parent
d8368b783b
commit
9ebb7fca0b
3 changed files with 20 additions and 4 deletions
|
@ -99,7 +99,7 @@ module Capybara
|
|||
|
||||
res
|
||||
|
||||
rescue *(node.respond_to?(:driver) ? node.driver.invalid_element_errors : [])
|
||||
rescue *(node.respond_to?(:session) ? node.session.driver.invalid_element_errors : [])
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
|
@ -77,12 +77,20 @@ RSpec.describe Capybara::Result do
|
|||
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' }
|
||||
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: [StandardError] )))
|
||||
result = string.all('//li', text: 'Alpha')
|
||||
expect(result.size).to eq 0
|
||||
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
|
||||
it "should evaluate filters lazily" do
|
||||
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
||||
|
|
|
@ -119,6 +119,14 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
|||
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
|
||||
it "can return an element" do
|
||||
@session.visit('/form')
|
||||
|
|
Loading…
Reference in a new issue