cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

Disable the "save address" popup in Chrome #25608

Open magnattic opened 1 year ago

magnattic commented 1 year ago

What would you like?

When my tests fills out an address form with Chrome as the browser, the following prompt pops up: image

It would be great if this could be disabled altogether for cypress.

Why is this needed?

It overlaps the test window and has to be closed manually each time.

Other

During my google search, I found different ways this could be implemented:

Not sure if any of those actually work, but might be worth a try.

yktoo commented 1 year ago

We're also bumping into this stupid popup that prevents a page element from being clicked.

nagash77 commented 1 year ago

Hi @magnattic , that does seem annoying! To be totally transparent, I don't see this issue being prioritized ahead of the extensive backlog. However we would definitely welcome external contributions that address this issue.

anhtester commented 1 year ago

Until now I still haven't found a solution 🥲

sjmog commented 11 months ago

Same issue here, but with the "Save credit card" popup in Chrome.

anhtester commented 11 months ago

Now, I found this to work in Selenium Java.

ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); prefs.put("autofill.profile_enabled", false); options.setExperimentalOption("prefs", prefs);

WebDriver driver = new ChromeDriver(options);

sigerello commented 5 months ago

This solves the issue for me:

// cypress.config.ts

import {defineConfig} from 'cypress'

export default defineConfig({
  e2e: {
    baseUrl: 'http://localhost:8080',
    setupNodeEvents(on, config) {
      // prettier-ignore
      on('before:browser:launch', (browser, launchOptions) => {
        if (browser.family === 'chromium' && browser.name !== 'electron') {
          // Disable Chrome's "Save address?" pop up
          launchOptions.preferences.default.autofill.profile_enabled = false

          // Disable Chrome's "Save password?" pop up
          launchOptions.preferences.default.credentials_enable_service = false
          launchOptions.preferences.default.profile.password_manager_enabled = false

          // Disable Chrome's "Save card?" pop up
          launchOptions.preferences.default.autofill.credit_card_enabled = false

          // Disable Chrome's "Show downloads when they're done" option
          launchOptions.preferences.default.download_bubble.partial_view_enabled = false

          return launchOptions
        }
      })

      return config
    },
  },
})

Would be great if Cypress applies these options by default.

But be careful! It seems chrome properties are cached. Try to comment out these modifications and console.log(launchOptions.preferences.default) – you will see these options are still applied. I tried cypress cache clear command and also re-install Chrome, but nothing helped. Maybe someone can suggest how to clear this cache?

AlexSdet commented 4 months ago

@sigerello Im trying your solution (copy paste), but getting error right away:

Cannot set properties of undefined (setting 'profile_enabled')
TypeError: Cannot set properties of undefined (setting 'profile_enabled')

Any ideas what Im missing ?

sigerello commented 4 months ago

@AlexSdet, it seems launchOptions.preferences.default.autofill is undefined in your case, while it should be an object. Have no idea why.

Try optionally initialize it:

launchOptions.preferences.default.autofill ??= {}
launchOptions.preferences.default.autofill.profile_enabled = false

Same for launchOptions.preferences.default.profile and launchOptions.preferences.default.download_bubble in case you will face into the similar issue for these properties.