Text input approaches with typeText and setText

Last edited on

The Squish API offers two different functions to type text into INPUT fields:

While Squish uses setText by default when recording a test, there are some use cases where typeText has to be used, for example if an event handler should be triggered by the input.

Making text input with setText

The function setText is recorded by default. It sets the text of the object programatically. Using setText will work the same way with any browser, regardless the fact that different browsers process text input in different ways. It accepts text input that can be processes by any browser but does not work with text input which some browsers won't be able to process, e.g. , or other non-alphanumeric characters on Firefox or Safari. Besides, setText does not interfere with other applications running in parallel. This allows working with other applications while a test is running.

Making text input typeText

The drawback of the above-standing approach is that a call to setText might not trigger an event handler of the web application. For example, if the web application implements a validation function that is called when the user types to accept, deny or modify the text input. To trigger such an event handler, typeText can be used as it simulates key-strokes as they are done by a user typing on a keyboard.

To set the focus to the INPUT field before making the text input, setFocus can be called.