AWS Amplify has announced Cypress as their tool of choice for adding end-to-end testing for the Amplify Console!

Learn More

Cypress.browser

Improve this doc

Cypress.browser returns you properties of the browser.

Syntax

Cypress.browser // returns browser object

Examples

Log browser information

Cypress.browser returns browser object

it('log browser info', function() {
  console.log(Cypress.browser)
  // {
  //   name: 'chrome',
  //   displayName: 'Chrome',
  //   version: '67.123.456.90',
  //   majorVersion: '67',
  //   path: '/path/to/browser',
  //   isHeaded: true,
  //   isHeadless: false
  // }
})

Conditionals

Check that Chrome specific styles are applied

@media and (-webkit-min-device-pixel-ratio:0) {
  .header {
    margin-right: 0;
  }
}
it('has correct Chrome specific css property', function () {
  // if in Chrome, check css property was properly applied
  if (Cypress.browser.name === 'chrome') {
    cy
    .get('.header')
    .should('have.css', 'margin-right')
    .and('eq', '0')
  }
})

Screenshot only in headless environment

Cypress.Commands.overwrite('screenshot', (originalFn, subject, name, options) => {
  // only take screenshots in headless environment
  if (Cypress.browser.isHeadless) {
    // return the original screenshot function
    return originalFn(subject, name, options)
  }

  return cy.log('No screenshot taken when headed')
})

// only takes in headless environment
cy.screenshot()

History

Version Changes
3.0.2 Cypress.browser introduced

See also