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

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

问题描述

我按照这个答案看起来几乎是我需要的东西。

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天全站免登陆