7

I'm automating tests using Selenium and C# and I need to open an external app from the browser. The problem is, I always get this notification and it blocks the test execution.

Does anyone know how to deal with this?

Notification screenshot

Scott Dudley
  • 3,256
  • 1
  • 18
  • 30
Jose Ferreira
  • 71
  • 1
  • 5
  • This is a Chrome annoyance, something you need to mention in the question. There is a [recent bug report](https://bugs.chromium.org/p/chromium/issues/detail?id=788431) about it. Marked as "fixed", consider using another browser until that bug fix makes it onto your machine. – Hans Passant Feb 08 '18 at 12:34
  • Yes, I had already seen that. But my problem isn't about Chrome 'forgetting' the custom protocol. It's how to deal with it for the first time it apears. I need to either: - Dismiss it - Prevent it from showing – Jose Ferreira Feb 08 '18 at 13:44
  • Hmya, Chrome surely has a boss-override switch to suppress this prompt. How reconfiguring Chrome is any different from clicking the button is not obvious. Google "chrome disable protocol handler prompt" for obvious hits. Or use another browser. – Hans Passant Feb 08 '18 at 13:59
  • Our applications need to run on Chrome, so replacing the browser is not an option. Also, I can't just hide or ignore the notification. Chrome must be allowed to open the external application (G.Printer) for the tests to pass. – Jose Ferreira Feb 08 '18 at 15:46
  • @JoseFerreira , did you find a usable/working solution to this problem? I have the same question but the answers listed below are not suitable for my setup. – ErikWe Jun 26 '19 at 08:12
  • I hope following link helps you. https://stackoverflow.com/questions/55124895/how-to-disable-always-open-these-types-of-links-in-the-associated-app-chrome-a/60347389#60347389 – Subba Changa Feb 22 '20 at 14:21
  • I hope following link helps you. https://stackoverflow.com/questions/55124895/how-to-disable-always-open-these-types-of-links-in-the-associated-app-chrome-a/60347389#60347389 – Subba Changa Feb 22 '20 at 14:24

2 Answers2

2

Chrome stores the settings for the acceptance of protocol handlers in the user profile. When running Chrome from Selenium, Chrome doesn't seem to use the standard Chrome user profile by default, and instead uses some default settings that are not persisted.

To get around this, you can launch Chrome from the command line manually and manually specify a new --user-data-dir=c:\foo\bar profile location. (Point it to a new/empty directory and Chrome will populate it for you.)

Using this manually-launched browser, navigate to the page you need to interact with, activate the link, click the "always open" checkbox, and run the program once.

Next, close Chrome and save a copy of the entire new user profile directory. When you run your Selenium tests, make sure to always pass Chrome the same command line options pointing it to that user profile. These settings are now persisted, so the link will open without user intervention in the future. (This question may be of help to feed the right command line args to Chrome.)

For repeatable tests, you will probably want to save a static copy of this profile and redeploy it whenever you launch Selenium.

Scott Dudley
  • 3,256
  • 1
  • 18
  • 30
0

If you are using Javascript+Selenium or WebdriverJS then use this :

chromeOptions = {
    'args': ['--test-type',
             '--start-maximized',
             'use-fake-ui-for-media-stream',],
    'prefs': {
        protocol_handler: {
          excluded_schemes: {
            'yourprotocolname': false
          }
        }
      },
};
Pramod
  • 768
  • 1
  • 12
  • 27