How to start tunnel for automation test in Pytest on LambdaTest
If you want to run your an automation test in Pytest on LambdaTest using the tunnel and want to start the tunnel automatically in the script, you can use the follwing steps. You can refer to sample test repo here.
Go to your LambdaTest dashboard and click the configure tunnel button on the top right corner and use the download link to download the binary file.
In your conftest.py
file, ensure that you have specified the username and accesskey and paste the following code (refer to conftest.py
for full code) :
import subprocess
#start tunnel process
tunnel_process = subprocess.Popen(["./LT","--user",username,"--key",access_key],stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
#leave rest of the configuration untouched
#In the fin function, end the process
def fin():
#browser.execute_script("lambda-status=".format(str(not request.node.rep_call.failed if "passed" else "failed").lower()))
if request.node.rep_call.failed:
browser.execute_script("lambda-status=failed")
else:
browser.execute_script("lambda-status=passed")
browser.quit()
#end tunnel process
tunnel_process.terminate()
Add the following line in conftest.py
:
desired_caps['tunnel'] = True
cd tests //navigate to tests directory
python sample_todo.py