我想切换为只运行一个测试,这样就不必等待其他测试才能看到一个测试的结果。
目前,我注释掉了其他测试,但这真的很烦人。
有没有办法切换到只运行一个测试在Cypress?
我想切换为只运行一个测试,这样就不必等待其他测试才能看到一个测试的结果。
目前,我注释掉了其他测试,但这真的很烦人。
有没有办法切换到只运行一个测试在Cypress?
当前回答
执行此类运行的最佳方法是使用cypress提供的.only关键字。
要在一个描述函数中运行来自多个描述函数的所有测试用例,请在所需的描述中添加.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(){
});
});
所以这里只有第二个描述会运行。
类似地,如果你想在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(){
});
});
这里,yy和zz的it会运行
这类似于你可能熟悉的因果报应和茉莉花中的契合。
你可以用它跳过柏树的测试。跳过或退出
其他回答
执行此类运行的最佳方法是使用cypress提供的.only关键字。
要在一个描述函数中运行来自多个描述函数的所有测试用例,请在所需的描述中添加.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(){
});
});
所以这里只有第二个描述会运行。
类似地,如果你想在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(){
});
});
这里,yy和zz的it会运行
这类似于你可能熟悉的因果报应和茉莉花中的契合。
你可以用它跳过柏树的测试。跳过或退出
您可以通过在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', () => { ... });
});
最著名的解决方案已经存在,只需要在控制台中添加一个简单的参数。 https://github.com/cypress-io/cypress/tree/develop/npm/grep
简单地运行: npx cypress run——env grep="TestName"——spec "filename"
Cypress .only()函数仅用于开发。
你可以用这个
cypress run -- --spec 'path/to/files/*.spec.js'
or
npm run --spec 'path/to/files/*.spec.js'
这对我很管用。
非常感谢
有多种方法可以实现这一点。
你可以添加。only到它或描述见@bkucera答案 你可以从终端做,在这里的文件解释 NPX cypress run——record——spec "cypress/integration/my-spec.js" NPM run cypress -- --record——spec "cypress/integration/my-spec.js"