diff --git a/lib/capybara/playwright/node.rb b/lib/capybara/playwright/node.rb index f50b906..912d272 100644 --- a/lib/capybara/playwright/node.rb +++ b/lib/capybara/playwright/node.rb @@ -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? diff --git a/spec/feature/example_spec.rb b/spec/feature/example_spec.rb index 8b622ea..27f4155 100644 --- a/spec/feature/example_spec.rb +++ b/spec/feature/example_spec.rb @@ -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