首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我运行Protractor测试无头(Chrome)时,如何处理在辅助浏览器选项卡中加载的页面?

当我运行Protractor测试无头(Chrome)时,如何处理在辅助浏览器选项卡中加载的页面?
EN

Stack Overflow用户
提问于 2020-06-29 21:17:58
回答 1查看 53关注 0票数 0

当此代码单击“打印”-icon时,将生成一个PDF文件,并在新的浏览器选项卡中显示。我想切换到此选项卡,等待PDF在那里完成加载,检查URL的一部分,然后关闭该辅助选项卡。

代码语言:javascript
复制
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 headless-mode模式下运行,否则测试运行会中断。

代码语言:javascript
复制
expect(await browser.getCurrentUrl()).toContain(mUrl);

console output

控制台输出证明它会切换到辅助选项卡,但显然从未尝试加载url。由于无法关闭此辅助选项卡,整个套件将在此时中断。

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2020-06-30 05:19:09

有一件事..。下载功能在无头chrome中不可用。当然。下面我要说的是,我有点不确定是不是这样

浏览器中没有‘打开’pdf文件这样的东西。原因是浏览器实际上在幕后下载它(可能是临时的)。这就是为什么你永远不能在headless中做到这一点

但这只是一种冒险行为

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62639014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档