How to upload file on LambdaTest for automation test in Pytest
If you want to upload a file to the LambdaTest and use it in your Pytest automation test, you can follow the below steps. You can refer to sample test repo here.
Use the LambdaTest file upload API to upload the file to the backend -https://api.lambdatest.com/automation/api/v1/user-files
In the conftest.py
file, 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:
capabilities = {
"build": "Sample PY Build",
"platformName": "Windows 11",
"browserName": "Chrome",
"browserVersion": "latest",
"lambda:userFiles": ["photo1.png","photo2.png"]
}
The files can be used in your test like so:
- For Windows:
elm = driver.find_element_by_xpath("//input[@type='file']")
elm.send_keys("C:\\Users\\ltuser\\Downloads\\photo1.png")
- For MacOS:
elm = driver.find_element_by_xpath("//input[@type='file']")
elm.send_keys("/Users/ltuser/Downloads/photo1.png")
cd tests //navigate to tests directory
python sample_todo.py