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

Merged
merged 7 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/capybara/playwright/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def initialize(element_or_keyboard, keys)
_key = key.last
code =
if _key.is_a?(String) && _key.length == 1
_key.upcase
_key
elsif _key.is_a?(Symbol)
key_for(_key)
else
Expand All @@ -567,7 +567,7 @@ def initialize(element_or_keyboard, keys)
when String
key.each_char do |char|
executables << PressKey.new(
key: char.upcase,
key: char,
modifiers: modifiers,
)
end
Expand Down Expand Up @@ -600,6 +600,10 @@ def execute

class PressKey
def initialize(key:, modifiers:)
# Shift always requires uppercase key
# See https://playwright.dev/docs/input#keys-and-shortcuts
key = key.upcase if modifiers.include?(MODIFIERS[:shift])

# puts "PressKey: key=#{key} modifiers: #{modifiers}"
if modifiers.empty?
@key = key
Expand Down
18 changes: 18 additions & 0 deletions spec/feature/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@
end
end

it 'can send keys without modifier' do
Capybara.app_host = 'https://github.com'
visit '/'

find('body').send_keys ['s']

expect(page).to have_field('query-builder-test')
end

it 'can send keys with modifier' do
Capybara.app_host = 'https://tailwindcss.com/'
visit '/'

find('body').send_keys [:control, 'k']

expect(page).to have_field('docsearch-input')
end

it 'does not silently pass when browser has not been started' do
expect do
page.driver.with_playwright_page do |_page|
Expand Down
Loading