Testim Copilot is here | Learn More

Handling Unexpected Popup Messages While Running Tests—With Hooks!

Had enough false positives because of in-app messages and chat pop-ups? Do you happen to have a test failing every…

Author Avatar
By Astar Rigler,

Had enough false positives because of in-app messages and chat pop-ups?

Do you happen to have a test failing every once in a while because of chat pop-ups that appear on any page at any time and cover the element you are looking to click on? If you ever had in-app messages and walkthroughs that do not allow you to interact with any other element on the page, then hooks might be a good option to try out!

What is a hook?

A hook allows you to execute custom code before, instead of, or after existing code. For example, you could write a hook to execute a two-factor authentication as part of the normal login process.

Testim.io allows you to “step in” before and after each step or test to run your own code or a group of steps. A common use case for using a hook in your test cases will be to detect and close product tours or chat boxes before executing any step. This will ensure that all elements of the page are visible and intractable as expected.

What should you do next?

If you have pop-ups you would like to close to avoid interference with the test run, one approach is to have the application admins disable these specifically for your automation users. This ensures that your test automation team has the ability to conduct tests without interference by pop-ups.

However, if that is not possible in some environments or at all you should use hooks.

Open the Testim editor and follow these steps to record an action that closes the box and then use hooks to call on that action when needed:

  1. Create a new test
  2. Record a step that closes the pop-up, for example, click on the X button to close the chat window.
  3. Put this step in a group and call it “close chatbox”
  4. Save the test
  5. Go to the Runs, configurations and create a new configuration
  6. Choose “advanced”, click “before each step handler”, and choose the “close chatbox”
    group you created.

For more information about running with test configurations see this doc.

Expert Tip

The idea demonstrated in this blog is to use a hook for a specific action you might need to take (like approving a message or closing a pop-up) in random unexpected places in the test.
However, hooks are very powerful. You can use them for other purposes like sending an API request after each test to delete entities created in the tests or to send results to Slack! If you prefer to code your hooks, create a custom coded step and set it up to run on each step or test. If you prefer recording, use shared groups for that.

Contact your CSM or Testim support to try this out!