Answered
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.
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
}
Cypress.browser.name
returns the name of the browser Cypress is currently using (e.g. "chrome"
, "firefox"
).