Executing in the chrome browser in cypress

In Cypress by default, the test programs execute in the electron browser. In Cypress, we can also execute the test programs in different browsers, only if you have already installed it. Cypress supports only a few browsers namely,

  • Electron
  • Chrome
  • Chromium
  • Canary.

Let us execute the programs in different browsers in the test runner and in the command line for the below code.

Example code:

describe(('My First Test suite'),
function() {
  it('My First testcase',
  function() {
    cy.visit("https://chercher.tech/");
  })
})

Execution in the test runner

By selecting the downward arrow mark, you can change the browser accordingly. Here the execution of Test.js file performed in the chrome browser.

chrome-execution-test-runner

Output: Execution in the test runner with a change in the browser.

output-chrome

In the headed and headless mode, the execution can be done in any browser via the command line.

Headless execution in cypress

Since there is a change in the browser, we have to specify the headless mode in the command line as below. --browser chrome makes the test to execute in the chrome browser.

node_modules\.bin\cypress run --headless --spec "cypress/integration/examples/Test.js"--browser chrome

[OR]

npx cypress run --headless --spec "cypress/integration/examples/Test.js"--browser chrome

Output: Execution in the headless mode with the change in the browser.

chrome-headless-command-line

Due to the change in the browser, it is not necessary to specify the term headed in the command. Even when it is specified no error occurs in the execution.

node_modules\.bin\cypress run --headed --spec "cypress/integration/examples/Test.js"--browser chrome

[OR]

node_modules\.bin\cypress run --spec "cypress/integration/examples/Test.js"--browser chrome

[OR]

npx cypress run --spec "cypress/integration/examples/Test.js"--browser chrome

[OR]

npx cypress run --headed --spec "cypress/integration/examples/Test.js"--browser chrome

Output : Execution in the headed mode with the change in the browser.

headed-chrome-commadline

Automatically browser prompts as below in the test runner,
output-chrome

Other than chrome if you wish to execute in a different browser like firefox, canary, etc.., change the command to --browser firefox ,--browser canary,etc..,

These are the basic concepts of Cypress. By having a strong foundation in the basics, it becomes easier to deal with the core concepts. From the next article, we can learn the core concepts of cypress.

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions