Prerun Scripts

How to provision the VM and build your app before running TestDriver

Prerun scripts are Bash commands executed on a TestDriver VM before each test within a CI/CD pipeline. Their primary purpose is to establish the state of a machine. This ensure it is consistent before every test execution.

You can configure prerun script to install necessary dependencies, build your application, set specific configurations, and more.

This crucial step helps to speed up the setup of an environment, prepare for a test suite to run, and prevent test failures due to environment inconsistencies and promote reproducible builds, ultimately enhancing the overall test suite's effectiveness.

Example

This is an example of how to download Arc Browser and use it instead of Chrome.

name: TestDriver.ai Regression Testing - Waveterm
on:
    push:
        branches:
            - main
    pull_request:
        branches:
            - main
    schedule:
        - cron: 0 21 * * *
    workflow_dispatch: null

permissions:
    contents: read # To allow the action to read repository contents
    pull-requests: write # To allow the action to create/update pull request comments

jobs:
  test:
    name: "TestDriver"
    runs-on: ubuntu-latest
    steps:    
    # Download an exe for this test
    - uses: testdriverai/action@main
      with:
        key: ${{ secrets.TESTDRIVER_API_KEY }}
        prompt: | 
          1. /run testdriver/${{ matrix.test }} 
        prerun: |
          Get-NetIPAddress -AddressFamily IPv6
          # URL for the Arc browser installer
          $installerUrl = "https://releases.arc.net/windows/ArcInstaller.exe"
          # Location to save the installer
          $installerPath = "$env:USERPROFILE\Downloads\ArcInstaller.exe"
          # Download the Arc browser installer
          Write-Host "Downloading Arc browser installer..."
          Invoke-WebRequest -Uri $installerUrl -OutFile $installerPath
          # Check if the download was successful
          if (Test-Path $installerPath) {
              Write-Host "Download successful. Running the installer..."
              Start-Process -FilePath $installerPath -ArgumentList '/silent' -Wait
              Start-Sleep -Seconds 10
          } else {
              Write-Host "Failed to download the Arc browser installer."
          }
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        FORCE_COLOR: "3"

Last updated

Was this helpful?