Skip to content

Commit

Permalink
Merge pull request #86 from maciesielka/allow-lowercase-keys
Browse files Browse the repository at this point in the history
[Bugfix] Allow lowercase strings in `send_keys`
  • Loading branch information
YusukeIwaki authored Dec 14, 2024
2 parents 62ffa7b + 3a5ffff commit ea5415f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit ea5415f

Please sign in to comment.