| 
 | 1 | +# How to upload file on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=Pytest-upload-file) for automation test in Pytest   | 
 | 2 | + | 
 | 3 | +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](https://github.com/LambdaTest/pytest-selenium-sample).  | 
 | 4 | + | 
 | 5 | +# Steps:  | 
 | 6 | + | 
 | 7 | +### Step 1: Upload the file to LamdbaTest using API  | 
 | 8 | + | 
 | 9 | +Use the LambdaTest file upload API to upload the file to the backend -https://api.lambdatest.com/automation/api/v1/user-files  | 
 | 10 | + | 
 | 11 | + | 
 | 12 | +### Step 2: Pass file in capabilities  | 
 | 13 | + | 
 | 14 | +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:  | 
 | 15 | + | 
 | 16 | +```  | 
 | 17 | +capabilities = {  | 
 | 18 | + "build": "Sample PY Build",  | 
 | 19 | + "platformName": "Windows 11",  | 
 | 20 | + "browserName": "Chrome",  | 
 | 21 | + "browserVersion": "latest",  | 
 | 22 | +		"lambda:userFiles": ["photo1.png","photo2.png"]  | 
 | 23 | +}  | 
 | 24 | +```  | 
 | 25 | + | 
 | 26 | +### Step 3: Use the file in your test  | 
 | 27 | + | 
 | 28 | +The files can be used in your test like so:  | 
 | 29 | + | 
 | 30 | +* For Windows:  | 
 | 31 | +```python  | 
 | 32 | +elm = driver.find_element_by_xpath("//input[@type='file']")  | 
 | 33 | +elm.send_keys("C:\\Users\\ltuser\\Downloads\\photo1.png")  | 
 | 34 | +```  | 
 | 35 | +* For MacOS:  | 
 | 36 | +```python  | 
 | 37 | +elm = driver.find_element_by_xpath("//input[@type='file']")  | 
 | 38 | +elm.send_keys("/Users/ltuser/Downloads/photo1.png")  | 
 | 39 | +```  | 
 | 40 | +### Step 4: Run your test  | 
 | 41 | + | 
 | 42 | +```bash  | 
 | 43 | +cd tests //navigate to tests directory  | 
 | 44 | +python sample_todo.py  | 
 | 45 | +```  | 
 | 46 | + | 
 | 47 | +# Links:  | 
 | 48 | + | 
 | 49 | +[LambdaTest Community](http://community.lambdatest.com/)  | 
 | 50 | + | 
0 commit comments