如何在 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.