Skip to content

Commit 6f5b31a

Browse files
committed
Make Node#obscured? support nested iframes
1 parent 79748ef commit 6f5b31a

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

lib/capybara/cuprite/browser.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def obscured?(node, x = nil, y = nil)
218218
end
219219
return true if value == true
220220

221-
false
221+
frame_obscured_at?(*value.values_at("x", "y"))
222222
end
223223

224224
def all_text(node)
@@ -268,6 +268,22 @@ def attach_page(target_id = nil)
268268
target.page = Page.new(target.client, context_id: target.context_id, target_id: target.id)
269269
target.page
270270
end
271+
272+
def frame_obscured_at?(x, y)
273+
frame = page.active_frame
274+
return false if frame.main?
275+
276+
parent_frame = page.frame_by(id: frame.parent_id)
277+
frame_node = parent_frame&.at_xpath("//iframe[@id=\"#{frame.name}\"]")
278+
return false unless frame_node
279+
280+
switch_to_frame(:parent)
281+
begin
282+
obscured?(frame_node, x, y)
283+
ensure
284+
switch_to_frame(frame)
285+
end
286+
end
271287
end
272288
end
273289
end

lib/capybara/cuprite/page.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ def closed?
138138
false
139139
end
140140

141+
def active_frame
142+
if @frame_stack.empty?
143+
main_frame
144+
else
145+
@frames[@frame_stack.last]
146+
end
147+
end
148+
141149
private
142150

143151
def prepare_page
@@ -180,14 +188,6 @@ def find_position(node, **options)
180188

181189
raise
182190
end
183-
184-
def active_frame
185-
if @frame_stack.empty?
186-
main_frame
187-
else
188-
@frames[@frame_stack.last]
189-
end
190-
end
191191
end
192192
end
193193
end

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ module TestSessions
3737
RSpec.configure do |config|
3838
config.define_derived_metadata do |metadata|
3939
regexes = <<~REGEXP.split("\n").map { |s| Regexp.quote(s.strip) }.join("|")
40-
node #obscured? should work in nested iframes
4140
node #drag_to should work with jsTree
4241
node #drag_to should drag and drop an object
4342
node #drag_to should drag and drop if scrolling is needed

0 commit comments

Comments
 (0)