0
votes

When I try to upload a.jpg file to my application in the saucelabs virtual test, I get an error.

Using driver.SendKey() to upload the file to the application in the saucelab VM machine. I'm trying to figure out the correct path to get the jpg file from sauce-storage using SendKeys. Please help

code:

{
        IAllowsFileDetection allowsDetection = driver as IAllowsFileDetection;
                        if (allowsDetection != null)
                        {
                            allowsDetection.FileDetector = new LocalFileDetector();
                        }

                        driver.SendKeys(element, "sauce-storage:oldtraford.jpg");
 } 

Error: Test failed with error: OpenQA.Selenium.WebDriverException: unknown error: path is not absolute: sauce-storage:oldtraford.jpg (Session info: chrome=74.0.3729.185) (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-54-generic x86_64) at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Appium.AppiumDriver1.Execute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text) at BST10Web.Framework.UI.Helpers.UiElementHelpers.EnterText(IWebElement element, String value

2
If you are using SauceLabs, you have access to their support. Just file a ticket. - JeffC
I did file a ticket. Thank you - user3354854
This is not something support can fix because it's not officially supported - wswebcreation

2 Answers

0
votes

This is also not possible with the sauce storage. The sauce storage is only accessible before the test starts to provision the machine you want to use (change the register, install an application and so on)

You can't access the storage during a test execution, see also https://wiki.saucelabs.com/display/DOCS/Temporary+Storage+Methods

0
votes

The Problem

Just for the benefit of future requesters, here's why uploading a file on a remotely controlled browser is tricky.

When you select a file to upload in a web form, what's really happening is that you're filling in the value of a file input with the path of the file you want to upload.

That is, you're telling the form where the file lives on your hard drive, and that's it. When you submit the form, the browser goes to your hard drive, finds the file, and sends it to the server.

The browser has to be able to reach the file you're uploading. When your browser runs on the same computer or network as the file, this isn't a problem... But remote browsers aren't on the same computer or network. As far as the browser is concerned, the file you're uploading doesn't exist, and your test fails.

The Solution

You can work around this in Selenium using File Detectors.

A file detector is just a piece of code you give the Selenium driver, that lets it figure out if the value you're sending with the send_keys method is the path to a file. If it thinks it is, the Selenium bindings do the following:

  1. Find the file on the local computer and compress it
  2. Sends the compressed file to a temporary directory on the remote computer
  3. Uncompress the file
  4. Take the file's location on the remote computer, and pass that location to the file input with send_keys

So now, the file is on the same computer as the browser, and the browser knows where to find it. Boom! You can upload your file to your web app.

Sauce Labs' documentation has an example of File Detectors for use with their service.

Fancy File Detectors

Because File Detectors take strings and return file paths, you can also use them to make your code more modular and re-usable.

For instance, if you upload the same spreadsheet from multiple tests, you can create a File Detector that returns that spreadsheet path if it receives the string sheet. Then, if the location of the sheet changes, you only have to update it in the File Detector.

Alternatively, if you need to upload different sized images, you could write a file detector that takes an image size as an input uses imagemagick to create an image of that size.