tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with Azure storage support
477 lines (368 loc) ⢠13.1 kB
Markdown
# tdpw
[](https://www.npmjs.com/package/tdpw)
[](https://nodejs.org/)
[](https://opensource.org/licenses/MIT)
[](https://www.npmjs.com/package/tdpw)
> š¦ **TestDino CLI** - Upload Playwright test reports to TestDino platform with Azure storage support
## š Quick Start
```bash
# Install and run in one command (recommended)
npx tdpw ./playwright-report --token="your-api-token"
# With HTML report upload
npx tdpw ./playwright-report --token="your-token" --upload-html
# Full features with traces and verbose output
npx tdpw ./test-results --upload-html --upload-traces --verbose
```
## š¦ Installation
### NPX (Recommended - No Installation Required)
```bash
npx tdpw ./your-report-directory --token="your-token"
```
### Global Installation
```bash
npm install -g tdpw
tdpw ./your-report-directory --token="your-token"
```
### Project Dependency
```bash
npm install --save-dev tdpw
# Add to package.json scripts
{
"scripts": {
"upload-reports": "tdpw ./playwright-report --token=\"$TESTDINO_TOKEN\""
}
}
```
## šÆ Features
- ā
**Zero Configuration** - Auto-discovers Playwright reports (`report.json`, `results.json`)
- ā
**Smart File Discovery** - Finds HTML reports and trace files automatically
- ā
**Azure Storage Integration** - Uploads HTML reports and traces to Azure Blob Storage
- ā
**CI/CD Ready** - Works seamlessly with GitHub Actions, GitLab CI, Jenkins, Azure DevOps
- ā
**Secure Authentication** - Token-based API authentication with validation
- ā
**Progress Tracking** - Real-time upload progress with spinners and percentages
- ā
**Robust Error Handling** - Comprehensive retry logic and graceful fallbacks
- ā
**Environment Detection** - Automatically detects CI/CD context and system information
- ā
**Metadata Collection** - Gathers Git, CI, and system metadata automatically
## š Usage
### Basic Usage
```bash
# Upload JSON report only
npx tdpw ./playwright-report --token="trx_development_..."
# Upload with HTML report (includes all assets: screenshots, CSS, JS)
npx tdpw ./playwright-report --token="trx_development_..." --upload-html
# Upload everything including trace files
npx tdpw ./playwright-report --token="trx_development_..." --upload-html --upload-traces
```
### Command Options
| Option | Description | Default |
|--------|-------------|---------|
| `<report-directory>` | Directory containing Playwright reports | Required |
| `-t, --token <value>` | TestDino API token | Required |
| `--upload-html` | Upload HTML reports to Azure storage | `false` |
| `--upload-traces` | Upload trace files to Azure storage | `false` |
| `--json-report <path>` | Specific JSON report file path | Auto-detected |
| `--html-report <path>` | Specific HTML report directory path | Auto-detected |
| `--trace-dir <path>` | Specific trace files directory path | Auto-detected |
| `-v, --verbose` | Enable verbose logging for debugging | `false` |
| `--dry-run` | Validate configuration without uploading | `false` |
| `-h, --help` | Display help information | - |
| `--version` | Show version number | - |
### Environment Variables
Avoid passing sensitive tokens in command line by using environment variables:
```bash
# Set once in your environment
export TESTDINO_TOKEN="trx_development_your_token_here"
export TESTDINO_UPLOAD_HTML="true"
export TESTDINO_UPLOAD_TRACES="true"
# Use without exposing token
npx tdpw ./playwright-report --verbose
```
**Supported Environment Variables:**
- `TESTDINO_TOKEN` - API authentication token
- `TESTDINO_UPLOAD_HTML` - Upload HTML reports (`true`/`false`)
- `TESTDINO_UPLOAD_TRACES` - Upload trace files (`true`/`false`)
- `TESTDINO_VERBOSE` - Enable verbose logging (`true`/`false`)
- `TESTDINO_API_URL` - Custom API endpoint (development only)
## š§ CI/CD Integration
### GitHub Actions
```yaml
name: Playwright Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- name: Upload test results to TestDino
if: always() # Upload even if tests fail
run: npx tdpw ./playwright-report --token="${{ secrets.TESTDINO_TOKEN }}" --upload-html --upload-traces
```
### GitLab CI
```yaml
image: node:18
stages:
- test
- upload
playwright-tests:
stage: test
script:
- npm ci
- npx playwright install --with-deps
- npx playwright test
artifacts:
when: always
paths:
- playwright-report/
expire_in: 1 week
upload-results:
stage: upload
script:
- npx tdpw ./playwright-report --token="$TESTDINO_TOKEN" --upload-html --upload-traces
dependencies:
- playwright-tests
when: always
```
### Jenkins Pipeline
```groovy
pipeline {
agent any
tools {
nodejs '18'
}
environment {
TESTDINO_TOKEN = credentials('testdino-token')
}
stages {
stage('Install') {
steps {
sh 'npm ci'
sh 'npx playwright install --with-deps'
}
}
stage('Test') {
steps {
sh 'npx playwright test'
}
post {
always {
archiveArtifacts artifacts: 'playwright-report/**/*'
}
}
}
stage('Upload Results') {
steps {
sh 'npx tdpw ./playwright-report --token="$TESTDINO_TOKEN" --upload-html --upload-traces'
}
}
}
}
```
### Azure DevOps
```yaml
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
TESTDINO_TOKEN: $(TestDinoToken) # Set in Azure DevOps variables
steps:
- task: NodeTool@0
inputs:
versionSpec: '18'
- script: |
npm ci
npx playwright install --with-deps
displayName: 'Install dependencies'
- script: npx playwright test
displayName: 'Run Playwright tests'
continueOnError: true
- script: |
npx tdpw ./playwright-report --token="$(TESTDINO_TOKEN)" --upload-html --upload-traces
displayName: 'Upload test results'
condition: always()
```
## š Authentication
### API Token Format
TestDino API tokens follow this format:
```
trx_{environment}_{64-character-hex-string}
```
**Examples:**
- `trx_development_a1b2c3d4e5f6...` (Development environment)
- `trx_staging_x1y2z3a4b5c6...` (Staging environment)
- `trx_production_m1n2o3p4q5r6...` (Production environment)
### Getting Your Token
1. Sign up at [TestDino](https://app.testdino.com)
2. Navigate to **Settings** ā **API Tokens**
3. Generate a new token for your desired environment
4. Store it securely in your CI/CD secrets or environment variables
**ā ļø Security Best Practices:**
- Never commit tokens to version control
- Use environment variables or CI/CD secrets
- Rotate tokens regularly
- Use development tokens for local testing
## š File Discovery
The CLI automatically discovers Playwright reports in standard locations:
### JSON Reports (Required)
The CLI looks for JSON reports in this order:
1. `./playwright-report/report.json` (default Playwright location)
2. `./playwright-report/results.json`
3. `./test-results/results.json`
4. `./results.json`
5. Custom path via `--json-report <path>`
### HTML Reports (Optional)
Looks for directories containing `index.html`:
1. `./playwright-report/` (if contains `index.html`)
2. `./html-report/`
3. `./test-report/`
4. Custom path via `--html-report <path>`
### Trace Files (Optional)
Looks for directories containing trace files (`.zip`):
1. `./playwright-report/trace/`
2. `./test-results/`
3. `./traces/`
4. Custom path via `--trace-dir <path>`
**š” Manual Override**: Use CLI flags to specify exact paths if auto-discovery fails.
## šØ Error Handling & Troubleshooting
### Common Issues
#### Invalid Token Format
```bash
ā Validation Error: Invalid API token format
š” Expected format: trx_{environment}_{64-char-hex}
```
**Solution**: Verify your token format and environment.
#### No Reports Found
```bash
ā File System Error: No JSON report found in ./playwright-report
š” Use --json-report <path> to specify exact location
```
**Solution**: Check report directory or use manual path override.
#### Network/Upload Errors
```bash
ā Network Error: Failed to connect to TestDino API
š” Check your internet connection and API endpoint
```
**Solution**: Verify network connectivity and token validity.
#### File Type Restrictions
```bash
ā ļø Skipped: file.md - file type 'md' not allowed
```
**Solution**: Only supported file types are uploaded (html, css, js, png, jpg, zip, json).
### Exit Codes
| Code | Description | Meaning |
|------|-------------|---------|
| `0` | Success | Upload completed successfully |
| `1` | General error | Configuration or validation error |
| `2` | Authentication error | Invalid or expired API token |
| `3` | File not found | Required files missing |
| `4` | Network error | Connection or API issues |
### Debug Mode
Enable detailed logging for troubleshooting:
```bash
# Verbose mode
npx tdpw ./playwright-report --token="..." --verbose
# Debug mode (most detailed)
LOG_LEVEL=debug npx tdpw ./playwright-report --token="..." --verbose
# Dry run (validate without uploading)
npx tdpw ./playwright-report --token="..." --dry-run --verbose
```
## š Examples
### Basic Upload
```bash
npx tdpw ./playwright-report --token="trx_development_abc123"
```
### Full Upload with All Features
```bash
npx tdpw ./playwright-report \
--token="trx_production_xyz789" \
--upload-html \
--upload-traces \
--verbose
```
### Custom Paths
```bash
npx tdpw ./custom-dir \
--json-report ./custom-dir/my-results.json \
--html-report ./custom-dir/html-output \
--trace-dir ./custom-dir/traces \
--token="$TESTDINO_TOKEN"
```
### Environment Variables
```bash
# Set environment variables
export TESTDINO_TOKEN="trx_development_abc123"
export TESTDINO_UPLOAD_HTML="true"
export TESTDINO_UPLOAD_TRACES="true"
# Simple command
npx tdpw ./playwright-report
```
## š Performance
### Typical Upload Times
| Report Size | File Count | Upload Time | Notes |
|-------------|------------|-------------|-------|
| Small | < 20 files | < 10s | JSON + few screenshots |
| Medium | 20-100 files | 10-30s | HTML + screenshots + traces |
| Large | 100+ files | 30s-2min | Full report with many traces |
### Optimization Tips
1. **Selective uploads**: Only upload HTML/traces when needed for debugging
2. **Use environment variables**: Avoid command-line token exposure
3. **Parallel CI jobs**: Upload reports from different test shards in parallel
4. **Conditional uploads**: Only upload on failure or specific branches
```yaml
# Example: Only upload on test failure
- name: Upload test results on failure
if: failure()
run: npx tdpw ./playwright-report --token="$TESTDINO_TOKEN" --upload-html --upload-traces
```
## š Support & Contributing
### Getting Help
- š **Documentation**: [docs.testdino.com](https://docs.testdino.com)
- š **Issues**: [GitHub Issues](https://github.com/testdino/playwright-cli/issues)
- š¬ **Discussions**: [GitHub Discussions](https://github.com/testdino/playwright-cli/discussions)
- š§ **Email**: support@testdino.com
### Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes and add tests
4. Ensure all tests pass: `npm test`
5. Lint your code: `npm run lint`
6. Commit with conventional commits: `git commit -m "feat: add amazing feature"`
7. Push to your fork: `git push origin feature/amazing-feature`
8. Open a Pull Request
### Development Setup
```bash
# Clone the repository
git clone https://github.com/testdino/playwright-cli.git
cd playwright-cli
# Install dependencies
npm install
# Run in development mode
npm run dev -- ./test-data --token="your-dev-token" --dry-run
# Build the project
npm run build
# Test the built CLI
node dist/cli/index.js --help
```
## š License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## š Roadmap
- [ ] Multi-project support
- [ ] Custom report formatters
- [ ] Advanced filtering options
- [ ] Real-time upload progress with ETA
- [ ] Report comparison features
- [ ] Integration with more CI platforms
- [ ] Performance optimizations for large reports
- [ ] Incremental uploads for faster CI/CD
---
**Made with ā¤ļø by the [TestDino](https://testdino.com) team**