How to Run a Pre-Test Executable on TestMu AI
Pre-run executables let you run custom scripts before the Selenium test starts. Use this feature to install user custom certificates that are required for test cases to execute successfully.
To use certificates for Selenium tests, you need 3 things:
- Certificate file.
- The script that installs the certificate in the Virtual Machine (VM).
- The script that deletes the certificate in the VM.
Instructions
Upload your certificate file, installation, and uninstallation script using the below steps. The prerun and lambda:userFiles keys shown here are part of the broader set of Selenium automation capabilities you can pass to a test.
- Upload your certificate using the below command.
curl --location --request POST '<https://api.lambdatest.com/automation/api/v1/user-files>'
- Install the certificate on macOS using the following command.
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Users/ltuser/Downloads/{CERTIFICATE-FILE-NAME}
- Install the certificate on Windows using the below command.
Import-Certificate -FilePath "C:\Users\ltuser\Downloads\{NAME-OF-THE-CERTIFICATE}" -CertStoreLocation 'Cert:\LocalMachine\Root' -Verbose
- Use the following cURL request to upload pre and post run files altogether.
curl --request POST \
--url <https://api.lambdatest.com/automation/api/v1/files> \
--header 'Authorization: Basic {TOKEN}' \
--header 'Content-Type: multipart/form-data' \
--header 'cache-control: no-cache,no-cache,no-cache' \
--header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
--form pre_run_file=@{PATH-TO-CERTIFIFICATE-INSTALLATION-SCRIPT} \
--form post_run_file=@{PATH-TO-CERTIFICATE-DELETION-SCRIPT} \
--form 'name={NAME-OF-YOUR-PRERUN}'
- Run the below capabilities to use the certificate, pre, and post run files in a test.
"lambda:userFiles": ["certificate.p12"],
"prerun": {
"accessKey": "****",
"background": False,
"filePath": "<organization-id>/uploads/install_certificate.ps1",
"postAction": {
"filePath": "xyz/post/delete_certificate.ps1",
"url": "<https://api.lambdatest.com/automation/api/v1/files/download>"
},
"url": "<https://api.lambdatest.com/automation/api/v1/files/download>",
"user": "****"
},
Note: Replace
{TOKEN},{PATH-TO-CERTIFICATE-FILE},{PATH-TO-CERTIFICATE-INSTALLATION-SCRIPT},{PATH-TO-CERTIFICATE-DELETION-SCRIPT},{NAME-OF-YOUR-PRERUN}with the appropriate values.
-
After uploading your pre-run script, reach out to us via chat support or email to get the scripts approved.
-
Once your script is approved, pass the
prerunkey in the capability as follows:
"prerun": {
"url": "{NAME-OF-YOUR-PRERUN}/pre/{NAME-OF-YOUR-CERTIFICATE-INSTALLATION-SCRIPT}",
},
Note: Replace
{NAME-OF-YOUR-PRERUN}as provided in Step 1 and{NAME-OF-YOUR-CERTIFICATE-INSTALLATION-FILE-NAME}with the name of the certificate installation script that you uploaded in Step 1.
Leverage the Use of APIs to Pre-run Tests
Use the following prerun APIs to manage pre-run files. If you are still setting up your environment, first learn how to run your first Selenium test before adding pre-run scripts to the flow.
- GET/
files: Fetch all pre run files uploaded by the user. - POST/
files: Upload pre run executable file to lambda storage. - DELETE/
files/delete: Delete pre run from lambda storage. - POST/
files/validate: Check if the file is approved by TestMu AI. - PUT/
files/download: Download pre run executable file.
Note: To learn more about our APIs, check out our API Documentation.
Sample Certificate Installation and Uninstallation File (macOS)
Replace the placeholder values in each script file before use.
- In
install_certificate.shreplace{CERTIFICATE-FILE-NAME}with the certificate file name. - In
delete_certificate.shreplace{CERTIFICATE-NAME}with the certificate name (use Keychain Access to find the certificate name).
Following are the contents of the sample file:
For Installing:
Verifiedsudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Users/ltuser/Downloads/{CERTIFICATE-FILE-NAME}
For Deleting:
Verifiedsudo security delete-certificate -c "Local Certificate"
Sample Certificate Installation and Uninstallation File (Windows)
Replace the placeholder values in each script file before use.
- In
install_certificate.ps1replace{CERTIFICATE-FILE-NAME}with the certificate file name. - In
delete_certificate.ps1replace{CERTIFICATE-NAME}with the certificate name.
Following are the contents of the sample file:
For Installing:
VerifiedImport-Certificate -FilePath "C:\Users\ltuser\Downloads\{NAME-OF-THE-CERTIFICATE}" -CertStoreLocation 'Cert:\LocalMachine\Root' -Verbose
For Deleting:
VerifiedGet-ChildItem Cert:\CurrentUser\Root\{THUMBPRINT-OF-THE-CERTIFICATE} | Remove-Item
Got any questions?
Please reach out at our 24x7 Chat Support or you could also mail us at support@testmuai.com.
Next Steps
Continue with these related guides:
