Testcafe: setFilesToUpload thows illegal invocation error when trying to append file to a FormData instance

Created on 15 Jan 2018  路  8Comments  路  Source: DevExpress/testcafe

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

If you try to use FormData when uploading a file, an error will be thrown. This is most likely due to the testcafe file wrapper.

What is the expected behavior?

I expected testcafe to set the files and the application to upload the files. Using FormData is the most common way to upload files using an xhr without the need for the user to click on a submit button (using the change event).

How would you reproduce the current behavior (if this is a bug)?

Run the provided test case with skipJsErrors setted to false (this is the default value though)

Provide the test code and the tested page URL (if applicable)

Tested page URL: https://codepen.io/javiercbk/full/VyBgRr/

Test code

import path from 'path';

// make sure to point to an existing file
const TEST_FILE_PATH = path.join(__dirname, 'textfile.txt');

fixture`fileUpload`.page`https://codepen.io/javiercbk/full/VyBgRr/`;

test('fileupload', async (t) => {
  await t.switchToIframe('#result').setFilesToUpload('input[type="file"]', TEST_FILE_PATH);
});

Specify your

  • operating system: Mac OS X 10.13.2 (tested on Chrome 63.0.3239)
  • testcafe version: 0.18.6
  • node.js version: v8.9.3
Auto-locked hammerhead bug

All 8 comments

Hi @javiercbk,

Thanks for the report. I've reproduced the issue.

/cc @miherlosev @LavrovArtem Please take a look at this. I've reproduced this with the playground

Found a workaround https://codepen.io/javiercbk/full/NXLGGV/

The original case:

const f = files.item(i);

The modification:

let f;
try {
  f = files.item(i);
} catch (err) {
  if (err.message === 'Illegal invocation') {
    f = files[i];
  } else {
    throw err;
  }
}

Hi @javiercbk.
I've reproduced the problem and created the separate issue in another repository - https://github.com/DevExpress/testcafe-hammerhead/issues/1446.
When the issue is fixed, we will release a new version of TestCafe immediately.

@miherlosev I'm having the same issue with uploads. Can you update the version of testcafe-hammerhead on this project? Are you planning to do an npm publish any time soon?

Hi @cortezcristian .
[email protected] contains the fix of this problem. Try to install this version and tell us about the results.

@miherlosev thank you!

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

multivoltage picture multivoltage  路  3Comments

xalvarez picture xalvarez  路  3Comments

devmondo picture devmondo  路  3Comments

marchugon picture marchugon  路  4Comments

AndreyBelym picture AndreyBelym  路  3Comments