Skip to main content

Upload Files Using LambdaTest Selenium Grid

In Selenium automation testing, you might have come across the need to test the upload functionality on a web app or a website. LambdaTest now allows you to work with upload file functionality on the cloud-based Selenium Grid and test the upload feature on 3000+ browser and OS combinations.

In this document, you will see how you can upload a file on the LambdaTest platform and access it via an automation test script.

How To Upload Files On LambdaTest Platform


You can upload the files on the LambdaTest cloud based Selenium Grid, using our API for uploading user-files. Follow the steps below to learn how:

  • Open LambdaTest's API for uploading user-files Upload file
  • Click on the Lock icon to authorize your account. lock icon]
  • Enter your LambdaTest username and access key, in the box that appears, to validate your credentials. Once done, click on the "Authorise button to verify the credentials, and click on Close to close the window. authorize button

To get your LambdaTest Username and Access Key, visite your LambdaTest automation dashboard and click on the "key" icon, present on the top right corner.

automation key
  • Then click on the "Try it out" button. choose file
  • Once your authorization is successful and you click on the Try it out button, an option to select the file will appear on your screen. Choose the file to be uploaded using the "Choose File" button and click on Execute to upload it on the LambdaTest platform. 200 status code

Note: You can upload multiple files to our lambda storage. A maximum of 150 files can be uploaded per organization. We have limit of 20 MB files size per API. So if you are total file sizes reach the limit, please upload your files in multiple API calls.

Once the file is successfully uploaded, you will see a response body with 200 response code, as shown in the image below: upload file

How To Test The Uploaded File On LambdaTest Platform


Now once the file is uploaded successfully, you can test this file on the LambdaTest platform, to perform automation testing on cloud-based Selenium Grid on over 3000 browser and OS combinations.

To do so, you need to first add the desired capability into your automation script for file upload.

For example: Suppose you uploaded 3 files with name "804402.png", "file_example_JPG_2500kB.jpg", and "Sample_File_To_Upload.txt", then the desired capability to be added will be:

Java

HashSet<String> ab = new HashSet<>();
ab.add("Sample-Spreadsheet-10-rows.csv");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build","Upload");
capabilities.setCapability("name","Upload Files");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("browserVersion","104");
capabilities.setCapability("platformName", "Windows 10");
capabilities.setCapability("lambda:userFiles",ab);

C#

//HashMap
string testName = callStack[0].ToString();
InitCaps
String[] ltFile = new string[] { "file-name.csv" };

// Capabilities
capabilities.AddAdditionalOption("lambda:userFiles", ltFile);

PHP

$capabilities = array(
.
.
"lambda:userFiles" => [
"804402.png",
"file_example_JPG_2500kB.jpg",
"Sample_File_To_Upload.txt"
])

Python

capabilities = {
.
.
"lambda:userFiles" : [
"804402.png",
"file_example_JPG_2500kB.jpg",
"Sample_File_To_Upload.txt"
]
}

JavaScript

var capabilities = {
.
.
"lambda:userFiles" : [
"804402.png",
"file_example_JPG_2500kB.jpg",
"Sample_File_To_Upload.txt"
]
}

Now you can use the files uploaded for your use case in the automation test script.

Shown below is the file path for uploading on both desktop and mobile operating systems.

Operating SystemDefault Download Path
Linux/home/ltuser/Downloads
WindowsC:\Users\ltuser\Downloads
macOS/Users/ltuser/Downloads
Android/storage/emulated/0/Android/data/com.android.chrome/files/Download/
iOS/Users/ltuser/Downloads/ios/media

For example, let's say you want to upload a file on a web page via test script, then the sample Java code for this operation (on Windows and macOS) will be:

   // If the file is 804402.png, and testing environment is Windows OS
WebElement addFile = driver.findElement(By.xpath(".//input[@type='file']"));
addFile.sendKeys("C:\\Users\\ltuser\\Downloads\\804402.png");

// If the file is 804402.png, and testing environment is macOS
WebElement addFile = driver.findElement(By.xpath(".//input[@type='file']"));
addFile.sendKeys("/Users/ltuser/Downloads/804402.png");

That's it! You can now successfully upload files and use them with Selenium Automation testing on LambdaTest's cloud server. If you face any issues, please feel free to reach out to us via our 24/7 chat support, or you can even mail us at support@lambdatest.com
Happy Testing!

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles