Variables in TestDriver allow you to dynamically store and reuse data during test execution. This feature is particularly useful for handling dynamic content, passing data between steps, and customizing test behavior based on runtime conditions.
Generate a random number or string and use it to fill out a form.
Capture API responses and validate their content.
Capture text or values from the screen and use them in assertions.
Pass different values to the test using environment variables for testing multiple scenarios.
By leveraging variables in TestDriver, you can create dynamic, flexible, and reusable test scripts that adapt to changing conditions and data.
version: 6.0.0steps: - prompt: Generate a random number commands: - command: exec output: randomNumber js: | result = Math.floor(Math.random() * 1000); - command: exec js: | console.log("Generated Random Number: ${OUTPUT.randomNumber}"); - prompt: Use the random number in a form commands: - command: hover-text text: Enter Number description: Input field for numbers action: click - command: type text: ${OUTPUT.randomNumber}
You can run TestDriver in any CI/CD pipeline. Here is an example using the CLI in a generic workflow (adapt for your platform, e.g., GitHub Actions, GitLab CI, CircleCI, Jenkins, etc.):
workflows/testdriver.yml
Copy
Ask AI
steps: - name: Check out repository # For GitHub Actions: uses: actions/checkout@v4 # For GitLab CI: git clone ... - name: Run TestDriver CLI env: TD_API_KEY: ${{ secrets.TD_API_KEY }} TD_USERNAME: ${{ secrets.TD_USERNAME }} TD_PASSWORD: ${{ secrets.TD_PASSWORD }} # Add any other required environment variables run: | npx testdriverai@latest run testdriver/login.yaml
Now inside the login.yaml test file you can refer the variables
login.yaml
Copy
Ask AI
version: 6.0.0steps: - prompt: Open the homepage commands: - command: hover-text text: Login description: Login button in the top-right corner action: click - prompt: Verify the login form is displayed commands: - command: assert expect: The login form is displayed - prompt: Enter credentials and submit commands: - command: hover-text text: Email description: Email input field action: click - command: type text: ${TD_USERNAME} - command: hover-text text: Password description: Password input field action: click - command: type text: ${TD_PASSWORD} - command: hover-text text: Submit description: Submit button action: click