-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support Session#active_element
#2489
Conversation
spec/shared_selenium_session.rb
Outdated
@@ -234,6 +234,19 @@ | |||
end | |||
end | |||
|
|||
describe '#active_element', requires: [:js] do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets move this into the non-selenium specific specs - something like lib/capybara/spec/session/active_element_spec.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please add relevant tabindex attributes in the form since the test depends on the tabbing order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current tests assertions are about the first field that is not marked with [disabled]
.
Also, please add relevant tabindex attributes in the form since the test depends on the tabbing order.
What did you have in mind?
@@ -148,6 +148,10 @@ def evaluate_async_script(script, *args) | |||
unwrap_script_result(result) | |||
end | |||
|
|||
def active_element | |||
build_node(browser.switch_to.active_element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this changes the behavior of Session#send_keys when using the selenium driver because build_node
will build instances specialized for the specific browser being used - which may not end up directly calling the Selenium send_keys
directly - was this intentional? (it may actually be an improvement, just checking)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not intentional. Calling build_node
was an attempt to transform an instance of Selenium::WebDriver::Element
into an instance of Capybara::Node::Element
for the equivalence check in the test suite. Is there a better way or a different abstraction to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No -- just wanted to make sure you realized that build_node
would return a ::Capybara::Selenium::ChromeNode instance when using the selenium driver with Chrome, which has some extra code to work around an issue with emoji in send_keys -- not necessarily a bad thing just different than the previous behavior
28b01a8
to
5d0fdc1
Compare
[Follow-up to teamcapybara#2489][], adds support for filtering fields, links, and buttons based on whether or not they're focused. [Follow-up to teamcapybara#2489]: teamcapybara#2489
As a [follow-up][] to [teamcapybara#2422][], expose the [document.activeElement][] (that is, the element with focus) via the `Session`. When called from Rack Test environments, `Session#active_element` raises an error. [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement [follow-up]: teamcapybara#2422 (comment) [teamcapybara#2422]: teamcapybara#2422 [document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
5d0fdc1
to
5c1d6d3
Compare
[Follow-up to teamcapybara#2489][], adds support for filtering fields, links, and buttons based on whether or not they're focused. [Follow-up to teamcapybara#2489]: teamcapybara#2489
[Follow-up to teamcapybara#2489][], adds support for filtering fields, links, and buttons based on whether or not they're focused. [Follow-up to teamcapybara#2489]: teamcapybara#2489
def send_keys(*args) | ||
active_element.send_keys(*args) | ||
active_element.native.send_keys(*args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change before https://github.com/teamcapybara/capybara/pull/2489/files#r689119285.
Should we revert it so that the send_keys
goes through the specialized nodes?
It's worth mentioning that I've opened #2490 as a follow-up PR. Unfortunately, GitHub won't let me declare the branch off of |
[Follow-up to teamcapybara#2489][], adds support for filtering fields, links, and buttons based on whether or not they're focused. [Follow-up to teamcapybara#2489]: teamcapybara#2489
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As of [teamcapybara/capybara#2489][] (April 14, 2021), Capybara supports calling `#send_keys` on the page (instead of a particular element). Similarly, there is a global `:focused` filter that compares the node to the [Document.activeElement][]. These are both powered by a [Driver#active_element][] method in drivers that support JavaScript. This commit integrates `Capybara::Cuprite::Driver` to support both. [teamcapybara/capybara#2489]: teamcapybara/capybara#2489 [Driver#active_element]: https://github.com/teamcapybara/capybara/blob/c0cbf4024c1abd48b0c22c2930e7b05af58ab284/lib/capybara/driver/base.rb#L62-L68 [Document.activeElement]: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
As a follow-up to #2422, expose the document.activeElement
(that is, the element with focus) via the
Session
.When called from Rack Test environments,
Session#active_element
raisesan error.