Resolvi usar o faker.js e obtive alguns problemas com nomes de usuários que não podem ter acentos. Fiz um uma repetição de 10 testes para ver se surgia algum problema novo.
/// <reference types="cypress"/>
import { faker } from '@faker-js/faker';
faker.locale = 'pt_BR';
describe('Login em Alura Pic', () => {
beforeEach(() => {
cy.visit('https://alura-fotos.herokuapp.com');
});
it('Login válido', () => {
cy.login('flavio', '123');
cy.contains('a', '(Logout)').should('be.visible');
})
it('Login inválido', () => {
cy.login('Gertrudes', '1267');
cy.on('window:alert', (str) => {
expect(str).to.equal('Invalid user name or password');
});
});
for (let i = 1; i <= 10; i++) {
it(i + ' : Novo usuário logado', () => {
const randomFullName = faker.helpers.fake('{{name.firstName}} {{name.lastName}}')
const randomEmail = faker.internet.email(randomFullName);
const randomPassword = faker.internet.password(8, true)
const randomUserName = randomFullName.toLowerCase().trim().normalize('NFD').replace(/[\u0300-\u036f]/g, "").replaceAll(' ', '')
cy.novoUsuarioLogado(randomEmail, randomFullName, randomUserName, randomPassword)
cy.get('a.mr-1').should('contain.text', randomUserName)
});
};
});
gui_commands.js
/// <reference types="cypress"/>
Cypress.Commands.add('login', (nome, senha) => {
cy.get('input[formcontrolname="userName"]').type(nome)
cy.get('input[formcontrolname="password"]').type(senha)
cy.get('button[type="submit"]').click()
})
Cypress.Commands.add('novoUsuario', (email, fullName, userName, password) => {
cy.contains('p > a', 'Register now').click()
cy.get('input[formcontrolname="email"]').type(email)
cy.get('input[formcontrolname="fullName"]').type(fullName)
cy.get('input[formcontrolname="userName"]').type(userName)
cy.get('input[formcontrolname="password"]').type(password)
cy.get('small').should('contain.text', 'User available');
cy.contains('button', 'Register').should('be.visible').click({force:true});
cy.contains('ap-vmessage > small', 'User name is required!').should('be.visible')
})
Cypress.Commands.add('novoUsuarioLogado', (email, fullName, userName, password) => {
cy.contains('p > a', 'Register now').click()
cy.get('input[formcontrolname="email"]').type(email)
cy.get('input[formcontrolname="fullName"]').type(fullName)
cy.get('input[formcontrolname="userName"]').type(userName)
cy.get('input[formcontrolname="password"]').type(password)
cy.get('small').should('contain.text', 'User available');
cy.contains('button', 'Register').should('be.visible').click({force:true});
cy.contains('ap-vmessage > small', 'User name is required!').should('be.visible')
cy.get('input[formcontrolname="userName"]').should('be.visible').type(userName)
cy.get('input[formcontrolname="password"]').should('be.visible').type(password)
cy.get('button[type="submit"]').click()
})