Skip to content
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

Merged
merged 1 commit into from
Aug 15, 2021

Conversation

seanpdoyle
Copy link
Contributor

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 raises
an error.

History.md Outdated Show resolved Hide resolved
lib/capybara/session.rb Outdated Show resolved Hide resolved
@@ -234,6 +234,19 @@
end
end

describe '#active_element', requires: [:js] do
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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

seanpdoyle added a commit to seanpdoyle/capybara that referenced this pull request Aug 15, 2021
[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
seanpdoyle added a commit to seanpdoyle/capybara that referenced this pull request Aug 15, 2021
[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
seanpdoyle added a commit to seanpdoyle/capybara that referenced this pull request Aug 15, 2021
[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)
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 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?

@seanpdoyle
Copy link
Contributor Author

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 seanpdoyle:active-element, so it also contains commits from this branch.

@twalpole twalpole merged commit 5c1d6d3 into teamcapybara:master Aug 15, 2021
seanpdoyle added a commit to seanpdoyle/capybara that referenced this pull request Aug 16, 2021
[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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
seanpdoyle added a commit to seanpdoyle/cuprite that referenced this pull request Feb 29, 2024
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
route pushed a commit to rubycdp/cuprite that referenced this pull request Mar 1, 2024
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
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.

2 participants