Multiple file upload via setValue fails

59 views
Skip to first unread message

John Losh

unread,
Sep 22, 2020, 11:52:51 AM9/22/20
to NightwatchJs
If I pass a single file to setValue in my NW test it succeeds but if I try to pass an array of 2 files for upload it fails with 'invalid argument: file not found'. 
The verbose output appears to show the 2 file paths as a single string - (both file paths have been verified):
 "c:\code\nightwatch\test_files\test_auto1.mp4 c:\code\nightwatch\test_files\test_auto2.mp4".

Test code:
const filePath1 = require('path').resolve('./test_files/test_auto1.mp4 ');
const filePath2 = require('path').resolve('./test_files/test_auto2.mp4');
........
      .setValue('input[type=file]', [filePath1, filePath2]); // << multi-file fails
      .setValue('input[type=file]', [filePath1]);  // << single file works

Thanks in advance for any advice or assistance!

Christian Skubatz

unread,
Sep 23, 2020, 2:53:15 AM9/23/20
to NightwatchJs

Hi John,

we are uploading multiple files in this way

const path = require('path');

...

sectionMediaContent.setValue('@fileUpload', path.resolve(
`${__dirname}/../../../../etc/upload/documentMedium/01_documentMedium_DOC_Microsoft-Word-Document.doc`
+ `\n${__dirname}/../../../../etc/upload/documentMedium/02_documentMedium_DOCX_Microsoft-Word-Open-XML-Document.docx`
+ `\n${__dirname}/../../../../etc/upload/documentMedium/03_documentMedium_DOT_Word-Document-Template.dot`
+ `\n${__dirname}/../../../../etc/upload/documentMedium/04_documentMedium_DOTX_Word-Open-XML-Document-Template.dotx`
+ `\n${__dirname}/../../../../etc/upload/documentMedium/05_documentMedium_ODT_OpenDocument-Text-Document.odt`
+ `\n${__dirname}/../../../../etc/upload/documentMedium/06_documentMedium_OTT_OpenDocument-Document-Template.ott`
+ `\n${__dirname}/../../../../etc/upload/documentMedium/07_documentMedium_PDF_Portable-Document-Format-File.pdf`,
));

FYI: This could possibly help you too: https://groups.google.com/g/nightwatchjs/c/gGYtX-R8Pzg/m/bLmSYaG6CAAJ
I have talked with our developers and now we "flush" the input after an upload, the workaround ist not needed anymore.

Hope it helps and works for you too.

Greetings,
Chris

John Losh

unread,
Sep 24, 2020, 8:55:47 PM9/24/20
to NightwatchJs
Thanks for your help Chris, using the '/n' in the string instead of using the array got things working for a local file upload.
Now my quest is to get this running in our cloud hosting provider, unfortunately the cloud-based browser has no concept of my local test file for upload. My attempts to pass a web-based URL to setValue() are failing with ".setElementValue() protocol action: invalid argument: File not found : http://USWIL-7540-JL/test_files/Auto_test1.mp4", (even though the URL is definitely valid). 
Is it possible that setValue will not locate a file from a web URL? I haven't seen anyone using a URL like this yet.

Thanks again!
-John.

Reply all
Reply to author
Forward
0 new messages