gpt4 book ai didi

javascript - Cypress :运行所有规范,但创建一个没有运行规范的循环

转载 作者:行者123 更新时间:2023-11-28 21:35:18 27 4
gpt4 key购买 nike

我的 Cypress.io 有问题,这是我的问题:

我这里有 4 个不同的测试文件:

integration/socle_full_ts_dev/1_register_user.spec.js

/// <reference types="cypress" />
import { first, last } from 'random-name';

describe('Validate register in Socle-Full-JS DEV', () => {
xit('Register ramdom user on Socle', () => {
cy.visit(Cypress.env('HERUKU_URL') + 'auth/register');
setTypeInRegisterForm(false)
cy.wait(1000);
cy.get('.register-form-button').click();
cy.wait(3000);
cy.url().should('eq', Cypress.env('HERUKU_URL') + 'showcase/app/home');
});

xit('Register ramdom user on Socle with button enter', () => {
cy.visit(Cypress.env('HERUKU_URL') + 'auth/register');
setTypeInRegisterForm(true);
cy.wait(3000);
cy.url().should('eq', Cypress.env('HERUKU_URL') + 'showcase/app/home');
});

xit('Validated register first user', () => {
cy.visit(Cypress.env('MAIL_URL'));
setTypeInEtherealForm();
cy.get('tbody > :nth-child(1) > :nth-child(2) > a').click();
clickLinkInEmail();
cy.wait(3000);
cy.url().should('eq', Cypress.env('HERUKU_URL') + 'showcase/app/home');
});

xit('Validated register second user', () => {
cy.visit(Cypress.env('MAIL_URL'));
setTypeInEtherealForm();
cy.get(':nth-child(2) > :nth-child(2) > a').click();
clickLinkInEmail();
cy.wait(3000);
cy.url().should('eq', Cypress.env('HERUKU_URL') + 'showcase/app/home');
});
});

const setTypeInRegisterForm = (isEnter) => {
const firstName = first();
const lastName = last();
const email = firstName + '.' + lastName + '@example.fr';
cy.writeFile('cypress/fixtures/register_user.json', {
firstName,
lastName,
email
});
cy.get('#FIRST_NAME').type(firstName);
cy.get('#LAST_NAME').type(lastName);
cy.get('#EMAIL').type(email);
cy.get('#PASSWORD').type('toto');
cy.get('#PASSWORD_CONFIRM').type('toto');
if (isEnter) {
cy.get('#ORGANIZATION_NAME').type('Needone{enter}');
} else {
cy.get('#ORGANIZATION_NAME').type('Needone');
}
}

const setTypeInEtherealForm = () => {
cy.get('#address').type('toto.toto@ethereal.email');
cy.get('#password').type('LALALLA{enter}');
cy.get(':nth-child(4) > .nav-link').click();
}

const clickLinkInEmail = () => {
cy.get('iframe').then((iframe) => {
const body = iframe.contents().find('body');
cy.wrap(body).find('a').click();
});
}

integration/socle_full_ts_local/1_register_user_local.spec.js

/// <reference types="cypress" />
import { first, last } from 'random-name';

describe('Validate register in Socle-Full-JS LOCAL', () => {
it('Register ramdom user on Socle', () => {
cy.visit(Cypress.env('LOCAL_URL') + 'auth/register');
setTypeInRegisterForm(false)
cy.wait(1000);
cy.get('.register-form-button').click();
cy.wait(3000);
cy.url().should('eq', Cypress.env('LOCAL_URL') + 'showcase/app/home');
});

it('Register ramdom user on Socle with button enter', () => {
cy.visit(Cypress.env('LOCAL_URL') + 'auth/register');
setTypeInRegisterForm(true);
cy.wait(3000);
cy.url().should('eq', Cypress.env('LOCAL_URL') + 'showcase/app/home');
});

it('Validated register first user', () => {
cy.visit(Cypress.env('MAIL_URL'));
setTypeInEtherealForm();
cy.get('tbody > :nth-child(1) > :nth-child(2) > a').click();
clickLinkInEmail();
cy.wait(3000);
cy.url().should('eq', Cypress.env('LOCAL_URL') + 'showcase/app/home');
});

it('Validated register second user', () => {
cy.visit(Cypress.env('MAIL_URL'));
setTypeInEtherealForm();
cy.get(':nth-child(2) > :nth-child(2) > a').click();
clickLinkInEmail();
cy.wait(3000);
cy.url().should('eq', Cypress.env('LOCAL_URL') + 'showcase/app/home');
});
});

