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,
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/");
})
})
By selecting the downward arrow mark, you can change the browser accordingly. Here the execution of Test.js file performed in the chrome browser.
Output: Execution in the test runner with a change in the browser.
In the headed and headless mode, the execution can be done in any browser via the command line.
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.
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.
Automatically browser prompts as below in the test runner,
--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.