javascript - 如何在 Cypress 中运行 beforeEach?
问题描述
我目前正在构建一个测试,似乎在第二次和第三次测试之后, 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 语句下传递任何其他函数,或者是否需要进行不同的设置。
我应该如何使用 beforeEach?该文件以前可以工作,但由于某种原因开始失败。您能否提一些建议?
解决方案
错误消息cy.type() 只能接受字符串或数字。你传入: undefined表示路径的最后一部分是undefined
,例如 this.data。fullName或 this.info.userGoodCredit。公司。
如果this.data
未定义,您的错误将是无法获取 undefined 的属性“fullName”,因此您的 beforeEach() 可能没问题。
看起来测试中使用的属性或夹具对象中存在拼写错误。用console.log(this.info.userGoodCredit)
和检查console.log(this.data)
。
推荐阅读
- c++ - 向量加法 CUDA
- jquery - 将鼠标悬停在 html 文章上并更改另一个 div 的背景
- javascript - 将 Powershell GUI 中的多个标签和文本框输入复制到剪贴板以进行粘贴
- jquery - 上传前如何取消选中的文件?
- python - 为什么 await 需要这么多次?
- php - 使用 Imagick 压缩的图像未通过 PageSpeed 测试
- javascript - 如何根据 $group 对多个字段进行 $count 和 $total
- f# - 如何从 GetPixelSpan 提取、向上转换和处理字节数组,然后保存回文件?
- c# - 获取标头“setcookie”并将其转换为 Cookie 对象
- r - 在 QT 中编译 RInside 时无法打开基础包