如何在testcafe中存根window.open

问题描述 投票:1回答:1

我想在testcafe中模拟window.open函数。因此,如果我的应用程序调用window.open而不是点击实际的窗口,我们可以使用模拟

这样会更好

onBeforeLoad: (window) => {
   cy.stub(window, 'open');
}
testing mocking automated-tests e2e-testing testcafe
1个回答
6
投票

要实现此目标,请使用'Inject Scripts into Tested Pages'功能。

const mockWindowOpen = "window.open = function () { };";
test
   ('My test', async t => { /* ... */ })
   .clientScripts({ content: mockWindowOpen });
© www.soinside.com 2019 - 2024. All rights reserved.