0

On clicking a button, I should get the location settings popup to accept/cancel the location permission, but in cypress test runner, on clicking the button, it shows permission denied.
I have checked the browser permission also, that didn't work.

Referred this:
https://github.com/kamranayub/cypress-browser-permissions/blob/master/cypress/integration/notifications.test.js

Added below permissions in cypress.json file:

"browserPermissions": {
        "notifications": "allow",
        "geolocation": "allow",
        
      }

Nothing seems to work!

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • Looks like the `browserPermssions` needs to be nested within `env` in [cypress.json](https://github.com/kamranayub/cypress-browser-permissions#in-cypressjson). Have you configured your `plugins/index.js` file properly? – jjhelguero Jun 03 '22 at 15:24
  • plugins/index.js file: const { cypressBrowserPermissionsPlugin } = require('cypress-browser-permissions') module.exports = (on, config) => { config = cypressBrowserPermissionsPlugin(on, config)return config} cypress.json : "env": { "browserPermissions": { "notifications": "allow", "geolocation": "allow" } – Yashodha RV Jun 04 '22 at 16:23
  • i have added above lines, still it dint work – Yashodha RV Jun 04 '22 at 16:24

1 Answers1

1

CAVEAT: This worked for Chrome not for Firefox, I didn't try Edge. I have no idea whether this will work for anyone else, but as it did for me after I looked at this very thread, I'll add it in.

I am using the more recent Cypress config format and I found that adding the browserPermissions object to the first level env variable inside the config didn't work. It does, however, appear to work if I instead add the configuration inside the e2e object:

const { defineConfig } = require('cypress');
const { cypressBrowserPermissionsPlugin } = require('cypress-browser-permissions');


module.exports = defineConfig({

  // ...other configs

  e2e: {
    setupNodeEvents(on, config) {
      config = cypressBrowserPermissionsPlugin(on, config);
      config.env.browserPermissions = {
        geolocation: 'allow',
      };
      return config;
    }
  }
});

NOTE: I had to stop and restart the Cypress process (restarting the browser window, as it does on save, isn't sufficient). I will also say that once I did this settings were forced and unchangeable in the browser settings page(s). So I'm not entirely sure this is how you should go about it, just that I now do not get prompted for geolocation permissions.

pj1301
  • 43
  • 1
  • 6