GitHub Integration
This guide shows you how to integrate TestivAI with GitHub Actions for automated visual testing in your CI/CD pipeline.
Prerequisites
- A TestivAI account (sign up at dashboard.testiv.ai)
- A GitHub repository
- Admin access to the repository (for adding secrets)
Step 1: Get Your API Key
- Log in to the TestivAI Dashboard
- Navigate to Settings → API Keys
- Click Generate New API Key
- Give it a descriptive name (e.g., "GitHub Actions")
- Copy the API key - you won't be able to see it again
Step 2: Add API Key to GitHub Secrets
- In your GitHub repository, go to Settings → Secrets and variables → Actions
- Click New repository secret
- Name it
TESTIVAI_API_KEY - Paste the API key you copied
- Click Add secret
Security Best Practice
Never commit your API key to your repository. Always use GitHub Secrets to keep it secure.
Step 3: Configure Your Workflow
Create a new file at .github/workflows/testivai.yml in your repository:
Basic Example
name: Visual Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
visual-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Install TestivAI CLI
run: npm install -g @testivai/cli
- name: Authenticate TestivAI
run: testivai auth
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
- name: Run visual tests
run: testivai run "npm test"
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Framework-Specific Examples
Playwright
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Run visual tests
run: npx playwright test
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Cypress
- name: Run visual tests
run: testivai run "cypress run --browser chrome --headless"
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Selenium (JavaScript)
- name: Run visual tests
run: testivai run "npx jest tests/"
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Selenium (Python)
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run visual tests
run: testivai run "pytest tests/ -v"
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Selenium (Java)
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Run visual tests
run: testivai run "mvn test"
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Step 4: Optional - Set Up Webhooks
For automatic test runs when you push changes:
- In the TestivAI Dashboard, go to Project Settings
- Find the Webhook URL (it looks like:
https://api.testiv.ai/webhooks/github/{project-id}) - In your GitHub repository, go to Settings → Webhooks
- Click Add webhook
- Paste the webhook URL
- Select:
- Content type:
application/json - Which events would you like to trigger this webhook?:
- Pushes
- Pull requests
- Content type:
- Click Add webhook
Advanced Configuration
Custom Baseline Branch
To control which branch is used for baselines:
- name: Run visual tests
run: |
if [[ $GITHUB_REF == refs/heads/main ]]; then
testivai run "npm test" --baseline main
else
testivai run "npm test" --baseline main
fi
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Parallel Execution
For faster test runs with multiple shards:
jobs:
visual-tests:
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
# ... setup steps ...
- name: Run visual tests (shard ${{ matrix.shard }})
run: npx playwright test --shard=${{ matrix.shard }}/4
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Conditional Testing
Run visual tests only on specific paths:
- name: Detect changes
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
visual:
- 'src/**/*.css'
- 'src/**/*.scss'
- 'src/components/**/*'
- 'pages/**/*'
- name: Run visual tests
if: steps.changes.outputs.visual == 'true'
run: npx playwright test
env:
TESTIVAI_API_KEY: ${{ secrets.TESTIVAI_API_KEY }}
Troubleshooting
API Key Not Working
- Verify the secret name is exactly
TESTIVAI_API_KEY - Check that the API key hasn't expired
- Ensure the key has the correct permissions for the project
Tests Fail in CI
- Make sure you're running tests in headless mode
- Check browser dependencies are installed
- Verify the TestivAI CLI is installed globally or locally
Permission Denied Errors
- name: Fix permissions
run: chmod +x node_modules/.bin/testivai
Slow Test Runs
- Use the
--parallelflag for supported frameworks - Consider using GitHub Actions caching
- Optimize your test suite to run only what's needed
Best Practices
- Always use GitHub Secrets for API keys
- Pin your dependencies to ensure consistent runs
- Use matrix builds for parallel execution
- Cache dependencies between runs
- Run tests on PRs to catch issues early
- Set status checks to prevent merging failing visual tests
Status Checks Example
- name: Check visual test results
run: |
if [ $? -ne 0 ]; then
echo "Visual tests failed!"
echo "Check the TestivAI dashboard for details"
exit 1
fi
Need Help?
- Check our Troubleshooting Guide
- Visit our Documentation
- Contact support at hello@testiv.ai