Skip to main content

Install Custom Certificates on the VM Through Pre-run-executables


Pre-run-executables allow you to run your custom scripts before the selenium test is started. We can use this feature to install user custom certificates that are mandatory for test cases to execute successfully.

To use certificates for selenium tests, we require 3 things:

  • Certificate file.
  • The script that installs the certificate in our Virtual Machine (VM).
  • The script that deletes the certificate in our VM.

Instructionsโ€‹


Upload your certificate file, installation, and uninstallation script using the given curl command. Here's the command:

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-CERTIFICATE-FILE} \
--form pre_run_file=@{PATH-TO-CERTIFIFICATE-INSTALLATION-SCRIPT} \
--form post_run_file=@{PATH-TO-CERTIFICATE-DELETION-SCRIPT} \
--form 'name={NAME-OF-YOUR-PRERUN}'

Note: Replace {TOKEN}, {PATH-TO-CERTIFICATE-FILE}, {PATH-TO-CERTIFICATE-INSTALLATION-SCRIPT}, {PATH-TO-CERTIFICATE-DELETION-SCRIPT}, {NAME-OF-YOUR-PRERUN} with the appropriate value.

Step 1: Wait for the pre-run scripts to be approved by the lambda test team.

Step 2: Pass the prerun key in capability as

"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โ€‹


Here are the prerun APIs:

  • GET/files: Fetch all pre run files uploaded by the user.
  • POST/files: Upload pre run executable file to our lambda storage.
  • DELETE/files/delete: Delete pre run from our lambda storage.
  • POST/files/validate: Check if the file is approved by LambdaTest.
  • PUT/files/download: Download pre run executable file.

Note: To know more about our APIs, check out our API Documentation.

Sample Certificate Installation and Uninstallation File (macOS)โ€‹


  • In install_certificate.sh replace {CERTIFICATE-FILE-NAME} with the certificate file name.
  • In delete_certificate.sh replace {CERTIFICATE-NAME} with the certificate name (You can use the Keychain Access to find the certificate name.)

Following are the contents of the sample file:

For Installing:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Users/ltuser/Downloads/Prerun/{CERTIFICATE-FILE-NAME}

For Deleting:

sudo security delete-certificate -c "Local Certificate"

Sample Certificate Installation and Uninstallation File (Windows)โ€‹


  • In install_certificate.ps1 replace {CERTIFICATE-FILE-NAME} with the certificate file name.
  • In delete_certificate.ps1 replace {CERTIFICATE-NAME} with the certificate name.

Following are the contents of the sample file:

For Installing:

Import-Certificate -FilePath "C:\Users\ltuser\Downloads\Prerun\{NAME-OF-THE-CERTIFICATE}" -CertStoreLocation 'Cert:\LocalMachine\Root' -Verbose

For Deleting:

Get-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 [email protected].