1

I'm trying to upload a file to the site I'm testing (Using Chrome) with Testcafe. Below is my code so far,

    await t
        .setFilesToUpload(Selector('input.btn.btn-link.d-none'), file_path)

    await t
          .setNativeDialogHandler(() => true)
                  .click('#Ok');

Once I try to upload the file, browser pops up a native dialog window, my options are "Open" / "Cancel". How do I click "Open" ? Also I don't know how to get the Selector for Open button.

I'm running this on Linux, Java Script. Below is the error,

   1) The specified selector does not match any element in the DOM tree.

       > | Selector('#Open')

      Browser: HeadlessChrome 78.0.3904 / Linux 0.0.0
      Screenshot: /app/code/screenshots/2019-12-11_22-28-52/test-2/HeadlessChrome_78.0.3904_Linux_0.0.0/errors/1.png

         71 |            //.handleAlert().click()
         72 |            //.click('#Open');
         73 |
         74 |        await t
         75 |              .setNativeDialogHandler(() => true)
       > 76 |                      .click('#Open');
         77 |
         78 |        const history = await t.getNativeDialogHistory();
         79 |        await console.log(history);
         80 |    }
         81 |}

         at <anonymous> (/app/code/gen_lib/gen_lib.js:76:24)
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
usustarr
  • 418
  • 1
  • 5
  • 21
  • 1
    TestCafe cannot operate with the native browser "Open File" dialog. Usually it's enought to put the file into the element using the .setFilesToUpload action and raise an uploading process (if it does not start automatically). If such scenario doesn't work with your site, please provide a sample page or a public url to reproduce the issue. – Dmitry Ostashev Dec 12 '19 at 17:06
  • You can see a detailed [description](https://devexpress.github.io/testcafe/documentation/recipes/basics/test-file-upload.html) of how to test file upload in TestCafe and inspect a runnable example [here](https://github.com/DevExpress/testcafe-examples/tree/master/examples/upload-files). – mlosev Oct 14 '20 at 07:13

1 Answers1

0
async uploadFile() {
    await this.t
        .setFilesToUpload(<Your input selector>, [
            'path to file/Image.jpg'
        ])
}
Olena Huk
  • 93
  • 9