【问题标题】:How are tests organised in cypresscypress 中的测试是如何组织的
【发布时间】:2019-06-20 06:29:16
【问题描述】:

我们目前正在考虑从 selenium 交换到 cypress 以进行我们的自动化端到端测试,因为它看起来好像可以阻止一些由 selenium 引起的等待问题。

由于登录时间可能需要一段时间,我们在 NUnit 中的测试类开始时使用 [OneTimeSetUp] 来进行初始登录,然后我们从那里运行测试。

所以我的问题是 cypress 中的测试是如何组织的?我们可以在同一个实例上运行多个测试吗?

【问题讨论】:

    标签: automated-tests cypress


    【解决方案1】:

    赛普拉斯使用 mocha 作为测试结构。

    describe() 块在 mocha 中对测试进行分组。

    it() 块告诉这是一个测试。

    例如

      describe('Login Functionality', function() {
    
          it('Check Login with Correct Credentials', function() {
               //Your code
          })
    
         it('Check Login with Incorrect Username', function() {
               //Your code
          })
    
          it('Check Login with Incorrect Password', function() {
               //Your code
          })
    
    
        })
    
    

    【讨论】:

      【解决方案2】:

      您需要的一切都在官方文档中: https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Hooks

      享受赛普拉斯!

      示例:

        beforeEach(function () {
          cy.visit('/users/new')
          cy.get('#first').type('Johnny')
          cy.get('#last').type('Appleseed')
        })
      
        it('displays form validation', function () {
          cy.get('#first').clear() // clear out first name
          cy.get('form').submit()
          cy.get('#errors').should('contain', 'First name is required')
        })
      
        it('can submit a valid form', function () {
          cy.get('form').submit()
        })
      })
      

      【讨论】:

      • 另外,它听起来有点像 RTFM,只是形式更礼貌一些。
      猜你喜欢
      • 2022-06-29
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多