2

This is a kind of test I am trying to run in test cafe v1.0.1, I am relatively new to this.

This my test.js file where I have three different test cases R03, R05, R06 each after clicking on the SUBMIT button downloads an EXCEL file.

But before the download is finished, the browser closes and moves on to the next test.

How can I let the browser wait until the document is downloaded before moving onto the next test (say r05 in my case)?

import { Selector } from 'testcafe';

fixture `First Fixture`
    .page `http://devexpress.github.io/testcafe/example`;

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'))
 });
test('R05', async t => {
    await t
        .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_2'))
        .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_2'))
        .click(Selector('span').withText('SUBMIT'))
 });

test('R06', async t => {
    await t
        .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_3'))
        .click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_3'))
        .click(Selector('span').withText('SUBMIT'))
 });
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • can't you add a `.wait(60000)`? Not ideal, but gets the job done :) –  Mar 07 '19 at 18:36
  • Thanks for the suggestion but I can't, because the downloaded file is sometimes big in size which varies from time to time so it may take more time (which it does according to my experience) than a fixed time of say 60000ms. So i am looking for something to check if the downloaded file exists then only proceed to the next one – Ayush Singhania Mar 08 '19 at 09:43

1 Answers1

4

Not the ideal solution, but simple and should work if set the appropriate wait time.

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(60000); // in ms
 });

Another solution would be writing a function to check if the file exists in the directory -- see answers here

  • No, it won't, because the .wait(timeout) pauses the test, which I don't want because it will then pause the download which it started after clicking on the submit button. – Ayush Singhania Mar 08 '19 at 13:43
  • 2
    another solution might be this one https://stackoverflow.com/questions/48910111/how-to-do-fs-existssyncpath-with-timeout –  Mar 08 '19 at 14:10