繁体   English   中英

如何在 Cypress 中运行 beforeEach?

[英]How do I run a beforeEach in Cypress?

我目前正在构建一个测试,似乎在第二次和第三次测试之后,beforeEach 没有得到我需要的信息,并告诉我我遇到了以下问题:

cy.type() can only accept a string or number. You passed in: undefinedLearn more

我的文件如下:


describe('Test all', function () {

    beforeEach(() => {
        cy.fixture('onlineApp.json').then(function (data) {
            this.data = data
        })

        cy.fixture('onlineAppUsers.json').then(function (info) {
            this.info = info
        })

    })


    // Getting into the site to start testing

    it('Build remodel ', function () {

        // Get into the producs page
        Cypress.config().baseUrl
        cy.visit(Cypress.env('url_products'))

        cy.buildRemodel()
        cy.onlineappCreateProfileForm()
        cy.businessInfo()
        cy.logOut()

    })

    it('Buy a Business', function () {

        // Get into the login page
        Cypress.config().baseUrl
        cy.visit(Cypress.env('url_login'))

        // Login | Use the information from the Fixture file created at the time that we create an account

        cy.get('#email').type(this.data.email)
        cy.get('#password').type('Abcd1234')
        cy.get('.app-submit-btn-text').should('be.visible').click()

        // Start a new Application

        cy.get(':nth-child(2) > .small-text > a').should('be.visible').click()

        // Start Loan Application

        cy.buyBusiness()

        // Fill out form

        cy.get('#full_name').type(this.info.userGoodCredit.name)
        cy.get('#company').type(this.info.userGoodCredit.company)
        cy.get('#phone_number').type(this.info.userGoodCredit.phone)
        cy.get('#email')
        cy.wait(10000)
        cy.get('.app-submit-btn-text', { delay: 100 }).should('be.visible').click()
        cy.businessInfo()
        cy.logOut()


    })

    it('Expand a Business', function () {
        // Get into the login page
        Cypress.config().baseUrl
        cy.visit(Cypress.env('url_login'))

        // Login | Use the information from the Fixture file created at the time that we create an account

        cy.get('#email').type(this.data.email)
        cy.get('#password').type('Abcd1234')
        cy.get('.app-submit-btn-text', { time: 100000 }).should('be.visible').click()

        // Start a new Application

        cy.get(':nth-child(2) > .small-text > a').should('be.visible').click()

        // Start Loan Application

        cy.expandBusiness()

        // Fill out form

        cy.get('#full_name').type(this.data.fullName)
        cy.get('#company').type(this.info.userGoodCredit.company)
        cy.get('#phone_number').type(this.info.userGoodCredit.phone)
        

    })
    
  })

我的问题在扩展业务测试之后开始。 我不知道是否必须在 beforeEach 语句下传递任何其他 function 或者是否需要进行不同的设置。

我应该如何使用 beforeEach? 该文件以前可以工作,但由于某种原因开始失败。 您能否提一些建议?

错误消息cy.type() 只能接受字符串或数字。 你传入: undefined表示路径的最后一部分是undefined ,例如 this.data。 fullName或 this.info.userGoodCredit。 公司

如果this.data未定义,您的错误将是cannot get property "fullName" of undefined ,因此您的 beforeEach() 可能没问题。

看起来测试中使用的属性或夹具 object 中存在拼写错误。 检查console.log(this.info.userGoodCredit)console.log(this.data)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM