Code Monkey home page Code Monkey logo

cypress-javascript-end-to-end-testing's Introduction


Part 01. Introduction


Part 02. Environment setup on Windows & Mac OS

$ npm init -y
$ npm install cypress

Start cypress

$ npx cypress open

or

$ node_modules/.bin/cypress open

Part 03. How To Write & Run Tests in Cypress


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

Part 04. CSS & XPath Locators | get() & xpath() methods

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);
  });
});

Part 05. Assertions


Part 06. Folder Structure | IntelliSense Auto Suggestions


Cypress


Part 07. Interacting with Elements | Radio Buttons & Checkboxes

https://itera-qa.azurewebsites.net/ - not working right now


Part 08. Interacting with Elements | DropDowns


Part 09. Interacting with Elements | Alerts


Part 10. Interacting with Elements | Handling Child Tabs


Part 11. Interacting with Elements | Handling iFrames

$ npm install cypress-iframe

Part 12. Interacting with Elements | Handling Tables


Part 13. Interacting with Elements | Handling Mouse Events

$ npm install @4tw/cypress-drag-drop

Part 14. Interacting with Elements | Handling File Upload

$ npm install cypress-file-upload

Part 15. Hooks & Tags


Part 16. Fixtures & Data Driven Testing (Using JSON Data)


Part 17. How To Create Custom commands


Part 18. Browser Navigation | go() & reload()


Part 19. How To Capture Screenshots & Videos on Test Failures

$ npx cypress run --spec cypress/e2e/CaptureScreenshotsAndVideos.cy.js

Part 20. How To Generate HTML Reports | Headed & Headless mode execution

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

Part 21. Page Object Model Pattern in Cypress

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.