Handling Popups In Browser Tests


This guide describes how to manage popups such as modals or application windows in a Synthetics browser test.



Synthetic browser tests automatically handle JavaScript modals:

  • alert modals are closed.
  • prompt and confirm modals are answered Lorem Ipsum.

Basic authentication

For basic authentication popups, specify the associated credentials in your browser test configuration under Advanced Options > HTTP Auth:

Basic Auth Popup

Application popups

Anchored popups

If a popup appears at a specific point of your journey, you can record a step to close it and allow this step to fail using the corresponding option. This way, your test knows how to behave in case a popup appears. If the popup does not show up, the step fails without causing the whole test to fail.

Allow step to fail to handle popup

Moving popups

If the time at which these popups appear in a session is not predictable, check with the third party providing the popup to see if they can create a rule that prevents the popup from appearing during your browser test execution. They could, for example, provide you with a cookie that you can input below the dedicated Advanced option of your test.

Alternatively, use one of these methods to ensure your popup is closed and your test is able to continue its journey:

  • Create a JavaScript assertion at the beginning of your browser test to regularly try to close the popup:

    if (document.querySelector("<ELEMENT>")) {
      return true;
    } else {
      return new Promise((resolve, reject) => {
        const isPopupDisplayed = () => {
          if (document.querySelector("<ELEMENT>")) {
        let popup = setInterval(isPopupDisplayed, 500);
  • Record steps to close the popup, add them between all your other browser test steps, and select the Allow this step to fail option for each of them.

Further Reading