Authentication in TestDriver
Learn how to securely handle authentication workflows in TestDriver using GitHub Actions.
This guide explains how to handle authentication workflows in TestDriver using GitHub Actions. It covers securely passing credentials (for example, usernames and passwords) to the TestDriver action and using them in both the prerun
script and test files. Save these locally in your .env
file and use them in CI as GitHub secrets.
Always remember to add a .gitignore
file to your repository including a .env
line so you never accidentally commit you TestDriver API key.
This is important for security and to prevent exposing sensitive information. For more info see GitHub Docs.
How authentication works in TestDriver
- Store Credentials Securely:
- Use GitHub Secrets to store sensitive information like usernames, passwords, or API keys.
- Pass Credentials to the Workflow:
- Supply credentials as environment variables or directly in the workflow.
- Use Credentials in Tests:
- Dynamically reference credentials in the
prerun
script or test files to perform authentication steps.
store credentials in GitHub secrets
- Navigate to your repository’s Settings > Secrets and variables > Actions.
- Add the following secrets:
TD_USERNAME
: The username for login.TD_PASSWORD
: The password for login.TD_API_KEY
: Your TestDriver API key.TD_WEBSITE
: The URL of the website to test.
Step 2: Pass credentials to the workflow
Secrets are passed to the GitHub Action using the secrets
context. They can be supplied as:
- Environment Variables: Passed via the
env
block. - Inline in the
prerun
Script: Used directly in the script.
Example workflow
Step 3: Use credentials in test files
Secrets can be referenced in the test file using placeholders (for example, ${TD_USERNAME}
and ${TD_PASSWORD}
).
Example test file:
How it works together
- Secrets in the Workflow:
- Secrets like
TD_USERNAME
andTD_PASSWORD
are passed as environment variables to the TestDriver action.
- Secrets in the
prerun
Script:
- The
TD_WEBSITE
secret is used to launch the browser with the correct URL.
- Secrets in the Test File:
- The test file dynamically references the secrets to fill in login credentials during the test.
Benefits of using authentication in TestDriver
- Secure Handling of Credentials:
- Secrets are encrypted and not exposed in logs.
- Even if printed, they appear as
***
.
- Dynamic Testing:
- Easily switch between different environments (for example, staging, production) by updating the secrets.
- Reusability:
- Use the same workflow and test files across multiple repositories or environments.
By securely passing credentials and using them in the prerun
script and test files, you can automate authentication workflows in TestDriver while ensuring sensitive information remains protected.