Waiting for conditions
Learn how to easily wait for different conditions in Momentic.
Smart waiting
By default, Momentic intelligently waits for the page to stabilize before performing each action. This procedure is called “Smart waiting”. Smart waiting is designed to remove the need for users to add explicit sleep commands, which is a common source of flakiness in traditional testing frameworks.
While smart waiting, Momentic will periodically check if performing the next action is possible. For example, while waiting for the page to stabilize for a CLICK
command, Momentic will periodically check if the element to be clicked is present on the page and proceed if so.
The smart waiting timeout is set to 3 seconds by default and is configurable through each test’s AI options. If your application needs more than 3 seconds to respond to user actions (e.g. your backend sometimes takes 5 seconds to respond to a click and update the frontend), you have two options:
- Increase the smart waiting timeout
- Use an explicit wait (see next section)
Tab following
By default, Momentic will wait for clicks on anchor tags that have their target
attribute set to _blank
to create a new tab. Momentic will wait up until the test’s page load timeout for the new tab to load before proceeding.
In addition, Momentic also automatically switches to new tabs that are created during interactive commands such as CLICK
or PRESS
. However, depending on your application, this behavior may be timing-dependent. If the interactive command triggers long-running JavaScript in your application that takes more than 500ms
to open the new tab, Momentic will likely not follow the tab. To ensure stable tab switching in this case, please see the next section on how to use explicit waits.
Explicit waits
Momentic offers different waiting options depending on what condition you wish to wait for.
URL change
Use the Wait for URL command to wait for the current page to a specified URL or glob. Use the Switch to tab command to switch to a different tab, which may be newly opened by an action.
Page content change
Use a Page check or Element check action to wait until the page contains some text or element you know should be present once the page is finished loading. Use the timeout option to control the maximum waiting time. This is the recommended way to wait for page loads and navigations that can take more time than the smart waiting timeout.
Arbitrary condition
Use a AI assertion action to wait until Momentic’s AI agent determines that your English statement is true. Use the timeout option to control the maximum waiting time.
Was this page helpful?