【发布时间】:2020-10-19 16:02:59
【问题描述】:
当此代码单击“打印”图标时,将生成 PDF 文件并显示在新的浏览器选项卡中。我想切换到此选项卡,等到 PDF 在那里完成加载,检查 URL 的一部分,然后关闭该辅助选项卡。
it( "should open document as PDF-file in new browser-tab", async () => {
const mUrl = "TherapyReportForm/Export";
await mTherapyReportView.btnPrintform.click();
await browser.getAllWindowHandles().then(async (handles) => {
//if there is a secondary browser-tab open...
if (handles.length > 1) {
//...click on it
await browser.driver.switchTo().window(handles[1]);
}
});
//confirm that the url of the secondary tab matches the print-url pattern
await browser.sleep( 18000 );
expect( await browser.getCurrentUrl() ).toContain( mUrl );
await browser.getAllWindowHandles().then( async (handles) => {
//if there are multiple browser-tabs open
if (handles.length > 1) {
//close the secondary and move back to first
await browser.driver.close();
await browser.driver.switchTo().window( handles[0] );
}
} );
} );
上面的测试工作可靠,除非我在 chromes 无头模式下运行它,否则测试运行会中断
expect(await browser.getCurrentUrl()).toContain(mUrl);
控制台输出证明它切换到辅助选项卡,但显然从未尝试加载 url。由于它无法关闭此辅助选项卡,因此整个套件将在那时中断。
我做错了什么?
【问题讨论】:
标签: selenium google-chrome protractor automated-tests headless