Search code examples
seleniumprotractorbrowserstack

Uploading local files with browserstack using Protractor


I have a simple script which is trying to upload a file directly to my application. This test works fine on my local setup (win10 + chrome 73) however when running through browserstack-local (which as I understand sets up a secure connection to my local machine) I am receiving the following error.

Failed: invalid argument: File not found : C:\correctPath/correctFileName.zip
[Chrome #01]         (Session info: chrome=73.0.3683.86)
[Chrome #01]         (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

I am printing out the following confirmations so I know that the paths are correct.

Code

Which produces

[Chrome #01] File Path: C:\correctPath/correctFileName.zip
[Chrome #01] File exists: true

These are printed before the failure occurs.

Note: I can run tests which do not require uploading files fine.

I am brand new to browserstack so there may be something simple I am missing. Any help or advise would be appreicated.


Answer:

Corey pointed me in the right direction with his answer. I needed to add the following two lines to my onPrepare in my config file and I can upload fine now.

const remote = require('selenium-webdriver/remote');
await browser.setFileDetector(new remote.FileDetector());

Solution

  • see "Local file detector" section at: https://seleniumhq.github.io/docs/remote.html

    Local file detector

    The Local File Detector allows the transfer of files from the client machine to the remote server. For example, if a test needs to upload a file to a web application, a remote WebDriver can automatically transfer the file from the local machine to the remote web server during runtime. This allows the file to be uploaded from the remote machine running the test.