Bug Report T824527
Visible to All Users

TestCafe Studio generates an incorrect path to the uploaded file

created 5 years ago

I am using TestCafe Studio to record tests that Upload files in my web application.
I have used the Set Files to Upload both with and without Clear Upload as the next step.

The test runs perfectly fine when I run from TestCafe Studio.
However, when the tests are deployed by Azure DevOps to another machine where the _uploads_ folder does not have the same exact file path, the tests fail because it cannot find the whole path name.

Cannot find the following file(s) to upload: C:\Source\Test\PortalTestCafe\TestCafeTests\_uploads_\HealthCareClinic.spfx Browser: HeadlessChrome 77.0.3865 / Windows 10.0.0

If I change the Javascript file and replace the entire path with "…", the test runs fine from the Javascript file.
.click(Selector('span').withText('Browse'))
.setFilesToUpload(Selector('#uploadModelFiles'), ['…\_uploads_\HealthCareClinic.spfx'])
.click(Selector('.main-container'))
.click(Selector('#uploadProjectButton'))

I cannot seem to remove the entire file path in the testcafe file however.

In our Azure DevOps, the command line is using the testcafe files.

Is there something that I need to so differently to be able to run the testcafe file?
Or is my only option to run the Javascript?

Please advise.
Thanks

Answers approved by DevExpress Support

created 5 years ago

We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

    created 5 years ago

    Hi

    It's a bug in TestCafe Studio. We've already fixed it and are going to include the fix in the next TestCafe Studio release.
    TestCafe Studio will record relative paths for the uploaded files. In your tests, you need to update all absolute paths and replace them with relative ones.

    At present, the only way to run your tests in Azure DevOps is to convert them to JavaScript and fix absolute paths.

      Show previous comments (1)
      DO DO
      Dmitry O. (DevExpress) 5 years ago

        Unfortunately, we cannot provide a precise date of the next release.

        CD CD
        Customer97930_Developer 5 years ago

          I have upgraded to the latest TestCafe and still am having the same issue.
          Can you provide instructions or documentation on how the upload should be coded in TestCafe?
          I have an uploads folder and the test runs from TestCafe studio.
          When trying to run the testcafe files from my local computer:
          In dos prompt:

          1. Cannot find the following file(s) to upload:
            HealthCareClinic.sxxx

            Browser: Chrome 80.0.3987 / Windows 10.0.0

            2

          1/1 failed (21s)

          AK AK
          Alexey K. (DevExpress) 5 years ago

            Hello.
            The issue with absolute paths was fixed in v.1.2.0. So, in the latest version, the setFilesToUpload step should not write absolute paths.

            The recording of the file uploading works in the following way. When you record your test using the Visual Recorder, uploaded files are automatically copied to the _uploads_ directory. After that, in the Set Files to Upload step, you will see the list of uploaded files without paths (i.e 'file1.txt', 'file2.txt').

            If you convert your test to JS, you will see the following command: .setFilesToUpload(Selector('#file'), ['file1.txt', 'file2.txt']);. Thus, using the Recorder will prevent using absolute paths in the setFilesToUpload step.

            You mentioned that you can reproduce the error on your local machine. So, I assume that recorded tests still have absolute paths since they were written in the older TestCafe Studio version. I recommend you check if your test files contain absolute paths. The easiest way to check this is to convert them to JS.

            If they contain absolute paths, it's better to rewrite your tests using the latest TestCafe Studio version. Alternatively, you can create a new test in the fixture, copy all steps before the setFilesToUpload step from the old test, create a new setFilesToUpload step using the Visual Recorder, and copy all steps after the setFilesToUpload step from the old test.

            If my assumption is incorrect, please share your .testcafe files and the converted files so that we can research them in detail.

            Other Answers

            created 5 years ago (modified 5 years ago)

            Hello Alexey,

            Thanks for your response. Let me provide more details for you.

            Yesterday, I upgraded to version 1.2.2 of TestCafe Studio. I then used TestCafe studio to record a new test with the webpage in my application that has the upload functionality.
            Here is my folder structure. Notice the uploads folder.

            Clipboard-File-1.png
            Clipboard-File-3.png

            Here is what my Set Files to Upload looks like:
            Clipboard-File-2.png

            When I run the test in TestCafe Studio it works fine. When I convert the testcafe file to JS and run it in TestCafe Studio it works fine.

            Here is the problem that I am having. When I use a dos window and navigate to c:\TestCafe\TestCaseFolder and execute either the *.testcafe file or the *.js file, I get the error that it cannot find the file to upload.

            Code
            c:\TestCafe\TestCaseFolder>testcafe chrome:headless *.testcafe Running tests in: - HeadlessChrome 80.0.3987 / Windows 10.0.0 onprem.admin.upload × UploadHealthCareClinicModel 1) Cannot find the following file(s) to upload: HealthCareClinic.spfx Browser: HeadlessChrome 80.0.3987 / Windows 10.0.0 2 1/1 failed (32s) c:\TestCafe\TestCaseFolder>

            Here is the JS code:

            JavaScript
            test('UploadHealthCareClinicModel', async t => { await t .click(Selector('a').withText('Models')) .click(Selector('span').withText('Browse')) .setFilesToUpload(Selector('#uploadModelFiles'), ['HealthCareClinic.spfx']) .click(Selector('#uploadProjectButton')) .typeText(Selector('.dx-texteditor-input-container').find('.dx-texteditor-input'), 'HealthCareClinic')

            Clipboard-File-4.png

              Show previous comments (8)
              Alex Skorkin (DevExpress) 5 years ago

                We fixed the issue described in this ticket on April 6 in version 1.2.3. Have you had a chance to check out the fix?

                CD CD
                Customer97930_Developer 5 years ago

                  Thank you. I have created a new test and it passes in both Studio and from the command line.
                  I will also test with Azure DevOps.

                  Alex Skorkin (DevExpress) 5 years ago

                    You are welcome.

                    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.