Skip to main content

Cypress.browser

Cypress.browser returns you properties of the browser.

Syntax

Cypress.browser // returns browser object

The object has the following properties:

PropertyTypeDescription
channelstringRelease channel of the browser, such as stable, dev, or canary.
displayNamestringHuman-readable display name for the browser.
familystringRendering engine being used. chromium or firefox.
isChosenbooleanWhether the browser is selected in the browser selector of the Cypress App.
majorVersionnumberThe major version number of the browser.
namestringMachine-friendly name, like chrome, electron, or firefox.
pathstringPath to the browser on disk. Blank for Electron.
versionstringFull version.
isHeadlessbooleanWhether the browser is running headlessly.
isHeadedbooleanWhether the browser displays headed.

Examples

Log browser information

Cypress.browser returns browser object

it('log browser info', () => {
console.log(Cypress.browser)
// {
// channel: 'stable',
// displayName: 'Chrome',
// family: 'chromium',
// isChosen: true,
// majorVersion: 80,
// name: 'chrome',
// path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
// version: '80.0.3987.87',
// 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', () => {
// 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 browser

Cypress.Commands.overwrite(
'screenshot',
(originalFn, subject, name, options) => {
// only take screenshots in headless browser
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 browser
cy.screenshot()

History

VersionChanges
3.0.2Cypress.browser introduced

See also