私はこのスレッドの提案に従いました: Protractor e2e test case for Download pdf file and the file is Download successfully, but the test is time out before the compare/expect.
var filename = 'somefilename';
var content = 'some content\r\nsome more content';
download.click();
browser.driver.wait(function() {
return fs.existsSync(filename);
}, 5000).then(function() {
expect(fs.readFileSync(filename, {encoding: 'utf8'})).toEqual(content);
});
ファイルを作成してダウンロードし、続行する前に 5 秒間待機します。私が受け取るメッセージは次のとおりです。
Message:
Error: Wait timed out after 5000ms
Stacktrace:
Error: Wait timed out after 5000ms
at Array.forEach (native)
From: Task: <anonymous wait>
at /path/to/test/e2e/scenarios.js:337:28
at Array.forEach (native)
行 337 は browser.driver.wait 行です。
次のようにして、ファイルが2つの短い行にすぎないため、ダウンロードは実際には非常に高速であるため、browser.driver.waitなしで試してみました。
expect(fs.existsSync(filename));
browser.sleep(5000);
expect(fs.readFileSync(filename, {encoding: 'utf8'})).toEqual(content);
しかし、 readFileSync のファイル名が存在しないと表示されています。これは、ファイルがまだダウンロードされておらず、 browser.sleep(5000) が何もしないためだと思います。
分度器で約束をする別の方法はありますか? または、これが機能しない理由について誰かが私に手がかりを与えることができますか? 分度器 2.1.0 を実行しています。私は 1.0.0 を実行していて、再試行する前にすべてを更新しましたが、残念ながら、まだ機能していません。
よろしく、ジュリー