mardi 12 janvier 2021

TestCafe: Changing download location

I am trying to change the download location and I found these codes doing research (sorry I forgot where I got these)

const browserConnection = t.testRun.browserConnection;
    const client = browserConnection.provider.plugin.openedBrowsers[browserConnection.id].client;
    const { Network, Page } = client;
    const downloadDirectory = '../my_downloads');

    await Promise.all([
      Network.enable(),
      Page.enable()
    ]);

    Network.requestWillBeSent((param) => {
      // console.log("Network.requestWillBeSent: " + JSON.stringify(param));
    });

    Network.responseReceived((param) => {
      // console.log("Network.responseReceived: " + JSON.stringify(param));
    });

    await Page.setDownloadBehavior({
      behavior: 'allow',
      downloadPath: downloadDirectory
    });

It was working perfectly fine using version 10.9.2 and this version was installed globally. I updated my TestCafe to 1.10.1 locally installed and now got this error:

TypeError: Cannot destructure property 'Network' of 'client' as it is undefined.

Any inputs are well appreciated. And looking forward to it :)

Aucun commentaire:

Enregistrer un commentaire