量角器 - 无法找到下载的文件 - 在 Chrome 上下载测试

fir*_*tor 4 download protractor

我想在 Google Chrome 上运行文件下载的 e2e 测试。我提到了几篇文章,包括量角器 - Jasmine - 将文件下载到相对路径用于下载 pdf 文件的量角器 e2e 测试用例在量角器测试中设置 chromedriver 首选项,但它们并没有让我满意。

这是我的量角器配置的简短介绍。

    ...
    'os': 'Windows',
    'os_version': '8.1',
    'browserName': 'Chrome',
    'version': '55',
    'chromeOptions': {
        args: ['--no-sandbox', '--test-type=browser'],
        prefs: {
            download: {
                'prompt_for_download': false,
                'directory_upgrade': true,
                'default_directory': '/tmp'
            }
        }
    }
    ...
Run Code Online (Sandbox Code Playgroud)

这是我的测试规范。

    it('file download test', () => {
        let filePath = path.resolve('/tmp/' + download-filename);
        // unlink(filePath);

        // click on a link by invoking anchor_element.click()
        // at the moment, file download will be done on chrome
        // with no prompt experienced

        // wait until file has been downloaded,
        //  (in fact, download can be finished within a sec)
        browser.wait(
            () => fs.existsSync(filePath),
            10000
        ).then(() => {
            // and then expectations here
        });
    });
Run Code Online (Sandbox Code Playgroud)

因此,就我而言,文件已成功下载但chromeOptions似乎不起作用,因为文件未下载到'default_directory'.

我怎么了?或者在我的情况下,默认情况下,使用 chrome 下载的文件在哪里?

我正在将 BrowserStack 用于 selenium 服务器并运行本地测试。我正在使用getMultiCapabilities选项配置具有多种功能的量角器。

希望有人能指导我一些关键提示。

Kul*_*mte 5

请在您的 conf.js 中添加以下代码

var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');
Run Code Online (Sandbox Code Playgroud)

并请参考首选项中的“下载路径”。

prefs: {
          download: {
            'prompt_for_download': false,
            'directory_upgrade': true,
            'default_directory': downloadsPath
          }
        }
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助。

谢谢