geckodriver icon indicating copy to clipboard operation
geckodriver copied to clipboard

Uploading files doesn't work when specifying a folder

Open KapustinMaxim opened this issue 5 years ago • 6 comments

Describe the bug

Using Nightwatch for testing and .setValue()` for uploading file/folder doesn't work for Mozilla Firefox.

Sample test

const chalk = require('chalk');
const DEFAULT_TIMEOUT = '2000';
var date = new Date().getDate();
var month = new Date().getMonth();
var year = new Date().getFullYear();


function browserName(browser) { 
  var a = browser.options.desiredCapabilities;
  return (a.browserName  ).replace(/ /g, '');
};


module.exports = {
  '@tags': ['master'],
      
  'step 1' : function (browser) {

        
    browser
      .maximizeWindow()
      .url('https://www.google.ru/imghp?hl=ru&tab=wi&authuser=0&ogbl')
      .click('.BwoPOe')
      .click('.H4qWMc:nth-child(2)')
      .setValue('#awyMjb','d:/yp.png')

      .end();
  },
 
};

Run with command

D:\Autotests\nightwatch-example-master>npm run test:ffox

> [email protected] test:ffox D:\Autotests\nightwatch-example-master
> nightwatch -e firefox


[Temp] Test Suite
=================
i Connected to 127.0.0.1 on port 4144 (3084ms).
  Using: firefox (80.0.1) on windows 6.1 platform.

Running:  TC1351 step 1

   Response 500 POST /wd/hub/session/0821360b-2abe-43b8-82fb-90828b69a18d/element/9a13d344-9760-4842-80f8-fa6d124eac14/value (45ms)
   {
     state: 'invalid argument',
     sessionId: null,
     class: 'org.openqa.selenium.remote.Response',
     value: {
       additionalInformation: '\nDriver info: driver.version: unknown',
       localizedMessage: 'File not found: d:/yp.png\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'S81', ip: '192.168.0.102', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\n" +
         'Driver info: driver.version: unknown',
       supportUrl: null,
       systemInformation: "System info: host: 'S81', ip: '192.168.0.102', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'",
       cause: null,
       suppressed: [],
       message: 'File not found: d:/yp.png\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'S81', ip: '192.168.0.102', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\n" +
         'Driver info: driver.version: unknown',
       class: 'org.openqa.selenium.InvalidArgumentException',
       buildInformation: null
     },
     status: 61
}
 Error while running .setElementValue() protocol action: File not found: d:/yp.png


FAILED: 1 errors (2.834s)
_________________________________________________

TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (11.179s)

 × temp
 – TC1351 step 1 (2.834s)

  TimeoutError: An error occurred while running .setValue() command on <#awyMjb>: 
   {"status":-1,"code":"","state":"invalid argument","value":{"additionalInformation":"\nDriver info: driver.version: unknown","localizedMessage":"File not found: d:/yp.png\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'S81', ip: '192.168.0.102', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\nDriver info: driver.version: unknown","supportUrl":null,"systemInformation":"System info: host: 'S81', ip: '192.168.0.102', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'","cause":null,"suppressed":[],"message":"File not found: d:/yp.png\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'S81', ip: '192.168.0.102', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\nDriver info: driver.version: unknown","class":"org.openqa.selenium.InvalidArgumentException","buildInformation":null},"errorStatus":61,"error":"File not found: d:/yp.png","httpStatusCode":500}
       at processTicksAndRejections (internal/process/task_queues.js:97:5)


npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! [email protected] test:ffox: `nightwatch -e firefox`
npm ERR! Exit status 5
npm ERR!
npm ERR! Failed at the [email protected] test:ffox script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\alex\AppData\Roaming\npm-cache\_logs\2020-09-23T17_09_59_787Z-debug.log


Configuration

nightwatch.json

{
 const seleniumServer = require('selenium-server');
const edgeDriver = require('edgedriver');
const chromeDriver = require('chromedriver');
const geckoDriver = require('geckodriver');
const ieDriver = require('iedriver'); 
require('dotenv').config();

module.exports = {
  src_folders: ['tests'],
  custom_commands_path: '',
  custom_assertions_path: '',
  page_objects_path: '',
  globals_path: '',
  live_output: false,
  disable_colors: false,
  parallel_process_delay: 10,
  "test_workers": {
    "enabled": false,
    "workers": "auto"
  },
  selenium: {
    start_process: true,
    //start_session: false,
    server_path:  "selenium-server-standalone-3.141.59.jar", //seleniumServer.path, 
    check_process_delay: 5000,
    host: '127.0.0.1',
    port: 4144,
    cli_args: {
      "webdriver.ie.driver": ieDriver.path,
      "webdriver.chrome.driver": chromeDriver.path,
      "webdriver.gecko.driver": geckoDriver.path,
      "webdriver.edge.driver":  "node_modules/edgedriver/msedgedriver.exe"
    }
  },
  
  test_settings: {
    skip_testcases_on_fail: false,
    end_session_on_fail: false,
    default: {     
      desiredCapabilities: {
        
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true,
        marionette: true,
        firefox:{
          w3c: false,
        /*browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          w3c: false,
          args: ['disable-gpu'] */
        }
      }
    },
    
    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          w3c: false,
          args: ['disable-gpu']
        }
      }
    },

    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true,
        marionette: true,
        firefox:{
          w3c: false,
        }
            
      }
    },

    edge: {
      desiredCapabilities: {
        browserName: 'MicrosoftEdge',
        javascriptEnabled: true,
        acceptSslCerts: true,
         edgeOptions:{
          w3c: false,
        }
      }
    },
    
    ie: {
      desiredCapabilities: {
        browserName: 'internet explorer',
        javascriptEnabled: true,
        acceptSslCerts: true
               
      }
    },
  }
};

Your Environment

Executable Version
nightwatch --version 1.4.2
npm --version '6.14.5'
Browser driver Version
firefox 80.0.1

| OS | Version | | Win7 | 6.1 |

-->

KapustinMaxim avatar Oct 09 '20 02:10 KapustinMaxim

As said on the other issue, is d:/yp.png really a valid file? Note that you are on Windows and it would require two backslashes and not a slash.

Also please provide the trace level log as requested when filing an issue.

whimboo avatar Oct 09 '20 07:10 whimboo

As said on the other issue, is d:/yp.png really a valid file? Note that you are on Windows and it would require two backslashes and not a slash.

Also please provide the trace level log as requested when filing an issue.

two backslashes worked! thank you very much, such a simple solution

KapustinMaxim avatar Oct 09 '20 07:10 KapustinMaxim

As said on the other issue, is d:/yp.png really a valid file? Note that you are on Windows and it would require two backslashes and not a slash.

Also please provide the trace level log as requested when filing an issue.

with files works fine THANKS, but how about folders?

`TC1351 step 5' : function (browser) {
    browser
    
      .click('#add-study-dropdown > span:nth-child(2)')
      .waitForElementVisible('css selector','#upload-studies > span')
      .click('#upload-studies > span')
      .waitForElementVisible('css selector','#file_input_instructions')
      .assert.containsText('#file_input_instructions','Choose File...')
      .pause(1000)
      
      //.click('#enable-dicom-wrapping')
      
      .setValue('#file_input',"d:\\HermioneGranger")   
      .pause(1000)
     
      .assert.elementPresent('.list-checkbox')
     
      
      .waitForElementVisible('css selector','#study-summary-patientName-1284011385711385715281414521212 > .normal','Hermione Granger')
      .assert.containsText('#study-summary-patientName-1284011385711385715281414521212 > .normal','Hermione Granger')


      
      .saveScreenshot('./tc_screenshots/TC1351/'+ year +'_'+ month +'_'+ date + '/' + browserName(browser) +'_5.png');
      //.quit();
  },`

ERROR

`Running:  TC1351 step 5

