【发布时间】:2020-06-13 14:06:25
【问题描述】:
我从 Cypress 开始,我想添加 Faker 来生成随机值。但我得到以下结果。你能帮我解决这个问题吗?
login_page.js
const faker = require('faker');
before(() => {
let userData = {
randomName: cy.faker.name.findName(),
randomEmail: cy.faker.internet.email(),
randomPassword: cy.faker.random.number()
}
}
describe('Create new user', function () {
it('Create new user via API', function () {
cy.request('POST', '/cadastrarUsuario', {
nome: userData.randomName,
email: userData.randomEmail,
senha: userData.randomPassword
})
.then((resp) => {
expect(resp.status).to.eq(200)
})
})
})
describe('Login with user just created', function () {
it('Login with user just created via API', function () {
cy.request('POST', '/logar', {
email: userData.randomEmail,
senha: userData.randomPassword
})
.then((resp) => {
expect(resp.status).to.eq(200)
})
})
})
index.js
cy.faker = require('faker');
执行结果
TypeError: Cannot read property 'name' of undefined
Because this error occurred during a 'before all' hook we are skipping all of the remaining tests.
【问题讨论】:
标签: javascript cypress faker