我已经为多个窗口编写了代码。也就是说,当我点击按钮时,它将打开新窗口,然后在该窗口中,我必须进行点击操作。 我用过这个代码 Const y=等待客户端函数(()=>;window.location.pathname)()
await t.switchToWindow(f => f.url.pathname === y)
enter image description here
enter image description here
总的来说,您的方法是正确的。 请看此示例:
fixture `fixture`
.page `http://example.com`;
test(`test`, async t => {
await t.openWindow('http://google.com');
await t.switchToWindow(data => {
return data.url.hostname === 'example.com';
});
await t.click('h1');
});
如果没有帮助,请共享演示此问题的示例。