Can Testcafe automate a senario of attaching an attachment from the dekstop in a form

Viewed 23

In my web application i have an attachment button which browses files from the local computer and selecting any file from that results in uploading that file as an attachment, Can we Automate scenarios which include attaching a file from the local computer using TestCafe in Node js.

import PageModel from './page';
fixture`Getting Started`    .page`https://devexpress.github.io/testcafe/example`;

test('My first test', async t => {

  await t
      .setFilesToUpload('#upload-input', [
          './upload/abc.pdf',
      ])
      // No Upload button present
      // the file uploads automaticaly as soon as we click open button in file browsing window
      await t.click(Selector('#Button1').find('i').withText("save"))
});

The Screen Shot for the initial input button's code

1 Answers

TestCafe cannot fully emulate the user's behavior when uploading a file, since the upload form is a native and protected (for security reasons) dialog. It cannot be accessed from a web application or node.js. Our documentation has a section dedicated to this issue: https://testcafe.io/documentation/402808/recipes/basics/test-file-upload

You can verify that the file selection dialog cannot be accessed if you open such a dialog on any page, and then use the dev tools to try to select this dialog or any element in it: you will not succeed, since it is not part of HTML.

Also, I noticed that in the above test you have, the #upload-input selector is selected incorrectly - it does not exist on the https://devexpress.github.io/testcafe/example page. Perhaps you meant to select #uploadfile?

Related