量角器:在不知道文件名的情况下测试下载文件 [英] protractor: test download file without knowing filename

查看:14
本文介绍了量角器:在不知道文件名的情况下测试下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了这个答案,它看起来几乎是我需要的东西.

I followed this answer and it looks almost the thing I need.

问题在于他已经知道文件名并且我正在做 e2e 测试以下载文件,但文件名取决于当前时间(即使是毫秒)所以我真的不知道名称(或者它会很难得到它).

The problem there is that he already knows the filename and I am doing e2e test for downloading a file, but the filename depends on the current time (even with milliseconds) so I don't really know the name (or it would be very difficult to get it).

我想我在这里遗漏了一些非常简单的东西,但我想了两种方法:

I think I am missing something very simple here, but I was thinking of two ways:

  1. 重新创建文件名(使用返回此文件名的相同函数)并开始检查具有该名称的文件是否存在,如果它不存在,则移动到下一毫秒,直到我找到正确的名称.
  2. 检查下载文件夹是否存在任何"文件,如果我在那里找到一个,那么它应该是我正在下载的文件(对于这种情况,我不知道如何在量角器中检查整个文件夹).

希望你们可以为这些替代方案提供帮助(我希望对第 2 点有所帮助),或者给我一个更好的替代方案.谢谢

Hope you guys could help with these alternatives (I would like some help with point 2) or maybe give me a better one. Thanks

推荐答案

我最终听从了@alecxe 的建议,这是我的答案:

I ended up following @alecxe's suggestion and here is my answer:

var glob = require("glob");

browser.driver.wait(function () {
    var filesArray = glob.sync(filePattern);
    if (typeof filesArray !== 'undefined' && filesArray.length > 0) {
        // this check is necessary because `glob.sync` can return
        // an empty list, which will be considered as a valid output
        // making the wait to end.
        return filesArray;
    }
}, timeout).then(function (filesArray) {
    var filename = filesArray[0];
    // now we have the filename and can do whatever we want
});

这篇关于量角器:在不知道文件名的情况下测试下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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