admin管理员组文章数量:1335438
I'm starting with Cypress and I want to add Faker to generate random values. But I'm getting following results. Could you please help me to troubleshooting that?
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');
Execution Results
TypeError: Cannot read property 'name' of undefined
Because this error occurred during a 'before all' hook we are skipping all of the remaining tests.
I'm starting with Cypress and I want to add Faker to generate random values. But I'm getting following results. Could you please help me to troubleshooting that?
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');
Execution Results
TypeError: Cannot read property 'name' of undefined
Because this error occurred during a 'before all' hook we are skipping all of the remaining tests.
Share
Improve this question
edited Jun 18, 2021 at 21:12
Richard Matsen
23.6k3 gold badges55 silver badges84 bronze badges
asked Feb 29, 2020 at 20:08
Clarissa RodriguesClarissa Rodrigues
511 silver badge2 bronze badges
1 Answer
Reset to default 5Cypress works pretty well with plain javascript, so the simplest way to get your login page working would be the following,
const faker = require('faker');
let userData = {
randomName: faker.name.findName(),
randomEmail: faker.internet.email(),
randomPassword: 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(201)
})
})
})
本文标签: javascriptUsing Faker with CypressStack Overflow
版权声明:本文标题:javascript - Using Faker with Cypress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742365675a2461201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论