可以在公用的文件 cypress/support/index.js 中定义,
也可以在当前的文件里定义。
语法:Cypress.Commands.add('functionName',(parameter1,parameter2, ... = {} ))=> { ... })
这里我们自定义一个方法 printLog(),有2个传参title和detail
/// <reference types="Cypress" />
describe('My First Test Suite', function() {
Cypress.Commands.add('printLog', (title, detail = {}) => {
cy.log('title is '+ title+',detail:' + detail)
})
it('My First Test', function() {
cy.visit('https://cn.bing.com/')
cy.get('#office').trigger('mouseover')
cy.wait(3000)
cy.get('#office').rightclick()
cy.wait(3000)
cy.printLog('aaa','bbb')
})
})
网友评论