无头Chrome量角器文件下载测试失败 [英] Protractor file download test fails when headless chrome

查看:88
本文介绍了无头Chrome量角器文件下载测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在量角器测试方面遇到问题。它正在工作,但是现在(甚至认为没有任何变化)它没有。
测试只是打开应用程序(Web应用程序),然后单击按钮下载图像。下载应立即开始。
问题是,下载事件后的下一条指令将引发异常:失败:无法访问chrome。我正在使用最新的chrome和chrome驱动程序版本。

I am having an issue with a protractor test. It was working, but now (even thought nothing has changed) it is not. The test is just opening the app (web application) and clicking on a button to download an image. The download should start straight away. The problem is that the next instruction after the download event throws an exception, Failed: chrome not reachable. I am using the latest chrome and chrome driver versions.

量角器的功能部分如下:

The capabilites section for protractor is like this:

capabilities: {
   browserName: 'chrome',
   loggingPrefs: { browser: 'ALL' },
   chromeOptions: {
      args: ['--headless', '--window-size=1240,780'],
   },
}

我正在阅读使用DevTools启用无头模式下载(Page.setDownloadBehavior),但到目前为止还算不上运气。

I am reading about using DevTools to enable downloads in headless mode (Page.setDownloadBehavior), but so far no luck.

有人吗?也有这个问题吗?

Does anybody have this issue too? Any clue how to fix it?

谢谢。

推荐答案

一个更简单的解决方案是将这些行添加到您的 protractor.conf.js

An easier solution is to add these lines to your protractor.conf.js:

exports.config = {
  ...
  onPrepare() {
    ...
    browser.driver.sendChromiumCommand('Page.setDownloadBehavior', {
      behavior: 'allow',
      downloadPath: downloadsPath
    });
  }
};

来自: https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c196

如果您懒于找到下载路径,只需将其粘贴在您的量角器顶部.conf.js

If you are to lazy to find a Download Path just paste this at the top of your protractor.conf.js:

var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');

它将文件下载到 e2e / downloads 文件夹。只需在测试中使用相同的代码即可确定文件是否已下载。

It will download the file to the e2e/downloads folder. Just use the same code in your tests to find out if the file downloaded.

这篇关于无头Chrome量角器文件下载测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