√ Element <#upload-studies > span> was visible after 86 milliseconds.
√ Element <#file_input_instructions> was visible after 1167 milliseconds.
√ Testing if element <#file_input_instructions> contains text 'Choose File...' (26ms)
   Response 500 POST /wd/hub/session/d7fff387-69a6-4422-b87d-985ed2003ca7/element/dae724bc-c577-4cad-9238-923695e8398c/value (45ms)
   {
     state: 'invalid argument',
     sessionId: null,
     class: 'org.openqa.selenium.remote.Response',
     value: {
       additionalInformation: '\nDriver info: driver.version: unknown',
       localizedMessage: 'File not found: d:\\HermioneGranger\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\n" +
         'Driver info: driver.version: unknown',
       systemInformation: "System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'",
       supportUrl: null,
       cause: null,
       suppressed: [],
       message: 'File not found: d:\\HermioneGranger\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\n" +
         'Driver info: driver.version: unknown',
       class: 'org.openqa.selenium.InvalidArgumentException',
       buildInformation: null
     },
     status: 61
}
 Error while running .setElementValue() protocol action: File not found: d:\HermioneGranger

× Testing if element <.list-checkbox> is present in 5000ms - expected "is present" but got: "not present" (5260ms)
    at Object.TC1351 step 5 (D:\Autotests\nightwatch-example-master\tests\Login_temp.js:103:15)


