Class: Capybara::Playwright::Node::SendKeys
- Inherits:
-
Object
- Object
- Capybara::Playwright::Node::SendKeys
- Defined in:
- lib/capybara/playwright/node.rb
Defined Under Namespace
Constant Summary collapse
- MODIFIERS =
{ alt: 'Alt', ctrl: 'Control', control: 'Control', meta: 'Meta', command: 'Meta', cmd: 'Meta', shift: 'Shift', }.freeze
- KEYS =
{ cancel: 'Cancel', help: 'Help', backspace: 'Backspace', tab: 'Tab', clear: 'Clear', return: 'Enter', enter: 'Enter', shift: 'Shift', control: 'Control', alt: 'Alt', pause: 'Pause', escape: 'Escape', space: 'Space', page_up: 'PageUp', page_down: 'PageDown', end: 'End', home: 'Home', left: 'ArrowLeft', up: 'ArrowUp', right: 'ArrowRight', down: 'ArrowDown', insert: 'Insert', delete: 'Delete', semicolon: 'Semicolon', equals: 'Equal', numpad0: 'Numpad0', numpad1: 'Numpad1', numpad2: 'Numpad2', numpad3: 'Numpad3', numpad4: 'Numpad4', numpad5: 'Numpad5', numpad6: 'Numpad6', numpad7: 'Numpad7', numpad8: 'Numpad8', numpad9: 'Numpad9', multiply: 'NumpadMultiply', add: 'NumpadAdd', separator: 'NumpadDecimal', subtract: 'NumpadSubtract', decimal: 'NumpadDecimal', divide: 'NumpadDivide', f1: 'F1', f2: 'F2', f3: 'F3', f4: 'F4', f5: 'F5', f6: 'F6', f7: 'F7', f8: 'F8', f9: 'F9', f10: 'F10', f11: 'F11', f12: 'F12', meta: 'Meta', command: 'Meta', }
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(element_or_keyboard, keys) ⇒ SendKeys
constructor
A new instance of SendKeys.
Constructor Details
#initialize(element_or_keyboard, keys) ⇒ SendKeys
Returns a new instance of SendKeys.
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/capybara/playwright/node.rb', line 530 def initialize(element_or_keyboard, keys) @element_or_keyboard = element_or_keyboard holding_keys = [] @executables = keys.each_with_object([]) do |key, executables| if MODIFIERS[key] holding_keys << key else if holding_keys.empty? case key when String executables << TypeText.new(key) when Symbol executables << PressKey.new( key: key_for(key), modifiers: [], ) when Array _key = key.last code = if _key.is_a?(String) && _key.length == 1 _key.upcase elsif _key.is_a?(Symbol) key_for(_key) else raise ArgumentError.new("invalid key: #{_key}. Symbol of 1-length String is expected.") end modifiers = key.first(key.size - 1).map { |k| modifier_for(k) } executables << PressKey.new( key: code, modifiers: modifiers, ) end else modifiers = holding_keys.map { |k| modifier_for(k) } case key when String key.each_char do |char| executables << PressKey.new( key: char.upcase, modifiers: modifiers, ) end when Symbol executables << PressKey.new( key: key_for(key), modifiers: modifiers ) else raise ArgumentError.new("#{key} cannot be handled with holding key #{holding_keys}") end end end end end |
Instance Method Details
#execute ⇒ Object
595 596 597 598 599 |
# File 'lib/capybara/playwright/node.rb', line 595 def execute @executables.each do |executable| executable.execute_for(@element_or_keyboard) end end |