-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
187 lines (154 loc) · 5.55 KB
/
action.yml
File metadata and controls
187 lines (154 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: 'TestAgent UI Testing'
description: 'Automatically generate and run UI tests for your web application using AI'
author: 'TestAgent Team'
branding:
icon: 'check-circle'
color: 'green'
inputs:
url:
description: 'URL of the web application to test'
required: false
default: ''
base-url:
description: 'Base URL for relative path testing'
required: false
default: ''
config-file:
description: 'Path to TestAgent configuration file'
required: false
default: 'config.yml'
google-api-key:
description: 'Google Gemini API key for test generation'
required: true
openai-api-key:
description: 'OpenAI API key (alternative to Google)'
required: false
test-timeout:
description: 'Timeout for each test in seconds'
required: false
default: '60'
max-tests:
description: 'Maximum number of tests to generate'
required: false
default: '10'
browser:
description: 'Browser to use for testing (chromium, firefox, webkit)'
required: false
default: 'chromium'
headless:
description: 'Run browser in headless mode'
required: false
default: 'true'
fail-on-test-failure:
description: 'Fail the action if tests fail'
required: false
default: 'true'
upload-artifacts:
description: 'Upload test results and screenshots as artifacts'
required: false
default: 'true'
comment-on-pr:
description: 'Comment test results on the PR'
required: false
default: 'true'
outputs:
tests-passed:
description: 'Number of tests that passed'
tests-failed:
description: 'Number of tests that failed'
total-tests:
description: 'Total number of tests run'
test-results-url:
description: 'URL to view detailed test results'
coverage-report:
description: 'UI coverage report'
runs:
using: 'composite'
steps:
- name: Checkout TestAgent
uses: actions/checkout@v4
with:
repository: 'abalakrishnan1/testagent'
path: '.testagent'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install TestAgent dependencies
shell: bash
run: |
cd .testagent
pip install -r requirements.txt
playwright install ${{ inputs.browser }}
- name: Run TestAgent
shell: bash
env:
GOOGLE_API_KEY: ${{ inputs.google-api-key }}
OPENAI_API_KEY: ${{ inputs.openai-api-key }}
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.number }}
REPOSITORY: ${{ github.repository }}
run: |
cd .testagent
python main.py \
--config="${{ github.workspace }}/${{ inputs.config-file }}" \
--url="${{ inputs.url }}" \
--browser="${{ inputs.browser }}" \
--headless="${{ inputs.headless }}" \
--timeout="${{ inputs.test-timeout }}" \
--max-tests="${{ inputs.max-tests }}" \
--output-format=github-action
- name: Upload test artifacts
if: ${{ inputs.upload-artifacts == 'true' }}
uses: actions/upload-artifact@v3
with:
name: testagent-results
path: .testagent/results/
- name: Comment on PR
if: ${{ inputs.comment-on-pr == 'true' && github.event_name == 'pull_request' }}
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const path = '.testagent/results/summary.json';
if (fs.existsSync(path)) {
const results = JSON.parse(fs.readFileSync(path, 'utf8'));
const comment = `## 🤖 TestAgent Results
**Tests Run:** ${results.total_tests}
**Passed:** ✅ ${results.tests_passed}
**Failed:** ❌ ${results.tests_failed}
**Coverage:** ${results.ui_coverage}%
${results.tests_failed > 0 ? '### Failed Tests\n' + results.failed_tests.map(test => `- ${test.name}: ${test.error}`).join('\n') : ''}
### Screenshots and Details
Check the [artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for detailed test results and screenshots.
---
*Generated by [TestAgent](https://github.com/abalakrishnan1/testagent)*
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
- name: Set outputs
shell: bash
run: |
if [ -f .testagent/results/summary.json ]; then
RESULTS=$(cat .testagent/results/summary.json)
echo "tests-passed=$(echo $RESULTS | jq -r '.tests_passed')" >> $GITHUB_OUTPUT
echo "tests-failed=$(echo $RESULTS | jq -r '.tests_failed')" >> $GITHUB_OUTPUT
echo "total-tests=$(echo $RESULTS | jq -r '.total_tests')" >> $GITHUB_OUTPUT
echo "coverage-report=$(echo $RESULTS | jq -r '.ui_coverage')" >> $GITHUB_OUTPUT
fi
- name: Fail if tests failed
if: ${{ inputs.fail-on-test-failure == 'true' }}
shell: bash
run: |
if [ -f .testagent/results/summary.json ]; then
FAILED=$(cat .testagent/results/summary.json | jq -r '.tests_failed')
if [ "$FAILED" -gt 0 ]; then
echo "❌ $FAILED tests failed"
exit 1
fi
fi