Command
JavaScript Test Package Cypress Command
npm install cypress --save-dev
yarn add cypress --dev
npx cypress open
yarn run cypress open
// cypress.config.js
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
baseUrl: 'https://example.com',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
describe('run some test scenario', () => {
beforeEach(() => {
cy.visits('http://www.google.com');
});
it('visit page test', () => {
});
});
cy.get('iframe').its('0.contentDocument').then(cy.log);
let getIframe = () => {
return cy.get('iframe').its('0.contentDocument').should('not.be.empty').then(cy.wrap);
}
Cypress.Commands.add('getIframe', () => {
return cy.get('iframe').its('0.contentDocument').should('not.be.empty').then(cy.wrap);
});
cy.getIframe();
Cypress.Commands.add('enterStripeCard', (options = {}) => {
options = {
...{ approved: true },
.. options,
};
cy.getIframe().within(() => {
cy.get('[name=cardnumber]')
.type(options.approved ? '4242424242424242' : '4000000000000002')
.wait(300);
cy.get('[name=exp-date]').type('0424').wait(300);
cy.get('[name=cvc]').type('242').wait(300);
cy.get('[name=postal]').type('42424');
});
});