Skip to content
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
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 == [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
Loading