Skip to content

fix(core): allow empty text in fill and keyboard_type in demo mode - #431

Open
VitorCoelho wants to merge 1 commit into
ServiceNow:mainfrom
VitorCoelho:fix/demo-mode-empty-text
Open

VitorCoelho wants to merge 1 commit into
ServiceNow:mainfrom
VitorCoelho:fix/demo-mode-empty-text

Conversation

@VitorCoelho

Copy link
Copy Markdown

What

fill() and keyboard_type() raised ZeroDivisionError in demo mode when the text was empty, because the typing delay is computed as 2000 / len(text). This change guards that division (max(len(text), 1)), so the delay for non-empty text is unchanged.

Why

With demo mode off, fill(bid, "") clears the field and keyboard_type("") does nothing, as expected. With any other demo mode (default, all_blue, only_visible_elements) the same actions fail with ZeroDivisionError: division by zero in last_action_error, and fill() leaves the old value in the field. Clearing a field with fill(bid, "") is a common agent action, so the result of an episode depended on whether demo mode was on.

How it was tested

  • New test_fill_type_empty_text, parametrized over demo_mode off and default: fill(bid, ""), fill(bid, "", True) and keyboard_type(""). The default case fails on main with ZeroDivisionError and passes with this change.
  • Checked the four demo modes by hand against a real Chromium page (tests/core/data/input_type/text_input.html): all now clear the field without an error; non-empty values behave as before.
  • pytest tests/core/test_actions_highlevel.py: 20 passed. black --check (24.2.0) is clean.

In demo mode, fill() and keyboard_type() compute the typing delay as
2000 / len(text), so an empty string raised ZeroDivisionError. The
action failed and, for fill(), the field was not cleared, while the
same action works when demo mode is off.

Guard the division so that empty text behaves the same in every demo
mode, and add a test for fill(bid, "") and keyboard_type("").

This branch has not been deployed

No deployments
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