Skip to content

Add support for Node#obscured? #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 6, 2025

Conversation

myabc
Copy link
Contributor

@myabc myabc commented Feb 18, 2025

This PR adds initial support for Node#obscured?.

Enables the obscured: option with Capybara::Node::Finders#all, Capybara::Node::Finders#find and the various assertion methods and matchers that support the same options, e.g.

      assert_selector("button[data-close-dialog-id]", obscured: false)
      assert_selector("button[data-submit-dialog-id]", obscured: false)

Essentially it is a port of Capybara::Selenium::Node#obscured? including the injected script (Capybara::Selenium::Node::OBSCURED_OR_OFFSET_SCRIPT).

A couple things to note:


undefined method `execution_id!' for nil stack trace
  1) Capybara::Session Cuprite node #obscured? should work in nested iframes
     Failure/Error: inject_extensions
 NoMethodError:
   undefined method `execution_id!' for nil
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/ferrum-0.16/lib/ferrum/page.rb:490:in `block in inject_extensions'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/ferrum-0.16/lib/ferrum/page.rb:483:in `each'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/ferrum-0.16/lib/ferrum/page.rb:483:in `inject_extensions'
 # ./lib/capybara/cuprite/page.rb:126:in `switch_to_frame'
 # ./lib/capybara/cuprite/browser.rb:284:in `frame_obscured_at?'
 # ./lib/capybara/cuprite/browser.rb:221:in `obscured?'
 # ./lib/capybara/cuprite/node.rb:21:in `command'
 # ./lib/capybara/cuprite/node.rb:217:in `obscured?'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:317:in `block in obscured?'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/node/base.rb:84:in `synchronize'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:317:in `obscured?'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb:358:in `block (6 levels) in <top (required)>'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/session.rb:451:in `within_frame'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb:357:in `block (5 levels) in <top (required)>'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/session.rb:451:in `within_frame'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb:355:in `block (4 levels) in <top (required)>'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/session.rb:451:in `within_frame'
 # /Users/alexbcoles/.gem/ruby/3.3.4/gems/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb:354:in `block (3 levels) in <top (required)>'
 # ./spec/spec_helper.rb:109:in `block (2 levels) in <top (required)>'

@myabc myabc force-pushed the feature/support-node-obscured branch from 67761db to f7b4a1d Compare February 23, 2025 16:55
@myabc myabc requested a review from toy February 23, 2025 16:57
@myabc myabc force-pushed the feature/support-node-obscured branch from f7b4a1d to d29cde6 Compare February 23, 2025 19:51
Copy link
Contributor

@toy toy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything suspicious, but it is not up to me to approve
Nice that you extracted chunk to ferrum

@myabc myabc force-pushed the feature/support-node-obscured branch from d29cde6 to ef7fdb2 Compare March 5, 2025 00:03
@route
Copy link
Member

route commented Mar 5, 2025

Nice work! Let me take a thorough look and I get back to you


switch_to_frame(:parent)
begin
obscured?(frame_node, x, y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be possible to check it even without switching frames, but not 100%

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing just this frame switching but it broke the implementation - the original implementation of isObscured calls document.elementFromPoint(px, py) (always on the current window) and doesn't know how to traverse nested frames.

I've gone ahead and reimplemented the nested frame handling in JavaScript - Although I think it'd probably be a bit more concise to use recursion, I've used iteration as that's what's been used elsewhere (e.g. _frameOffset).

myabc and others added 3 commits March 5, 2025 17:00
Ports `Capybara::Selenium::Node#obscured?` to Cuprite.

N.B. Support for nested iframes is not yet implemented.
Co-authored-by: Ivan Kuchin <tadump+git@gmail.com>
@myabc myabc force-pushed the feature/support-node-obscured branch from ef7fdb2 to bc037f6 Compare March 5, 2025 20:25
myabc added 2 commits March 5, 2025 17:29
Teaches `isObscured` how to traverse nested frames.
Although `Capybara::Selenium::Node#obscured?` accepts `x` and `y`
arguments, these parameters do not appear to part of the public Capybara
API.
@myabc myabc force-pushed the feature/support-node-obscured branch from bc037f6 to 91eb89f Compare March 5, 2025 20:29
@myabc myabc requested a review from route March 5, 2025 20:52
@route route merged commit 4fa8126 into rubycdp:main Mar 6, 2025
6 checks passed
@route
Copy link
Member

route commented Mar 6, 2025

Awesome thanks!

@myabc myabc deleted the feature/support-node-obscured branch March 6, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants