我想切换为只运行一个测试,这样就不必等待其他测试才能看到一个测试的结果。
目前,我注释掉了其他测试,但这真的很烦人。
有没有办法切换到只运行一个测试在Cypress?
我想切换为只运行一个测试,这样就不必等待其他测试才能看到一个测试的结果。
目前,我注释掉了其他测试,但这真的很烦人。
有没有办法切换到只运行一个测试在Cypress?
当前回答
您可以像这样运行测试。
运行——spec **/file.js
其他回答
您可以像这样运行测试。
运行——spec **/file.js
你可以用这个
cypress run -- --spec 'path/to/files/*.spec.js'
or
npm run --spec 'path/to/files/*.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()
A very easy solution is to prefix your tests in with numbers, as testing frameworks will typically will run tests in alpha/numeric order by default - so if I have to check one spec file - I will copy the contents into a file 0-[file-name].spec and re-run the test command. Once the test completes - you terminate the test run - as you will have the results you were looking for. This answer is targeted at projects where your testing framework is abstracted and as a developer, you do not have all available options for your testing framework. Not the best answer, but it works and is intuitive and super easy to do. I have found this to be a way to avoid adding a bunch of conditional skips() or only() calls that will not make it to production, will have to be removed and you can easily add the file pattern to .gitignore file so these local files do not get checked in.
您可以通过在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', () => { ... });
});