diff --git a/lib/ae_page_objects/element_proxy.rb b/lib/ae_page_objects/element_proxy.rb index c6094eb1..d9a73871 100644 --- a/lib/ae_page_objects/element_proxy.rb +++ b/lib/ae_page_objects/element_proxy.rb @@ -103,6 +103,14 @@ def method_missing(name, *args, &block) end implicit_element.__send__(name, *args, &block) + rescue AePageObjects::LoadingElementFailed + raise unless %w(to_s inspect).include? name.to_s + + # The element is being serialized for debug / warning purposes. In + # this situation it is a valid case that the element may not exist so + # instead of raising an error just return a string indicating that the + # element does not exist. + '[element not found]' end def respond_to?(*args) diff --git a/test/unit/element_proxy_test.rb b/test/unit/element_proxy_test.rb index 90e7deae..bed5ad4b 100644 --- a/test/unit/element_proxy_test.rb +++ b/test/unit/element_proxy_test.rb @@ -115,6 +115,18 @@ def test_absent__element_not_found assert proxy.absent?(wait: 20) end + def test_inspect__element_not_found + proxy = new_proxy + element_class.expects(:new).raises(AePageObjects::LoadingElementFailed) + assert_equal '[element not found]', proxy.inspect + end + + def test_to_s__element_not_found + proxy = new_proxy + element_class.expects(:new).raises(AePageObjects::LoadingElementFailed) + assert_equal '[element not found]', proxy.to_s + end + def test_presence proxy = new_proxy