How to handle browser popup in codecept JS

How to handle browser Pop Up?

I have tried with acceptPopup and it isn’t working.
Also, I have tried with Esc key to avoid the pop-up but it isn’t working.
Can you pls help with the same.
image
@christian_wolf : let me know your views :smile:

Thanks in advance.

@Vish131 you cannot handle the popup using Webdriver (if that is your used helper) or other helper.
When you’re testing with Chrome, you can pass a parameter to disable notification completely.

See https://webkul.com/blog/handle-browser-level-notification-using-selenium/ for details.

in you codeceptjs config it should look something like this:
//…
helpers: {
WebDriver: {
url: url,
browser: “chrome”,
//…
desiredCapabilities: {
chromeOptions: {
args: ["—disable-notifications"]
}
}
},
//…

Hi,
i want to accept the popup .so what should it would be .
Thanks :slight_smile:

you cannot accept the popup as far a s i know because it’s a system (windows/lonux/MacOS?) popup and therfor you must disable it.

Yes, I will work on this and share my observations as well.

As of now after adding the code with args : ["—disable-notifications"] ,

the pop-up is still visible.

Thanks mate for quick response

@Vish131 sorry to hear that it dit not help.

Maybe this thread has an answer for you: https://stackoverflow.com/questions/38684175/how-to-click-allow-on-show-notifications-popup-using-selenium-webdriver ?

1 Like

@Vish131
I do this way for Chrome + WebDriver

conf.desiredCapabilities.chromeOptions = {
  prefs: {
    profile: {
      default_content_settings: {
        popups: 0,
      },
    },
  },
};
1 Like

Thanks @christian_wolf and @juancuervo … i would go through the suggestions and will provide what works for me in detail.

Cheers,
Vishal

Hi, I tried using similar approach for setting default download directory in browser still it’s not working. Can you confirm if there are any changes required.
desiredCapabilities: {

      chromeOptions: {

        prefs: {

          'download.default_directory': filePath,

        },

      },

    },
},

Thanks

@gouri

This works for me

desiredCapabilities.chromeOptions = {
    prefs: {
      profile: {
        default_content_settings: {
          popups: 0,
        },
        default_content_setting_values: {
          automatic_downloads: true,
        },
      },
      download: {
        default_directory: filePath,
        prompt_for_download: false,
      },
    },
    extensions: [],
  };
1 Like

Hi,

Thank you so much for quick reply, solution mentioned above worked properly.

However to make it more dynamic i was trying to create folder before test execution and remove created folder after execution successfully completed.

Dynamic folder creation is working properly at runtime using following code snippet

_beforeSuite()

{

if (!Directory.Exists(downloadDir)){

  newPath = Directory.CreateDirectory(downloadDir).FullName;

  }

}

but Delete folder is not working at runtime, for which i tried following approaches

  1. Similar to createDirectory i tried to use Directory.Delete in _afterSuite
  2. Installed fs-extra module of npm and tried using remove function of file system in javascript but still folder is not getting deleted.

If you have handled dynamic folder creation at runtime can you please guide on same.

Thanks once again.