.skip() 和 .only() 的使用

.skip() 和 .only() 的使用

说明
  • 在做自动化测试中,跳过执行 某些测试用例,或只运行某些指定的测试用例,这种情况是很常见的
  • Cypress中也提供了这种功能
如何跳过测试用例

通过describe.skip() 或者 context.skip() 来跳过不需要执行的测试套件

复制代码
describe('ship test',()=>{
    describe.skip('跳过该测试套件',()=>{
        it('测试1',()=>{
            cy.log('测试用例1被执行');
        })
    })
})

通过 it.skip() 来跳过不需要执行的测试用例

typescript 复制代码
it.skip('测试用例2',()=>{
        cy.log('测试用例2');
});
指定执行测试套件或测试用例

当存在 .only() 指定某个测试套件或测试用例时,只有这个测试套件或测试用例会被执行 ,其他未加 .only() 的测试套件或测试用例都不会执行

通过 describe.only() 或者 context.only()来指定需要执行的测试套件

测试代码
typescript 复制代码
describe('only suite',()=>{
    context('suite1',()=>{
        it('case1',()=>{
            cy.log('case1');
        })
        it('case2',()=>{
            cy.log('case2');
        })
    })

    context.only('suite2',()=>{
        it('case3',()=>{
            cy.log('case3');
        })
        it('case4',()=>{
            cy.log('case4');
        })
    })

    context('suite3',()=>{
        it('case5',()=>{
            cy.log('case5');
        })
        it('case6',()=>{
            cy.log('case6');
        })
    })
})

通过 it.only() 来指定需要执行的测试用例

typescript 复制代码
describe('only suite',()=>{
    it.only('only case1',()=>{
        cy.log('case1');
    })

    it.only('only case2',()=>{
        cy.log('case2');
    })

    it('case3',()=>{
        cy.log('case3');
    })
})
相关推荐
程序员杰哥2 天前
Pytest之收集用例规则与运行指定用例
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
程序员小远4 天前
使用Jmeter进行http接口测试
自动化测试·软件测试·python·测试工具·jmeter·http·接口测试
程序员杰哥5 天前
如何使用Postman做接口自动化测试及完美的可视化报告?
自动化测试·软件测试·python·测试工具·jenkins·postman·1024程序员节
IAMeee6 天前
从项目中学习CAN和CANFD报文结构(新手入门)
自动化测试·can·uds·canfd·1024程序员节
软件测试小仙女6 天前
AI驱动的测试:Cypress的cy.prompt功能实践
自动化测试·软件测试·人工智能·测试工具·cypress·ai测试·测试计划