Codeception: Tell Chrome to automatically accept desktop notifications

September 1st, 2016

Set up Chrome environments in Codeception to allow Web Notifications.

If you're building a site that makes use of the handy Web Notifications API and want to test it in Codeception, you might want to tell your browser to enable notifications for the site. I had to fiddle a bit before getting this right, so hopefully it'll help somebody. In your xxx-acceptance.suite.yml, here are a couple of flags:

class_name: AcceptanceTester
modules:
  enabled:
    - Asserts
    - WebDriver:
      url: '/'
      browser: chrome
      restart: true
      capabilities:
      # Accept any JS alert boxes by default
        unexpectedAlertBehaviour: 'accept'
        chromeOptions:
          args:
            - 'enable-strict-powerful-feature-restrictions'
            - 'window-size=1440,900'
            - 'window-position=0,0'
          prefs:
            # Automatically accept desktop notifications
            'profile.managed_default_content_settings.notifications': 1

codeception

testing

automation

PHP