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 2000+ 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: The file to be uploaded must be of maximum size 15 MB and you can select up to 15 files at a time to upload on the LambdaTest platform.

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 LamnbdaTest platform, to perform automation testing on cloud-based Selenium Grid on over 2000 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

capabilities.setCapability("lambda:userFiles", ["804402.png","file_example_JPG_2500kB.jpg","Sample_File_To_Upload.txt"]);

C#

capabilities.SetCapability("lambda:userFiles", ["804402.png","file_example_JPG_2500kB.jpg","Sample_File_To_Upload.txt"]);

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. If the testing environment is a Windows-based OS, then the path to that file will be:

C:\\Users\\ltuser\\Downloads

And if the environment is mac OS based, then the path will be:

/Users/ltuser/Downloads

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 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 Mac OS   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 [email protected]
Happy Testing!

Last updated on