我正在尝试测试几种类型的用户是否成功登录。他们中的一些人有一些不同的行为。我试图在不复制粘贴相同代码部分的情况下执行此操作,因为逐一维护它们(不同文件或案例中的每个用户类型)是疯狂的。
我有自己的测试沙箱,因此文件中的凭据不会使安全性受到攻击(我希望?)
const credentials = [
{userType: 'UserType1', login: 'UserType1Login', password: 'UserType1Password'},
{userType: 'UserType2', login: 'UserType2Login', password: 'UserType2Password'}
//6 user types and credentials for NonExistingUser and blocked
];
describe('Checks login', () => {
beforeEach('Go to Login Modal', () => {
cy.visit('/');
cy.get('[data-cy=loginModalOpen]').click();
});
// dynamically create a single test for each credential obj in the list
credentials.forEach(credential => {
it(`Checks Authorization by ${credential.userType} user`, () => {
cy.get('[data-cy=login]').type(credential.login);
cy.get('[data-cy=password]').type(credential.password);
cy.get('[data-cy=loginSubmit]').click();
if (credential.userType.includes('blocked')) …Run Code Online (Sandbox Code Playgroud)