const setTypeInRegisterForm = (isEnter) => {
const firstName = first();
const lastName = last();
const email = firstName + '.' + lastName + '@example.fr';
cy.writeFile('cypress/fixtures/register_user.json', {
firstName,
lastName,
email,
password: 'password'
});
cy.get('#FIRST_NAME').type(firstName);
cy.get('#LAST_NAME').type(lastName);
cy.get('#EMAIL').type(email);
cy.get('#PASSWORD').type('password');
cy.get('#PASSWORD_CONFIRM').type('password');
if (isEnter) {
cy.get('#ORGANIZATION_NAME').type('Needone{enter}');
} else {
cy.get('#ORGANIZATION_NAME').type('Needone');
}
}

const setTypeInEtherealForm = () => {
cy.get('#address').type('toto.toto@ethereal.email');
cy.get('#password').type('LALALAALAL{enter}');
cy.get(':nth-child(4) > .nav-link').click();
}

const clickLinkInEmail = () => {
cy.get('iframe').then((iframe) => {
const body = iframe.contents().find('body');
cy.wrap(body).find('a').click();
});
}

integration/socle_full_ts_local/2_login_user_local.spec.js

/// <reference types="cypress" />
import * as userRegister from "../../fixtures/register_user.json";

describe('Test login on Socle-Full-JS LOCAL', () => {
it('Login user on Socle', () => {
cy.visit(Cypress.env('LOCAL_URL') + 'auth/login');
cy.get('#USERNAME').type(userRegister.email);
cy.get('#PASSWORD').type(userRegister.password);
cy.get('.login-form-button').click();
cy.url().should('eq', Cypress.env('LOCAL_URL') + 'showcase/app/home');
});

it('Login user on Socle with button enter', () => {
cy.visit(Cypress.env('LOCAL_URL') + 'auth/login');
cy.get('#USERNAME').type(userRegister.email);
cy.get('#PASSWORD').type(userRegister.password + '{enter}');
cy.url().should('eq', Cypress.env('LOCAL_URL') + 'showcase/app/home');
});
});

integration/socle_full_ts_dev/2_login_user.spec.js

/// <reference types="cypress" />
import * as userRegister from "../../fixtures/register_user.json";

describe('Test login on Socle-Full-JS DEV', () => {
xit('Login user on Socle', () => {
cy.visit(Cypress.env('HERUKU_URL') + 'auth/login');
cy.get('#USERNAME').type(userRegister.email);
cy.get('#PASSWORD').type(userRegister.password);
cy.get('.login-form-button').click();
cy.url().should('eq', Cypress.env('HERUKU_URL') + 'showcase/app/home');
});

xit('Login user on Socle with button enter', () => {
cy.visit(Cypress.env('HERUKU_URL') + 'auth/login');
cy.get('#USERNAME').type(userRegister.email);
cy.get('#PASSWORD').type(userRegister.password + '{enter}');
cy.url().should('eq', Cypress.env('HERUKU_URL') + 'showcase/app/home');
});
});

我遇到的问题是,当我想同时启动所有测试时,它会进入一个循环并且无法退出。我在网上查了看是否有人遇到过这个问题,但我没有找到……这是演示问题的视频:

Cypress problem gif

这是我尝试过的:

  • 使用 xit 将测试置于待机状态
  • 查看文档是否与内存分配有关...
  • 用文件夹分开测试

我的测试没有那么复杂我只是测试一个用户的注册和同一个用户的登录...

如果有人有想法?谢谢:)

最佳答案

好的,我有这个问题的解决方案:

在我的测试中我有:

it('在 Socle 上注册 ramdom 用户', () => {
//测试
});

要解决这个问题,只需将其转换为:

it('验证注册第一个用户', function () {
//测试
});

我不知道为什么,但它有效!

If anyone knows why i am taker :)

关于javascript - Cypress :运行所有规范,但创建一个没有运行规范的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59467383/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com