美文网首页
Cypress 自定义命令

Cypress 自定义命令

作者: BestFei | 来源:发表于2020-06-08 11:39 被阅读0次

可以在公用的文件 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')
    })
})

相关文章

网友评论

      本文标题:Cypress 自定义命令

      本文链接:https://www.haomeiwen.com/subject/vfmbzhtx.html