Cypress Tutorial
First Test In Cypress
How To Write First Test In Cypress ?
In Cypress, we refer test file as 'spec file' and spec files are saved with '.cy.js' extension. E.g. example.cy.js
To write a cypress test, here are some basic requirements and steps to be followed :
Prerequisites :
=> Familiar to JavaScript programming.
=> Install and setup Cypress => Follow Guide
Steps to write a Cypress test :
Open VS code(or any other editor).
Navigate to the project folder(CypressAutomation), where you have done setup for Cypress.
Under this project folder, create a new spec file named 'FirstSpec.cy.js' inside the directory cypress/e2e.
As Cypress is oriented on Mocha framework so, test will be written in 'describe() and it()' pattern.
In the first line describe your test suite. => describe('First Spec', function() {} )
Next define your test.
* To navigate through an url cypress has a function cy.visit("write url here") .
it('run', function() {
cy.visit('https://www.myautomationhub.com/')
})
Spec file will look like this :
To run the spec file, open terminal -
Run command : npx cypress open
And, then run command : npx cypress run --spec "cypress/e2e/FirstSpec.cy.js"
The displayed output would be :
Recorded video output :
To disable video recording, run command : npx cypress run --config video=false --spec "cypress/e2e/FirstSpec.cy.js"