Search code examples
javascripthtmlinternbrowserstack

How can I test an input type="file" with Browserstack


So, I've been trying to test an input type="file" with Browserstack and Intern.js, but I keep getting a "File not found" error because Browserstack searches for the file in my computer.

I know that Browserstack has Upload/Download capabilities, but from their documentation I didn't quite get how to use it.


Solution

  • The issues doesn't seem to be different. Assuming that you get 'File not found' error on your test page, I believe that your type command is simply sending the keys to remote browser's element.

    For an input element of type 'file', type command should first upload the file from your local machine to the remote machine and then transparently upload to your test page. If this is not working then mostly your element is not of type 'file' or the version of intern you are using does not support remote upload/has bug.

    According to me it should fail locally as well, provided you have selenium standalone server and webdriver setup which uses remotewebdriver.

    Extract from 'https://theintern.github.io/leadfoot/module-leadfoot_Command.html#type' (shared by jason0x43)


    Since 1.5, if the WebDriver server supports remote file uploads, and you type a path to a file on your local computer, that file will be transparently uploaded to the remote server and the remote filename will be typed instead. If you do not want to upload local files, use leadfoot/Session#pressKeys instead.


    Solution (worked for me):


    Sample code:

    function () {
          return this.remote
            .get(require.toUrl('http://www.fileconvoy.com/'))
            .findById('upfile_0')
              // .type('C:\\Users\\hello\\Desktop\\documents\\doc-sample1.doc')
              .type("//tmp//upload.log")
              .end()
            .findById('readTermsOfUse').click().end()
            .findById('upload_button').click().end()
            .sleep(5000)
        }
    

    ----------

    conf.js

      capabilities: {
        fixSessionCapabilities: true,
        remoteFiles: true,
        .
        .
        .
      },