【问题标题】:How to clear data of a file before test run in cypress如何在赛普拉斯测试运行之前清除文件的数据
【发布时间】:2021-03-03 10:20:52
【问题描述】:

在 Cypress 中,我使用 cy.writeFile() 将页面上显示的一些数据存储在文件中。

问题是这些数据添加到文件末尾,但我不希望之前的测试运行的数据在那里。

我有什么方法可以在每次测试运行之前重新启动这些数据?

【问题讨论】:

    标签: javascript automated-tests cypress


    【解决方案1】:

    您可以随时使用beforeEach 和下面的示例清除它:

    beforeEach(() => {
      cy.writeFile('cypress/fixtures/myFile.txt', '') // clears the file before each tests
    })
    
    describe('my tests', ()=> {
      it('test 1', () => {
        cy.writeFile('cypress/fixtures/myFile.txt', 'print test 1')
      })
      it('test 2', () => {
        cy.writeFile('cypress/fixtures/myFile.txt', 'print test 2')
      })
    })
    

    【讨论】:

      猜你喜欢
      • 2020-10-26
      • 2021-09-22
      • 2020-03-15
      • 2023-02-14
      • 2020-12-03
      • 2019-12-27
      • 1970-01-01
      • 2018-06-15
      • 2019-06-07
      相关资源
      最近更新 更多