From 905bd56040786c58673f91fbd03885a7952340c6 Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Thu, 31 Oct 2024 10:42:00 -0400 Subject: [PATCH 1/6] Allow lowercase strings in `send_keys` --- lib/capybara/playwright/node.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/capybara/playwright/node.rb b/lib/capybara/playwright/node.rb index 90642eb..866da33 100644 --- a/lib/capybara/playwright/node.rb +++ b/lib/capybara/playwright/node.rb @@ -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 @@ -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 From 390f8212621ad6027e24654d65e25222fc9e1b4a Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Thu, 31 Oct 2024 11:12:37 -0400 Subject: [PATCH 2/6] Add tests --- spec/feature/example_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/feature/example_spec.rb b/spec/feature/example_spec.rb index 32ce4fe..3514093 100644 --- a/spec/feature/example_spec.rb +++ b/spec/feature/example_spec.rb @@ -91,4 +91,22 @@ puts "#{li.with_playwright_element_handle { |handle| handle.text_content }} by Playwright" end end + + it 'can send keys with modifier' do + Capybara.app_host = 'https://github.com' + visit '/' + + page.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 '/' + + page.send_keys [:control, 'k'] + + expect(page).to have_field('docsearch-input') + end end From ca8b342fd558fe70b0a97d37a3d2675956c2651c Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Sun, 1 Dec 2024 10:36:19 -0500 Subject: [PATCH 3/6] Update test name --- spec/feature/example_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/feature/example_spec.rb b/spec/feature/example_spec.rb index 9f0677a..c13fa0b 100644 --- a/spec/feature/example_spec.rb +++ b/spec/feature/example_spec.rb @@ -92,7 +92,7 @@ end end - it 'can send keys with modifier' do + it 'can send keys without modifier' do Capybara.app_host = 'https://github.com' visit '/' From 8160dbb74f283e6b9962592d6c18ee7590c78c07 Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Sun, 1 Dec 2024 10:51:20 -0500 Subject: [PATCH 4/6] Use Node#send_keys for test --- spec/feature/example_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/feature/example_spec.rb b/spec/feature/example_spec.rb index c13fa0b..8b622ea 100644 --- a/spec/feature/example_spec.rb +++ b/spec/feature/example_spec.rb @@ -96,7 +96,7 @@ Capybara.app_host = 'https://github.com' visit '/' - page.send_keys ['s'] + find('body').send_keys ['s'] expect(page).to have_field('query-builder-test') end @@ -105,7 +105,7 @@ Capybara.app_host = 'https://tailwindcss.com/' visit '/' - page.send_keys [:control, 'k'] + find('body').send_keys [:control, 'k'] expect(page).to have_field('docsearch-input') end From 733e025e2c75ccf04a20c78f99e51538f31f370d Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Wed, 11 Dec 2024 09:00:41 -0500 Subject: [PATCH 5/6] Add special handling for the shift key --- lib/capybara/playwright/node.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/capybara/playwright/node.rb b/lib/capybara/playwright/node.rb index 866da33..0a1857c 100644 --- a/lib/capybara/playwright/node.rb +++ b/lib/capybara/playwright/node.rb @@ -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.upcase! if modifiers.include?(MODIFIERS[:shift]) + # puts "PressKey: key=#{key} modifiers: #{modifiers}" if modifiers.empty? @key = key From 3a5ffffe358ff2ae40f908920e395ea6e179a5fa Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Wed, 11 Dec 2024 09:29:20 -0500 Subject: [PATCH 6/6] Fix issue for frozen strings --- lib/capybara/playwright/node.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capybara/playwright/node.rb b/lib/capybara/playwright/node.rb index 0a1857c..f50b906 100644 --- a/lib/capybara/playwright/node.rb +++ b/lib/capybara/playwright/node.rb @@ -602,7 +602,7 @@ class PressKey def initialize(key:, modifiers:) # Shift always requires uppercase key # See https://playwright.dev/docs/input#keys-and-shortcuts - key.upcase! if modifiers.include?(MODIFIERS[:shift]) + key = key.upcase if modifiers.include?(MODIFIERS[:shift]) # puts "PressKey: key=#{key} modifiers: #{modifiers}" if modifiers.empty?