Get the name of the current browser being used in Cypress?

Answered
looper003 asked this question 10 months ago
looper003 on Mar 14, 2022

In my Cypress tests for my JavaScript application, how can I get the name of the current browser Cypress is using to run the tests?

Using that name, I want to something like this:

if (chrome) {
  // run specific test
}

Where I can run specific tests for a certain browser environment.

2 suggested answers
itsbambi on May 7, 2022

Your looking for the Cypress.browser object.

In that object is a name property that returns a "firefox", "chrome", "electron", or "edge" browser name string.

Cypress.browser.name

If you wanted to only run a test in Chrome, you could do this:

if (Cypress.browser.name === "chrome") {
  // run specific test
}
0 replies
moon_man41 on May 7, 2022

Cypress.browser.name returns the name of the browser Cypress is currently using (e.g. "chrome", "firefox").

0 replies
Answered