Skip to content

fix(node): fill text fields with real key presses so minlength validates - #377

Open
route wants to merge 3 commits into
mainfrom
fix/minlength-validity
Open

route wants to merge 3 commits into
mainfrom
fix/minlength-validity

Conversation

@route

@route route commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Part of #307.

Chrome checks minlength only after a user edit, and a value set from JS never counts as one, so has_field(..., valid: false) couldn't see a too-short value. Text inputs (text, password, email, search, tel, url) and textareas are now filled the way Capybara's Selenium node does it:

  • Focus, select the current value, and type with Ferrum's node.type.
  • Values over 30 characters use Capybara's rapid mode, like Selenium: the first 4 and last 3 characters as real keys, the middle set from JS. rapid: true/false is supported, and the "options ignored" warning is gone. Values of 7 characters or fewer are always typed in full: the split overlapped there ("Hello" became "Hellllo"), which Capybara's Selenium node also does.
  • A real blur fires one native change, then the field is focused again. That step is skipped when typing Enter submitted the form and left the page, which otherwise raised ObsoleteNode and made Capybara retry set until it timed out.
  • Newlines are sent as \r: Ferrum's keyboard.type drops \n inside a string, fixed in fix(keyboard): type "\n" in a string as Enter ferrum#730. The workaround can go once that is released.

Now passing and no longer skipped:

  • #has_field with valid should be false if field is invalid
  • #fill_in should handle carriage returns with line feeds in a textarea correctly
  • node #set should submit single text input forms if ended with \n

Every event-order and preventDefault spec in node_spec.rb passes unchanged.

Cost, average set time vs main:

Value main this PR
10 chars 6ms 15ms
30 chars 4ms 30ms
31 chars (rapid) 4ms 16ms
500 chars (rapid) 6ms 11ms

The threshold stays at 30 characters, like Selenium.

Metrics/ClassLength goes from 300 to 310 for Node.

Chrome checks minlength only after a user edit, and a value set from JS never counts as one. Text inputs and textareas are now typed with
Ferrum's node.type, and values over 30 characters use Capybara's Selenium rapid mode. Newlines are sent as \r because Ferrum drops \n.
has_field with valid, CRLF in a textarea and \n submitting a single-input form pass and are no longer skipped.
Typing a trailing \r presses Enter, which can submit the form and navigate away before the final blur/focus runs. That raised ObsoleteNode,
and Capybara retried set on the stale node until it timed out. Also inline the rapid-append JS and raise Metrics/ClassLength to 310.
@route
route marked this pull request as ready for review November 24, 2026 19:32
Rapid mode types the first 4 and last 3 characters and sets the middle from JS, so a value of 7 characters or fewer overlapped: "Hello" became
"Hellllo". It now types such values in full. Adds specs for a long value, a short one with rapid: true and maxlength with rapid: true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant