---
title: "Electron"
sidebarTitle: "Electron"
description: "Integrate TestDriver with Electron applications"
icon: "atom"
---

To integrate **TestDriver** with a workflow that uses the **runner artifact URL** and **GitHub token** for downloading artifacts, you can modify the workflow to include these steps. Below is an example of how to adapt the workflow to ensure TestDriver can access the artifacts.

---

## Updated workflow with TestDriver integration

This workflow builds the application, uploads the build as an artifact, and then uses TestDriver to download the artifact via the runner artifact URL and run tests.

### Workflow file

```yaml .github/workflows/testdriver-integration.yaml
name: Build and Test with TestDriver

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

jobs:
  build:
    name: Build Application
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Install dependencies
        run: npm install

      - name: Build Application
        run: npm run build # Ensure your project has a build script

      - name: Upload Build Artifact
        uses: actions/upload-artifact@v3
        with:
          name: app-build
          path: dist/ # Replace with the path to your built application

  test:
    name: Test Application with TestDriver
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Get Artifact URL
        id: artifact-url
        run: |
          echo "ARTIFACT_URL=${{ github.server_url }}/repos/${{ github.repository }}/actions/artifacts" >> $GITHUB_ENV

      - name: Run TestDriver CLI
        run: |
          npx testdriverai@latest run testdriver/test.yaml
        env:
          TD_API_KEY: ${{ secrets.TD_API_KEY }}
          ARTIFACT_URL: ${{ env.ARTIFACT_URL }}
          FORCE_COLOR: "3"
```

---

## Using lifecycle files for Electron apps

To ensure your Electron app is downloaded and run in the correct environment, use TestDriver's lifecycle files:

- **lifecycle/provision.yaml**: Download and extract the Electron app artifact here.
- **lifecycle/prerun.yaml**: Start your Electron app here before the test begins.

### Example:

```yaml testdriver/lifecycle/provision.yaml
version: 6.0.0
steps:
  - prompt: Download Electron app artifact
    commands:
      - command: exec
        lang: pwsh
        code: |
          Write-Host "Downloading artifact..."
          curl -H "Authorization: Bearer ${GITHUB_TOKEN}" \
          -L "${ARTIFACT_URL}" \
          --output artifact.zip
        echo "Extracting artifact..."
        unzip artifact.zip -d ./app
```

---

```yaml testdriver/lifecycle/prerun.yaml
version: 6.0.0
steps:
  - prompt: Start Electron app
    commands:
      - command: exec
        lang: pwsh
        code: |
          Start-Process -FilePath "./app/your-app-binary" # Replace with the actual binary or executable path
```

---

## Key changes and explanation

### 1. **Artifact URL Retrieval**

The `Get Artifact URL` step constructs the artifact URL dynamically using the GitHub repository and server URL. This value is passed to the lifecycle files as an environment variable.

### 2. **Downloading and running the app in lifecycle files**

- Download and extract the Electron app in `lifecycle/provision.yaml`.
- Start the Electron app in `lifecycle/prerun.yaml`.
- The TestDriver CLI will then execute your tests against the running app.

---

## Secrets configuration

Add the following secrets to your GitHub repository:

1. **`TD_API_KEY`**: Your TestDriver API key.
2. **`GITHUB_TOKEN`**: Automatically provided by GitHub Actions for authentication.

---

## Benefits of this workflow

1. **Dynamic Artifact Access**: Ensures TestDriver can download artifacts directly from the runner.
2. **Automated Testing**: Integrates TestDriver to validate the application after the build.
3. **Secure Authentication**: Uses the GitHub token for secure artifact access.
4. **Cross-Platform Support**: Can be adapted for different operating systems and environments.

---

By integrating TestDriver with the runner artifact URL and GitHub token, and using lifecycle files, this workflow ensures seamless and secure testing of your Electron application builds.
