Overview
When testing web applications, particularly those built with modern frameworks like React, you may encounter issues where input actions fail or behave inconsistently. This can manifest as the wrong value being entered or the input action failing entirely. These issues often stem from the application's own logic interfering with standard browser automation events. For example, an application might automatically insert a default value (like '0') into a field immediately after it has been cleared. Additionally, older test steps that include an explicit text selection action before an input are often no longer necessary, as modern runtimes handle field clearing automatically.
How It Works
The test runtime prepares a field for new input by automatically performing two steps:
- Selecting any existing content within the input field.
- Clearing the selected content, typically by simulating a backspace key press.
In some React applications, this clearing action can trigger an event listener that causes the application to immediately repopulate the field with a default value. When the runtime then proceeds to enter the intended text, it may be appended to this default value, leading to an incorrect final input.
To resolve this, you can use an advanced setting on the input action:
- Remove Unnecessary Text Selection Steps: First, ensure there are no explicit text selection or clearing actions right before your
Inputaction. These are redundant and can sometimes cause timing conflicts. - Enable Force React: In the action's advanced settings, enable the
Enable Force Reactoption. This setting changes the input method. Instead of simulating native keyboard events, it directly manipulates the application's React state to set the value. This bypasses the application's event listeners that cause the interference, ensuring the correct value is set and remains stable.
Limitations
The Enable Force React setting is specifically designed for applications built using the React JavaScript framework. It will not have an effect on applications built with other technologies like Angular, Vue.js, or standard HTML/JavaScript.
Related Info
To determine if your application exhibits this behavior, you can test it manually. Navigate to the relevant page, click into the input field, select all the text (Ctrl+A or Cmd+A), and press the Backspace key. If the field automatically repopulates with a default value, then enabling Enable Force React is the recommended solution for stabilizing your input actions.