我想切换为只运行一个测试,这样就不必等待其他测试才能看到一个测试的结果。
目前,我注释掉了其他测试,但这真的很烦人。
有没有办法切换到只运行一个测试在Cypress?
我想切换为只运行一个测试,这样就不必等待其他测试才能看到一个测试的结果。
目前,我注释掉了其他测试,但这真的很烦人。
有没有办法切换到只运行一个测试在Cypress?
当前回答
您可以像这样运行测试。
运行——spec **/file.js
其他回答
有多种方法可以实现这一点。
你可以添加。only到它或描述见@bkucera答案 你可以从终端做,在这里的文件解释 NPX cypress run——record——spec "cypress/integration/my-spec.js" NPM run cypress -- --record——spec "cypress/integration/my-spec.js"
通过终端运行特定文件:
npx cypress run --record --spec "cypress/integration/my-spec.js"
npm run cypress -- --record --spec "cypress/integration/my-spec.js"
我发现有一种方法可以跳过我不需要运行的测试(在当前测试中),那就是使用: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/')
})
1. 使用常规函数作为它的第二个参数是很重要的,这在箭头函数中是不可用的 2. 不管我们在哪里写这个,整个测试都会被跳过。skip()
我的测试文件有一个类似于/something.test的结构。并命令NPX cypress run——spec path/something.test。JSX在终端中给出了以下异常:
Can't run because no spec files were found.
We searched for any files matching this glob pattern:
...
令人惊讶的是,下面的工作和运行测试正好为一个文件(提供你已经安装了jest):
jest path/something.test.jsx
您可以通过在testrunner方法调用(describe, it等)前挂起x来静音不需要的测试套件和特定的用例。
所以它看起来是这样的:
// 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', () => { ... });
});