$ npm init -y
$ npm install cypress
Start cypress
$ npx cypress open
or
$ node_modules/.bin/cypress open
describe('My First Test', () => {
it('verify title-positive', () => {
cy.visit('https://opensource-demo.orangehrmlive.com/');
cy.title().should('eq', 'OrangeHRM');
});
it('verify title-negative', () => {
cy.visit('https://opensource-demo.orangehrmlive.com/');
cy.title().should('eq', 'OrangeHRM123');
});
});
$ node_modules/.bin/cypress run
$ node_modules/.bin/cypress run --headed
$ node_modules/.bin/cypress run --headless
$ node_modules/.bin/cypress run --spec cypress/e2e/MyFirstTest.cy.js
$ node_modules/.bin/cypress run --browser chrome
$ node_modules/.bin/cypress run --browser chrome --headed
http://automationpractice.com/ - not working right now
https://chrome.google.com/webstore/detail/selectorshub/ndgimibanhlabgdgjcpbbndiehljcpfh
$ npm install -D cypress-xpath
cypress/support/commands.js
/// <reference types"Cypress" />
/// <reference types"cypress-xpath" />
cypress/support/e2e.js
require('cypress-xpath')
CSSLocators.cy.js
describe('CSSLocators', () => {
it('csslocators', () => {
cy.visit('https://automationpractice.com/index.php');
// cy.get('#search_query_top').type('T-Shirts');
// cy.get('.search_query_top').type('T-Shirts');
// cy.get("[name='search_query']").type('T-Shirts');
cy.get("input.search_query_top[name='search_query']").type('T-Shirts');
cy.get("[name='submit_searh']").click();
cy.get('.lighter').contains('T-Shirts');
});
});
XPathLocators.cy.js
describe('XPathLocators', () => {
it('find no of products', () => {
cy.visit('https://automationpractice.com/index.php');
cy.xpath("//ui[@id='homefeatured']/li").should('have.length', 7);
});
it('chained xpath', () => {
cy.visit('https://automationpractice.com/index.php');
cy.xpath("//ui[@id='homefeatured']").xpath('./li').should('have.length', 7);
});
});
https://itera-qa.azurewebsites.net/ - not working right now
$ npm install cypress-iframe
$ npm install @4tw/cypress-drag-drop
$ npm install cypress-file-upload
$ npx cypress run --spec cypress/e2e/CaptureScreenshotsAndVideos.cy.js
https://www.npmjs.com/package/cypress-mochawesome-reporter
$ npm install cypress-mochawesome-reporter
cypress.config.js
const { defineConfig } = require('cypress');
module.exports = defineConfig({
reporter: 'cypress-mochawesome-reporter',
e2e: {
setupNodeEvents(on, config) {
require('cypress-mochawesome-reporter/plugin')(on);
},
},
});
cypress/support/e2e.js
import 'cypress-mochawesome-reporter/register';
$ npx cypress run --spec cypress/e2e/MyFirstTest.cy.js
$ npx cypress run --spec cypress/e2e/MyFirstTest.cy.js --browser chrome
$ npx cypress run --headed --spec cypress/e2e/MyFirstTest.cy.js --browser chrome