English 中文(简体)
Cypress - Hooks
  • 时间:2024-03-24 09:03:26

Cypress - Hooks

Previous Page Next Page  

台风Hooks用于在每次/每次检测之前进行某些操作。 其中一些共同点如下:

    before − It is executed, once the prior execution of any tests within a describe block is carried out.

    after − It is executed, once the post execution of all the tests within a describe block is carried out.

    beforeEach − It is executed prior to the execution of an inspanidual, it blocks within a describe block.

    afterEach − It is executed post execution of the inspanidual, it blocks within a describe block.

Implementation

The implementation of directs for the Cypress Hooks is below -


describe( Tutorialspoint , function() {
   before(function() {
      // executes once prior all tests in it block
      cy.log("Before hook")
   })
   after(function() {
      // executes once post all tests in it block
      cy.log("After hook")
   })
   beforeEach(function() {
      // executes prior each test within it block
      cy.log("BeforeEach hook")
   })
   afterEach(function() {
      // executes post each test within it block
      cy.log("AfterEac hook")
   })
   it( First Test , function() {
      cy.log("First Test")
   })
   it( Second Test , function() {
      cy.log("Second Test")
   })
})

产出如下:

Cypress Hooks

产出记录显示,第一个执行步骤是“一切照旧”。

最后一个执行步骤是AFTER ALL。 两人只住过一次。

The step executed under BEFORE EACH ran twice (before each TEST BODY).

此外,根据AFTER EACH执行的两步行动(在每一技术设备之后)。

两个区块均按执行顺序执行。

TAG

除hoo外,Cypress还有tag子——只有和.skip。

虽然只有tag子被利用去执行它被拖到的路障,但情况并非如此。 ski门被利用,排除了被拖到哪块。

Implementation with .only

The implementation of . only tag in Cypress is as follows -


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")
   })
})

产出如下:

Cypress Has Tags

产出记录显示,只有标的区块(第一次和第二次试验)只有行标。

Implementation with .skip

The implementation of .skip tag in Cypress is as follows -


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")
   })
})

产出如下:

Cypress Skip Tags

产出记录显示,与ski子的 block块(第三次测试)从执行中跳出。

Advertisements