FAILED: 1 assertions failed, 1 errors and  3 passed (8.94s)
_________________________________________________

TEST FAILURE: 1 error during execution; 1 assertions failed, 22 passed (28.381s)

 × Login_temp
 – TC1351 step 5 (8.94s)
   Testing if element <.list-checkbox> is present in 5000ms - expected "is present" but got: "not present" (5260ms)
       at Object.TC1351 step 5 (D:\Autotests\nightwatch-example-master\tests\Login_temp.js:103:15)

  TimeoutError: An error occurred while running .setValue() command on <#file_input>: 
   {"status":-1,"code":"","state":"invalid argument","value":{"additionalInformation":"\nDriver info: driver.version: unknown","localizedMessage":"File not found: d:\\HermioneGranger\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\nDriver info: driver.version: unknown","systemInformation":"System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'","supportUrl":null,"cause":null,"suppressed":[],"message":"File not found: d:\\HermioneGranger\nBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\nSystem info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\nDriver info: driver.version: unknown","class":"org.openqa.selenium.InvalidArgumentException","buildInformation":null},"errorStatus":61,"error":"File not found: d:\\HermioneGranger","httpStatusCode":500}
       at processTicksAndRejections (internal/process/task_queues.js:97:5)

   SKIPPED:
   - TC1351 step 6
   - TC1351 step 10
   - TC1351 step 11
   - TC1351 step 12
   - TC1351 step 13

   Response 500 POST /wd/hub/session/d7fff387-69a6-4422-b87d-985ed2003ca7/elements (491ms)
   {
     state: 'invalid session id',
     sessionId: null,
     class: 'org.openqa.selenium.remote.Response',
     value: {
       additionalInformation: '\nDriver info: driver.version: unknown',
       localizedMessage: 'Tried to run command without establishing a connection\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\n" +
         'Driver info: driver.version: unknown',
       systemInformation: "System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'",
       supportUrl: null,
       cause: null,
       suppressed: [],
       message: 'Tried to run command without establishing a connection\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'S81', ip: '192.168.0.104', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_261'\n" +
         'Driver info: driver.version: unknown',
       class: 'org.openqa.selenium.NoSuchSessionException',
       buildInformation: null
     },
     status: 6
}
 Error while running .locateMultipleElements() protocol action: Tried to run command without establishing a connection

× Hermione Granger - expected "visible" but got: "not found" (5002ms)
    at Object.TC1351 step 5 (D:\Autotests\nightwatch-example-master\tests\Login_temp.js:106:8)

npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! [email protected] test:ffox: `nightwatch -e firefox`
npm ERR! Exit status 5
npm ERR!
npm ERR! Failed at the [email protected] test:ffox script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\alex\AppData\Roaming\npm-cache\_logs\2020-10-09T08_44_32_263Z-debug.log`

KapustinMaxim avatar Oct 09 '20 08:10 KapustinMaxim

Sorry that we forgot about this issue.

Basically the WebDriver specification doesn't specify that the browser itself has to fetch all the files. Instead Element Send Keys expects an array of files separated by \n.

@KapustinMaxim can you verify that setting the list of files works?

whimboo avatar Mar 04 '22 16:03 whimboo

SORRY, problem solved

GabrielMendesdc avatar Apr 14 '22 11:04 GabrielMendesdc

I have the same problem on .net when i trying to upload folder. WebDriver throws OpenQA.Selenium.WebDriverArgumentException: File not found. And this method normally works with the same args using chromedriver or edgedriver. Suggestion to pass few files from directory like /n separated array not works because input doesn't have "multiple" attribute

Wampirs avatar May 04 '23 12:05 Wampirs