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

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

问题描述

我在量角器测试时遇到问题.它正在工作,但现在(甚至认为什么都没有改变)它不是.测试只是打开应用程序(Web 应用程序)并单击按钮下载图像.下载应立即开始.问题是下载事件后的下一条指令抛出异常,Failed: chrome not reachable.我正在使用最新的 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

如果您懒得找下载路径,只需将其粘贴到 protractor.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天全站免登陆