testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Cannot download file by clicking the link with attributes: download, target='_blank' and href='blob:...'

Open AlexKamaev opened this issue 3 years ago • 14 comments

<!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

AlexKamaev avatar Sep 23 '20 08:09 AlexKamaev

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:

image

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.

Rommel-GitHome avatar Oct 29 '20 19:10 Rommel-GitHome

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.

AlexKamaev avatar Oct 30 '20 08:10 AlexKamaev

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 avatar Dec 01 '21 14:12 AM1988

@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.

AlexKamaev avatar Dec 02 '21 06:12 AlexKamaev

We have tried this solution for #6946 but it did not work for us, we get a new blank window as shown : image 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 avatar May 18 '22 13:05 TusharBachchan

@TusharBachchan We'll take your usage scenario in account when we research the issue.

AlexKamaev avatar May 19 '22 07:05 AlexKamaev

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.

AMuskan12 avatar May 19 '22 07:05 AMuskan12

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.

yashaswi0812 avatar May 25 '22 05:05 yashaswi0812

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.

yashaswi0812 avatar May 25 '22 06:05 yashaswi0812

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar May 26 '22 05:05 github-actions[bot]

@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?

TusharBachchan avatar Sep 22 '22 07:09 TusharBachchan

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar Sep 27 '22 05:09 github-actions[bot]

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.

TusharBachchan avatar Nov 08 '22 16:11 TusharBachchan

We will update this thread once we have any news.

AlexKamaev avatar Nov 09 '22 06:11 AlexKamaev

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.

github-actions[bot] avatar Mar 16 '24 01:03 github-actions[bot]

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.

github-actions[bot] avatar Mar 26 '24 01:03 github-actions[bot]