How to upload file for automation tests with Mocha.js on LambdaTest cloud?
Hello Joe,
To upload a file in Mocha.js Testing for automation on Lambdatest cloud,you can download and use the below snippet code:
Step 1: Upload the file to LamdbaTest using API
Use the LambdaTest file upload API to upload the file to the backend -https://api.lambdatest.com/automation/api/v1/user-files
Step 2: Pass file in capabilities
In theconf/single.conf.jsfile, you need to update the test capabilities and add the filename for the lambda:userFiles capability. For example, if two files with filenames photo1.png and photo2.png, it has to be passed like so in the capability:
exports.capabilities = {
'build': 'Mocha-Selenium-Sample', //Build name
'name': 'Your Test Name', // Test name
'platform':'Windows 10', // OS name
'browserName': 'chrome', // Browser name
'version': 'latest', // Browser version
'visual': false, // To take step by step screenshot
'network':false, // To capture network Logs
'console':false, // To capture console logs.
'tunnel': false, // If you want to run the localhost than change it to true
"lambda:userFiles": ["photo1.png","photo2.png"],
};
Step 3: Use the file in your test
The files can be used in your test like so:
- For Windows:
driver.findElement(By.xpath("//input[@type='file']").sendKeys("C:\\Users\\ltuser\\Downloads\\photo1.png")
- For MacOS:
driver.findElement(By.xpath("//input[@type='file']").sendKeys("/Users/ltuser/Downloads/photo1.png")
Here’s the GitHub repo for the same: https://github.com/rshmimondal/Mocha-js-upload-file