testCafe .switchToWindow() 方法 - 如何仅使用部分 url 主机名(或标题)切换到新窗口

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

我想只使用部分 url 主机名切换到新窗口。 例如代替

  • switchToWindow(w => w.url.host === 'testcafe.io')

我想用这样的东西:

  • (w => w.url.host === /.testcafe/.) //regex
  • (w => w.url.host.includes('testcafe'))

以上这两个都不起作用。还有其他可能吗?

javascript testing automated-tests e2e-testing testcafe
1个回答
1
投票

您可以使用RegExp api。例如:

fixture('My fixture')
  .page('https://testcafe.io/');

test('First test', async t => {
  await t
    .openWindow('https://devexpress.github.io/testcafe/example/')
    .switchToParentWindow()
    .switchToWindow((w) => /example/.test(w.url.href))
});
© www.soinside.com 2019 - 2024. All rights reserved.