为什么我的cypress e2e测试无法完成?

时间:2019-10-16 08:40:17

标签: asp.net-core cypress blazor-client-side

我有这个赛普拉斯e2e测试。

/// <reference types="Cypress" />

describe('Toss Full Test', function () {
let polyfill;
const uuid = Cypress._.random(0, 1e6)

before(() => {
    const polyfillUrl = 'https://unpkg.com/whatwg-fetch@3.0.0/dist/fetch.umd.js';
    cy.request(polyfillUrl).then(response => {
        polyfill = response.body;
    });
});
Cypress.on('window:before:load', win => {
    delete win.fetch;
    win.eval(polyfill);
});
const SubscribeEmail = "tosstests" + uuid + "@yopmail.com";
const SubscribePassword = "tossTests123456!!";
const SubscribeLogin = "tosstests" + uuid;

it('Full process', function (win) {
    cy.server();
    cy.visit("/");



    cy.route('POST', '/api/account/register').as('register');
    //this could be lagging as ravendb is starting
    cy.get("#LinkLogin", { timeout: 20000 }).click();
    //register
    cy.get("#LinkRegister").click();
    cy.get("#NewEmail").type(SubscribeEmail);
    cy.get("#NewName").type(SubscribeLogin);
    cy.get("#NewPassword").type(SubscribePassword);
    cy.get("#NewConfirmPassword").type(SubscribePassword);

    cy.window()
        .then(win => {
            // disables runCaptcha
            win.runCaptcha = new win.Function(['action'], 'return Promise.resolve(action)');
        })
        .then(
            () => {
                cy.get("#BtnRegister").click();
                cy.wait('@register');
                cy.get('@register').then(function (xhr) {
                    expect(xhr.status).to.eq(200);
                });

            }
        );
    })
})

完整代码可在https://github.com/RemiBou/Toss.Blazor/tree/master/Toss.Tests.E2E.Cypress处找到。

当我使用以下代码运行项目时

docker-compose up -V ravendb web
./node_modules/.bin/cypress open

代码运行良好,断言为“ expect(xhr.status).to.eq(200);”。返回true,但测试执行永不停止。为什么会这样?

1 个答案:

答案 0 :(得分:0)

经过反复试验,我只需要从“ if”调用中的方法中删除“ win”参数,这是获取窗口引用的测试。实际上,此参数是您需要在测试结束时调用的回调,我找不到有关它的任何文档。