Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/prashantsinght99/cypress


https://github.com/prashantsinght99/cypress

cypress javascript mocha

Last synced: 3 days ago
JSON representation

Awesome Lists containing this project

README

        

npx cypress open : GUI MODE

npx cypress run : RUN ALL TESTS FROM TERMINAL IN HEADLESS MODE

npx cypress run --headed : RUN ALL TESTS FROM TERMINAL IN HEAD MODE (DEFAULT BROWSER ELECTRON)

npx cypress run --browser=chrome : RUN ALL TESTS FROM TERMINAL IN HEAD MODE (BY SETTING BROWSER)

npx cypress run --spec cypress\e2e\my.test.cy.js : RUN SPECIFIC TESTCASE

npx cypress run --config baseUrl=""

cypress run --env "token"="abc"

LOCATORS

ID

tag#id

tag.class

tag[attribute:"value"]

tag.class[attribute:"value"]

XPATH:

npm install -D cypress-xpath

commands.js

///

///

e2e.js

require('cypress-xpath');

cy.get("css locator")
cy.xpath

implicit explicit assertions

https://docs.cypress.io/guides/references/assertions

ALERTS

WINDOW:ALERT VALIDATION OF ALERT
WINDOW:CONFIRM: CLICKING ON CONFIRM
WINDOW:ALERT: CLICKING ON CANCEL
WINDOW:PROMPT: ENTER TEXT IN ALERT BY CAPTURING IT EARLIER
AUTHENTICATION USING URL/ AUTH OBJECT

FRAMES

HOW TO GET FRAME AND DOCUMENT WITHIN IT AND WRAP IT TO PERFORM ACTIONS
HOW TO CREATE A CUSTOM COMMAND
HOW TO USE PLUGIN IN FRAMES

MOUSE OPERATIONS:

MOUSE HOVER
DOUBLE CLICK
RIGHT CLICK
DRAG DROP
SCROLL TO A ELEMENT

FILE UPLOAD:

HOW TO UPLOAD SINGLE FILE
HOW TO UPLOAD MULTIPLE FILE
HOW TO RENAME A FILE
HOW TO DRAG DROP A FILE UPLOAD
HOW TO UPLOAD FILE SHADOW DOM

IMPORTANT PLUGINS:

CYPRESS XPATH PLUGIN: cypress-xpath
FILE UPLOAD PLUGIN: cypress-file-upload
DRAG AND DROP PLUGIN: cypress-drag-drop
IFRAME PLUGIN: cypress-iframe

NAVIGATION:

cy.go("forward") or cy.go(1)
cy.go('back) or cy.go(-1)

SCREENSHOT CAPTURING

screenshot() or via terminal run command videos and screenshot gets captured add video: true, in cypress.config.js

PERSERVE COOKIES

cy.getCookies()
cy.setCookie()
cy.clearCookies()
cy.clearLocalStorage()

Cypress.Cookies.preserveOnce("sessionId","remember_");

IMPLICIT ASSERTIONS

.should("have.length", 5)
.should("be.visible");
.should("exist");
.should("include", "PrashantSingh").and("not.contain", "pst99")
.should("include", "PrashantSingh");
.should("contains", "prashantsinght99");
.should("eq", "https://prashantsinght99.github.io/PrashantSingh.github.io/");
.should("have.value", "prashant");
.should("have.text", "You successfully clicked an alert");
.should("have.contain", "Congratulations");

.uncheck().should("not.be.checked")
.check().should("be.checked")
.check({ force: true }).should("be.checked");

EXPLICIT ASSERTIONS

cy.get('.name > h1').then((element) => {
let actualname = element.text();
expect(expectedname).to.equal(actualname);
expect(expectedname).to.not.equal(notexpectedname);
assert.equal(actualname, expectedname);
assert.notEqual(actualname, notexpectedname);
expect(element).to.contains("I am a JS Alert");
})

Direct

should('eq','')
should('contain','')
should('include','')

should('be.visible')
should('be.checked')
should('exist')
should('be.disabled')
should('be.focused')

should('have.length')
should('have.value')
should('have.text')
should('have.contain')