3

I am creating a test where it goes to a specific page and clicks on and the button which downloads an excel file.

The file is hosted in a far off location it takes generally 1.5 mins to gather it from the host server before the downloading is started, which only takes 2-3 seconds to download it completely.

From the time between I click on the submit button and the time the download is started, there is a gap of 1.5 mins(as mentioned before).

I tried applying .wait(120000) - 2 mins to be on the safe side.

The test gives an error (see the attached image below).

Screenshot of the error

This is my test code.

test('R03', async t => {
await t  
    .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_1'))
    .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_1'))
    .click(Selector('span').withText('SUBMIT'))
    .wait(120000); // in ms
});

Debugging the test showed me the following error:

 × R03

   1) Failed to complete a request to

   "http://example.com/Reports/ViewerPartial/DXXRDV.axd?actionKey=exportTo&arg=%7B%22documentId%22%3A%227c93875b0e0247e391d50759c00ef3a7%22%2C%22exportOptions%22%3A%22%7B%5C%22Html%5C%22%3A%7B%5C%22%40EmbedImagesInHTML%5C%22%3A%5C%22true%5C%22%7D%7D%22%2C%22format%22%3A%22xlsx%22%7D"
      within the timeout period. The problem may be related to local 
      machine's network or firewall settings, server outage, or network 
      problems that make the server inaccessible.

I have hidden the domain name changed it to example.com for company reasons.
If I removed the .wait(120000) the test is completed and is shown successful. Any suggestion would be appreciated. Trying to get the hang of it (testcafe)

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • I understand that adding the .wait(timeout) pauses the test which is not what i want. I just want it to wait and continue for sometime before moving to the next one. – Ayush Singhania Mar 08 '19 at 13:45

1 Answers1

1

As a workaround, you could wait for the file to arrive in the download folder by using a for loop:

import { join } from 'path';
import { existsSync } from 'fs';
import {t} from 'testcafe';

test("My Test", async (t) => {
    await t  
    .click(Selector('[data-bind^="css:{ \\\'dx-state- disabled\\\'].find('div').withText('Year_1'))
    .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_1'))
    .click(Selector('span').withText('SUBMIT'));

   await waitUntilFileIsDownloaded();
});

async function waitUntilFileIsDownloaded(){
    const downloadsFolder= `${process.env.HOME}/Downloads`;
    const expectedFile = join(downloadsFolder, 'data.csv');
    console.log(`waiting for file '${expectedFile}' ...`);
    for (let index = 0; index < 120; index++) {
        if (existsSync(expectedFile)) {
            console.log(`file downloaded after ${index} seconds`);
            return;
        }
        await t.wait(1000);
        console.log(`waiting for '${index}' seconds`);
    }
    console.log('File has not been downloaded in due time');
}
hdorgeval
  • 3,000
  • 8
  • 17
  • Hi thanks for the solution, looks good but doesn't solve my problem. After 10-12 seconds I get an error (screenshot of which i shared in my question) and after the designated time of 120 seconds, i get the same error as one i shared in my question "Failed to complete a request to ..... within the timeout period. The problem may be related to local machine's network or firewall settings, server outage, or network problems that make the server inaccessible." Any help would be appreciated. – Ayush Singhania Mar 11 '19 at 10:44
  • 1
    It looks like the issue is related to https://github.com/DevExpress/testcafe/issues/2940 Please refer to it for more details. Feel free to add comments and likes there to help us prioritize suggestions. – Alex Kamaev Mar 11 '19 at 13:35