GithubHelp home page GithubHelp logo

project-1's Introduction

Learning Cypress

Cypress tutorial:

https://www.youtube.com/watch?v=CYcdT-tOvB0&list=PLhW3qG5bs-L9LTfxZ5LEBiM1WFfvX3dJo&index=1

Cypress Prerequisites:

Hardware:

  • Window 7 and above
  • macOS 10.9 and above (64-bit only)
  • Linux Ubuntu 12.04 and above, Fedora 21 and Debian 8 (64-bit only)

Software:

  • Node.js 10 or 12 and above

Set up project:

  • Create a new project folder for Cypress project
  • Open that folder in VS Code
  • Open VS Code terminal and run command: npm init -y
  • Install Cypress: npm install cypress
  • Check Cypress version and install it by using command: npx cypress -v
  • Open Cypress: npx cypress open

Coding instructions:

Access elements:

instruction-1

  • Red circle: use selector
  • Hover to the component that you want to get
  • Blue circle: copy the element

Implicit vs Explicit Assertions;

https://javascript.plainenglish.io/types-of-cypress-assertions-405844a5c8cf

  • Implicit assertions: should(), and()
  • Explicit assertions: expect(), assert()

Steps to make a real test:

  • visit a site: cy.visit()
  • query for an element
  • trigger an element
  • make an assertion

More information can be found here: https://docs.cypress.io/guides/getting-started/writing-your-first-test#Write-a-real-test

should: https://docs.cypress.io/api/commands/should

  • contains: check if element contains a specific text
  • have: check if element have a specific component or not. For example: have.class --> check if element have a class with name or not --> other function have.class, have.text, have.html
  • be: check status of an element. For example: with a radio button, check if it has been selected or not --> other function be.visible, be.selected, be.disabled, be.focused
  • equal: check value of an element using invoke to get the attribute based on element type (class or id)
  • and: chained assertions --> do multiple assertions at the same time

expect

  • expect(Something).to.be.true: expect a condition to be true

--> other function: to.not.equal(), to.be.a('string'), to.be.true, to.be.false, to.be.null, to.exist

  • assert--> equal or strictEqual

--> other function: isAbove, isBelow, exists, notExists,true, false, isString, isNotString

Page Object Model:

Check out file login_test.js

Show reports after doing test cases:

  • Install npm install mochawesome --save-dev
  • Install npm install mochawesome-merge --save-dev
  • Install npm install rimraf
  • Add configuration in cypress.json:
"reporter": "mochawesome",
    "reporterOptions":{
        "charts":true,
        "overwrite":false,
        "html":false,
        "json":true,
        "reportDir":"cypress/reports"
    }

The reportDir can be any folder directory as you want

  • Take a look at the package.json file where:
"pretest": "rimraf -r ./cypress/reports/*.json"

is to remove json files in folder cypress/reports

"test": "npm run cypress-test || npm run posttest",
"cypress-test": "cypress run",

is to run cypress test cases. While posttest is to create reports

"posttest": "npm run merge-reports && npm run generate-htmlreport",
"merge-reports": "mochawesome-merge cypress/reports/*.json > cypress/reports/output.json",
"generate-htmlreport": "marge cypress/reports/output.json --reportDir cypress/reports"

merge-reports is to merge multiple json files into one file. The file after > is the output file

generate-htmlreport is to create reports, videos after using the output json file

Running these commands by npm run pretest or npm run test

project-1's People

Contributors

dependabot[bot] avatar phu0n9 avatar

Watchers

 avatar

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.