![](/img/trans.png)
[英].NET 6 E2E tests with test server fail on TeamCity CI, but work run manually
[英]Why does my cypress e2e test never complete?
我有這個 cypress 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 但測試執行永遠不會停止。 這是為什么?
經過大量試驗和錯誤后,我只需要從“if”調用中的方法中刪除“win”參數,這是獲取 window 參考的測試。 事實上,這個參數是你需要在測試結束時調用的回調,我找不到任何關於它的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.