testcafe
testcafe copied to clipboard
Cannot download file by clicking the link with attributes: download, target='_blank' and href='blob:...'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a download="hello.txt" href='#' id="link" target="_blank">Download</a>
<script>
let blob = new Blob(["Hello, world!"], { type: 'text/plain' });
document.querySelector('#link').href = URL.createObjectURL(blob);
</script>
</body>
</html>
fixture `f`
.page `http://127.0.0.1:8080`;
test('test', async t => {
await t.click('a');
await t.wait(5000);
});
WORKAROUND: use the --disable-multiple-windows
flag
In ref to your comment :
I am afraid I cannot provide you the url due to the sensitivity of the on-going project. But what do you mean by "create a sample..."? A sample of the site under test?
I was viewing at the browser's DevTools, the downloading is not similar to your example above where it uses download, target attributes. We are actually using SAPUI5 technology. Kind see attached screenshot:
So right now I shifting to using the --disable-multiple-windows on all tests. But it would be great if there is a way to apply that option on a particular test only.
But what do you mean by "create a sample..."? A sample of the site under test?
I mean that you can create a simple project that demonstrates the issue and share it with us.
I was viewing at the browser's DevTools, the downloading is not similar to your example above where it uses download, target attributes. We are actually using SAPUI5 technology. Kind see attached screenshot:
The issue can still be the same despite the fact that your markdown differs from the markdown in my example. I found this issue using other UI controls. In those UI controls, the markdown from my example was generated via JS.
But it would be great if there is a way to apply that option on a particular test only.
From our point of view, it's better to fix the cause of the issue. However, I can suggest a workaround. You can use the programmatic API and run your tests two times: with the disableMultipleWindows
option and without it.
I created a sample to demonstrate this approach:
Tests (test.js):
fixture `fixture`
.page `http://example.com`;
test('1', async t => {
await t.click('h1');
});
test('2', async t => {
await t.click('h1');
});
test('3', async t => {
await t.click('h1');
});
test('4', async t => {
await t.click('h1');
});
test('5', async t => {
await t.click('h1');
});
The runner (index.js):
const createTestCafe = require('testcafe');
async function start () {
const testcafe = await createTestCafe('localhost', 1337, 1338);
try {
const runner = testcafe.createRunner();
await runner
.src(['test.js'])
.browsers('chrome')
.filter(testName => testName !== '3')
.run({ disableMultipleWindows: false });
await runner
.filter(testName => testName === '3')
.run({ disableMultipleWindows: true });
}
finally {
await testcafe.close();
}
}
return start();
You can run the tests using the following command in the terminal: node index.js
.
Thus, 4 of 5 tests will be executed with the enabled multiple-windows feature and the last test with the disabled.
We have a similar issue in angular12 project:
<a href="javascript:void(0);" class="d-block">Download</a>
by clicking on the link we download the static file.
On click, we see that a new window has been opened but is closed after a few milliseconds, and the file is not downloaded.
@AM1988 this issue is specific to the href="blob:..."
case. I think that your usage scenario is similar to #6680.
Please try to check the https://www.npmjs.com/package/testcafe/v/1.17.2-alpha.2 version.
If it does not help, please create a new issue and share your example with us.
We have tried this solution for #6946 but it did not work for us, we get a new blank window as shown :
and our script freezes if we try to close the new window (using our script) and if we do not close the new window and we try to perform any action only one step further is performed and then it again freezes.
@TusharBachchan We'll take your usage scenario in account when we research the issue.
Regarding issue #6946 :- Thank you for your response. Actually we have some dependency around this scenario, could you please take this scenario bit early if possible. Your help will be appreciated.
Is there any update? we tried the solution and it didn't work for us. our script freezes if we try to close the new window (using our script) and if we do not close the new window and we try to perform any action only one step further is performed and then it again freezes and stays there till we manually close it.
we tried to write scripts in different tests still it didn't work. After Screen is frozen it doesn't move to another test. we even tried to forcefully close the window and it didn't work as well.
No updates yet. Once we get any results, we will post them in this thread.
@TusharBachchan We'll take your usage scenario in account when we research the issue.
Is there any updates regarding this issue, has this usage scenario taken into consideration?
No updates yet. Once we get any results, we will post them in this thread.
It would really be helpful if this issue is taken into consideration, please let us know if it is taken into consideration for future releases.
We will update this thread once we have any news.
This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.
We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.