'How to enable browser notifications using Cypress
I am using Cypress for e2e testing and the site I am testing requires to have the notification permission granted. For manual testing, I go to chrome preferences->Privacy and Security->Site Settings->Notifications and set the site url to 'Allow'
But how do I do this on Cypress ?
Solution 1:[1]
To do this on Cypress you need the index.html and then you can do this first test to confirm that the browser support notifications:
/// <reference types="Cypress" />
describe('Browser notifications', () => {
it('are supported by the test browser', () => {
cy.visit('index.html')
cy.window().should('have.property', 'Notification').should('be.a', 'function')
})
})
If you enable notifications from Cypress itself, you will see a popup if you click "Notify me!" button. The rest of the tests stubs Notification constructor to avoid popups
Solution 2:[2]
You can use the cypress-browser-permissions plugin.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | camilla stevani |
| Solution 2 | thisismydesign |
