Cypress Commands
Cypress Commands
- from the terminal of visual studio code install Cypress and open it:
- create file name: spec.cy.js inside e2e folder ------------------------- to write test case inside it
- write /// <reference types="cypress"/> --------------------- to prevent describe auto-complete and write it in e2e.js file and
delete import ‘./commands’ also
- use (it) to describe and write test case: it("Test Case Name",function(){
});
user can write many it or it.only functional scripts inside the editor and save them to appear inside the runner
user can put group of test cases (it) inside one describe or context for example:
describe(‘test cases name or description’, function(){ it test cases }); or
describe(‘test cases name or description’, () =>{ it test cases}); or
context(‘test cases name or description’ , function() { it test cases}); or
context(‘test cases name or description’, () =>{ it test cases}); or
cy.log(‘to display output in the runner screen’); function written inside describe or context
before (function() { }); or before(()=>{ }); to execute something before the function
beforeEach (function() { }); or beforeEach(()=>{ }); to execute something before each function
after(function() { }); or after(()=>{ }); to execute something after executing the function
afterEach(function() { }); or afterEach(()=>{ }); to execute something after executing each function
------------------
Visit Command
------------------
Cy.visit(‘cypress/index.html’);
});
Get Element Commands:
You can return any element in the page by using get command
You can return or get or find button class or #ID into cypress first then .click() to click on the button
To run all test cases in the (browser) and (VS Code Terminal) with one command in Visual Studio Code
1- Create (spec file.cy.js) under e2e and import all test cases created previously inside this file
using this code:
1- import './1- RegisterParaBank.cy'
2- import './2- LoginAndOpenNewAccount.cy'
3- import './3- loginAndAccountOverview.cy'
4- import './4- LoginAndTransferFund.cy'
5- import './5- LoginAndBillPay.cy'
6- import './6- loginAndFindTransActions.cy'
2- write in VS code Terminal npx cypress open then choose the new spec file name to run all cases
3- In the terminal write this command and run it plus notice the result in terminal:
npx Cypress open: npx cypress run --spec .\cypress\e2e\FileName.js
To record the result as a trusted video, go to cypress.config.js write this command before e2e
1- Video:true,
2- Go to command prompt or visual studio code and write this command:
Note that: red color differs between company to another and all above commands written as is except the red
color