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

[Bugfix] Allow lowercase strings in send_keys #86

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

maciesielka
Copy link

@maciesielka maciesielka commented Oct 31, 2024

Summary

This PR provides functionality that allows callers to specify lowercase keys in send_keys, something not currently supported as they are always uppercased unless they are sent as an individual string.

Background

I'd like to write a test to validate behavior for opening a window with send_keys [:control, 'k'], but that's not possible because the keys are implicitly uppercased in this library. Note that this same command works using a Selenium driver.

A possible workaround for existing versions is below, but ought to be supported outright.

page.driver.with_playwright_page do |page|
  page.keyboard.press('Control+k') # note this isn't `press('Control+K')`
end

I've added a test to this PR that confirms the correct behavior on sites that include shortcuts with modifiers (Tailwind) and without (Github).

@YusukeIwaki
Copy link
Owner

@maciesielka Hi, thank you for your contribution and sorry for late review.

It seems this PR breaks some compatibility for Capybara driver. Could you check the CI failure and fix it?

Failures:

  1) Capybara::Session Playwright node #send_keys should allow for multiple simultaneous keys
     Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }

       expected: "Oceanside"
            got: "oceanside"

       (compared using ==)
     # ./vendor/bundle/ruby/3.3.0/gems/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb:1112:in `block (3 levels) in <top (required)>'

  2) Capybara::Session Playwright node #send_keys should hold modifiers at top level
     Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }

       expected: "oceanSIDE"
            got: "oceanside"

       (compared using ==)
     # ./vendor/bundle/ruby/3.3.0/gems/capybara-3.40.0/lib/capybara/spec/session/node_spec.rb:1118:in `block (3 levels) in <top (required)>'

@maciesielka
Copy link
Author

maciesielka commented Dec 11, 2024

@maciesielka Hi, thank you for your contribution and sorry for late review.

It seems this PR breaks some compatibility for Capybara driver. Could you check the CI failure and fix it?

No worries, thanks for taking a peek! I'll try and investigate the test failures soon.

@maciesielka
Copy link
Author

@maciesielka Hi, thank you for your contribution and sorry for late review.

It seems this PR breaks some compatibility for Capybara driver. Could you check the CI failure and fix it?

@YusukeIwaki Looks like the shift key needs special handling, check out changes in 733e025 which include a comment to a seemingly important note from the Playwright docs. (I'm not sure how to run CI on those changes on my own, so I'll check back once you kick them off)

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