bku*_*era 19 e2e-testing cypress
我只想切换运行一个测试,所以不必等待其他测试来查看一个测试的结果。
目前,我注释掉了其他测试,但这确实很烦人。
有没有一种方法可以切换仅运行一个测试Cypress?
bku*_*era 24
是的,您可以按照赛普拉斯文档中.only所述使用
it.only('only run this one', () => {
})
it('not this one', () => {
})
Run Code Online (Sandbox Code Playgroud)
另外,您可以对describe和context块进行相同的操作
还有一个不错的VSCode扩展,可以.only使用键盘快捷键使添加/删除操作更加轻松。它称为测试实用程序:
有多种方法可以实现这一目标。
.only到it或describe看到@bkucera答案Run Code Online (Sandbox Code Playgroud)npx cypress run --record --spec "cypress/integration/my-spec.js" npm run cypress -- --record --spec "cypress/integration/my-spec.js"
x您可以通过预先考虑测试运行程序方法调用(describe、it等)来静音不需要的测试套件和特定情况。
所以它看起来像:
// this whole testsuite will be muted
xdescribe('Visit google', () => {
it('should visit google', () => { cy.visit('https://google.com/'); });
});
// this testsuite will run
describe('Visit youtube', () => {
it('should visit youtube', () => { cy.visit('https://youtube.com/'); });
// this testcase will be muted
xit('is not necessary', () => { ... });
});
Run Code Online (Sandbox Code Playgroud)
进行此类运行的最佳方法是使用.onlycypress 提供的
要在多个描述函数中的一个描述函数中运行所有测试用例,请在所需的描述中添加 .only。
describe("1st describe", () => {
it("Should check xx", async function(){
});
it("Should check yy", async function(){
});
});
describe.only("2nd describe", () => {
it("Should check xx", async function(){
});
it("Should check yy", async function(){
});
});
describe("3rd describe", () => {
it("Should check xx", async function(){
});
it("Should check yy", async function(){
});
});
Run Code Online (Sandbox Code Playgroud)
所以这里只有第二个描述会运行。
同样,如果您想运行 1 描述中的一些测试用例,请在您要运行的所有测试用例前面添加 .only。
describe("describe statement", () => {
it("Should check xx", async function(){
});
it.only("Should check yy", async function(){
});
it.only("Should check zz", async function(){
});
});
Run Code Online (Sandbox Code Playgroud)
所以这里yy 和 zz 的 it 将运行
这类似于您可能熟悉的karma 和 jasmine 中的 fit 和 fdescribe 。
您可以使用it.skip或xit跳过 cypress 中的测试
我发现有一种方法可以跳过不需要运行的测试(在当前测试中),那就是使用:this.skip();
it('test page', function () {
// skip this test for now
this.skip();
cy.visit('http://example.com/')
cy.contains('test page').click()
cy.url()
.should('include', '/test-page/')
})
Run Code Online (Sandbox Code Playgroud)
1. 使用常规函数作为它的第二个参数很重要,这在箭头函数中不可用
2. 无论我们在哪里编写 this.skip() ,整个测试都会被跳过
小智 5
最著名的解决方案已经存在,并且只需要在控制台中添加一个简单的参数 ( --env grep="YourTestName")。
安装此插件: https://github.com/cypress-io/cypress/tree/develop/npm/grep
只需运行:
npx cypress run --env grep="YourTestName" --spec "filename"
这样,就不需要编辑您的测试文件(就像这里建议使用该.only()功能的其他答案一样)。
| 归档时间: |
|
| 查看次数: |
7781 次 |
| 最近记录: |