Skip to content

Commit

Permalink
Do not modify special keys
Browse files Browse the repository at this point in the history
  • Loading branch information
maciesielka committed Dec 18, 2024
1 parent f3e81a5 commit 192b1a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/capybara/playwright/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ def execute

class PressKey
def initialize(key:, modifiers:)
# Shift always requires uppercase key
# Shift requires an explicitly uppercase a-z key to produce the correct output
# See https://playwright.dev/docs/input#keys-and-shortcuts
key = key.upcase if modifiers.include?(MODIFIERS[:shift])
key = key.upcase if modifiers.include?(MODIFIERS[:shift]) && key.match?(/^[a-z]$/)

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

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

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

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

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

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

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

it 'can shift+modifier' do
Capybara.app_host = 'https://github.com'
visit '/'

expect_any_instance_of(Playwright::ElementHandle).to receive(:press).with('Shift+Home')

find('body').send_keys %i[shift home]
end
end

it 'does not silently pass when browser has not been started' do
Expand Down

0 comments on commit 192b1a0

Please sign in to comment.