Skip to content

Commit eb7072f

Browse files
author
Tim Connor
committed
Allow missing elements to be inspected
1 parent 013d705 commit eb7072f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/ae_page_objects/element_proxy.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ def method_missing(name, *args, &block)
103103
end
104104

105105
implicit_element.__send__(name, *args, &block)
106+
rescue AePageObjects::LoadingElementFailed
107+
raise unless %w(to_s inspect).include? name.to_s
108+
109+
# The element is being serialized for debug / warning purposes. In
110+
# this situation it is a valid case that the element may not exist so
111+
# instead of raising an error just return a string indicating that the
112+
# element does not exist.
113+
'[element not found]'
106114
end
107115

108116
def respond_to?(*args)

test/unit/element_proxy_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ def test_absent__element_not_found
115115
assert proxy.absent?(wait: 20)
116116
end
117117

118+
def test_inspect__element_not_found
119+
proxy = new_proxy
120+
element_class.expects(:new).raises(AePageObjects::LoadingElementFailed)
121+
assert_equal '[element not found]', proxy.inspect
122+
end
123+
124+
def test_to_s__element_not_found
125+
proxy = new_proxy
126+
element_class.expects(:new).raises(AePageObjects::LoadingElementFailed)
127+
assert_equal '[element not found]', proxy.to_s
128+
end
129+
118130
def test_presence
119131
proxy = new_proxy
120132

0 commit comments

Comments
 (0)