如何在 Cypress 中实现标签?


我们可以在 Cypress 中实现标签。Cypress 有两个标签 - .only 和 .skip。.only 标签用于执行带有该标签的 it 块,.skip 标签用于排除带有该标签的 it 块。

示例

.only 实现

describe('Tutorialspoint', function()

   //it block with tag .only
   it.only('First Test', function() {
      cy.log("First Test")
   })

   //it block with tag .only
   It.only('Second Test', function() {
      cy.log("Second Test")
   })
   it('Third Test', function() {
      cy.log("Third Test")
   })
})

执行结果

输出日志显示,带有 .only 标签的 it 块(第一个和第二个测试)得到了执行。

示例

.skip 实现

describe('Tutorialspoint', function()
   it('First Test', function() {
      cy.log("First Test")
   })
   it('Second Test', function() {
      cy.log("Second Test")
   })

   //it block with tag .skip
   it.skip('Third Test', function() {
      cy.log("Third Test")
   })
})

执行结果

输出日志显示,带有 .skip 标签的 it 块(第三个测试)被跳过了,没有执行。

更新时间: 2021 年 11 月 19 日

835 次浏览

开启你的 事业

完成课程获得认证

开始学习
广告
© . All rights reserved.