How to clear an input type file?

69 views
Skip to first unread message

Christian Skubatz

unread,
Aug 29, 2019, 7:54:10 AM8/29/19
to NightwatchJs
Hi, 

I have found the information that since chrome 75+ consecutive file uploads are handled a bit differently. Now the files were added to the input, which means, that when uploading three files, the first file is uploaded three times, the second twice, and the last one once. This is because an added file persists and is re-uploaded with the subsequent one. Then I have read that several files can be uploaded at once, by chaining the paths (\n) together. This works fine.

This was the code before

    sectionMediaContent.setValue('@fileUpload', require('path').resolve(__dirname + '/../../../../etc/upload/audioMedium/01_audioMedium_MP3_L-0.02Min_B-40kBits_C-Mono_SR-22.05kHz_S-10.5KB.mp3'));
    sectionMediaContent.setValue('@fileUpload', require('path').resolve(__dirname + '/../../../../etc/upload/audioMedium/02_audioMedium_MP3_L-0.02Min_B-40kBits_C-Stereo_SR-22.05kHz_S-10.5KB.mp3'));

This is the code now

    sectionMediaContent.setValue('@fileUpload', require('path').resolve(
      __dirname + '/../../../../etc/upload/audioMedium/01_audioMedium_MP3_L-0.02Min_B-40kBits_C-Mono_SR-22.05kHz_S-10.5KB.mp3' + '\n' +
      __dirname + '/../../../../etc/upload/audioMedium/02_audioMedium_MP3_L-0.02Min_B-40kBits_C-Stereo_SR-22.05kHz_S-10.5KB.mp3'));

Problem

In my test suites, several uploads are performed in different test cases. So I have to empty the file input somehow before the next upload is triggered. I have tried different things but did not find a proper solution.
  • .sectionMediaContent.clearValue('@fileUpload') - did not work
  • .sectionMediaContent.setValue('@fileUpload', '') - did not work
Can someone help me and has a solution for my reset input problem?

Environment

    "chromedriver": "76.0.1",
    "html-dnd": "1.2.1",
    "nightwatch": "1.2.1",

Config (for local testing)

{
    "src_folders": ["tests"],
    "globals_path": "globals.chris.js",
    "page_objects_path": "page-objects",

    "webdriver" : {
        "start_process": false,
        "host": "localhost",
        "port": 4444
    },

    "test_settings": {

        "default": {
    "skip_testcases_on_fail": false,
            "webdriver": {
                "port": 9515,
                "default_path_prefix": ""
            },

            "desiredCapabilities": {
                "browserName": "chrome",
                "chromeOptions" : {
                    "args" : [
                        "--start-maximized"
]
                },
                "acceptSslCerts": true
            }
        }
    }
}

Any help is appreciated!
Regards, Chris
Message has been deleted

Christian Skubatz

unread,
Sep 26, 2019, 4:47:32 AM9/26/19
to NightwatchJs
Too bad that there seems to be no working solution for my case. I did a lot of research and found some threads on StackOverflow according to my problem.

I just found an ugly workaround. If you reload the page before the next upload in your test suite will happen - the input is cleared. Ugly but the best I could find.
Should there still be someone with ideas how the input can be cleared, of course I would be very grateful.

Regards
Chris

Side question: Why some threads are pinned here and others are not, who decides this and on what basis? Thanks :-)
Reply all
Reply to author
Forward
0 new messages