-
Notifications
You must be signed in to change notification settings - Fork 1
185 lines (163 loc) · 6.13 KB
/
selenium-tests.yml
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
name: Run all tests
on:
workflow_dispatch:
push:
branches:
- main
- feature2
pull_request:
branches:
- main
- test-branch
schedule:
- cron: "0 7 * * 2" # Every Tuesday at 7:00 AM UTC (8:00 AM Zurich time during CET)
- cron: "0 7 * * 5" # Every Friday at 7:00 AM UTC (8:00 AM Zurich time during CET)
jobs:
setup-environments:
runs-on: ubuntu-latest
outputs:
artifact_path: latest_logs/
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Set up virtual environment
run: |
python -m venv venv
# On Windows use `venv\Scripts\activate`
# On Linux/macOS use `source venv/bin/activate`
source venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-html
- name: Debug environment variables
run: echo $PATH
- name: Install required dependencies
run: |
sudo apt-get update
sudo apt-get upgrade
# Install Chrome (needed for Chrome tests)
- name: Install Chrome
run: |
sudo apt-get install -y google-chrome-stable
# Set up Firefox and GeckoDriver
- name: Set up Firefox and GeckoDriver
uses: browser-actions/setup-firefox@v1
with:
firefox-version: 'latest' # You can specify a specific version or 'latest'
install-geckodriver: true
install-dependencies: true
# Optionally, set environment variables for Firefox
- name: Set Firefox environment variables
run: |
echo "GECKODRIVER_PATH=/usr/local/bin/geckodriver" >> $GITHUB_ENV
echo "BROWSER=firefox" >> $GITHUB_ENV
- name: Prepare logs directory
run: mkdir -p latest_logs
test-production:
needs: setup-environments
runs-on: ubuntu-latest
strategy:
matrix:
browser: [chrome, firefox]
environment: production
steps:
- name: Use shared setup
run: echo "Reusing setup from setup-environments job"
- name: Run tests for production
env:
BASE_URL: ${{ vars.PRODUCTION_URL }}
run: |
# source venv/bin/activate # Activate the virtual environment
pytest --env=production --env_url=${{ vars.PRODUCTION_URL }} tests/test_login.py -sv --headless \
--html=latest_logs/report_production_${{ matrix.browser }}.html \
--self-contained-html --browser-name=${{ matrix.browser }}
- name: Upload test report
uses: actions/upload-artifact@v3
with:
name: test-report-production-${{ matrix.browser }}
path: latest_logs/
test-sauce-labs:
needs: test-production
runs-on: ubuntu-latest
strategy:
matrix:
browser: [chrome, firefox]
environment: sauce-labs
steps:
- name: Use shared setup
run: echo "Reusing setup from setup-environments job"
- name: Run tests for Sauce Labs
env:
BASE_URL: ${{ vars.SAUCE_LABS_URL }}
SELENIUM_REMOTE_URL: https://ondemand.eu-central-1.saucelabs.com:443/wd/hub
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
run: |
# source venv/bin/activate # Activate the virtual environment
pytest --env=sauce-labs --env_url=${{ vars.SAUCE_LABS_URL }} tests/test_login.py -sv --headless \
--html=latest_logs/report_sauce_labs_${{ matrix.browser }}.html \
--self-contained-html --sauce-labs --browser-name=${{ matrix.browser }}
- name: Upload Sauce Labs test report
uses: actions/upload-artifact@v3
with:
name: test-report-sauce-labs-${{ matrix.browser }}
path: latest_logs/
test-staging:
needs: test-sauce-labs
runs-on: ubuntu-latest
strategy:
matrix:
browser: [chrome, firefox]
environment: staging
steps:
- name: Use shared setup
run: echo "Reusing setup from setup-environments job"
- name: Run tests for staging
env:
BASE_URL: ${{ vars.STAGING_URL }}
run: |
# source venv/bin/activate # Activate the virtual environment
pytest --env=staging --env_url=${{ vars.STAGING_URL }} tests/test_login.py -sv --headless \
--html=latest_logs/report_staging_${{ matrix.browser }}.html \
--self-contained-html --browser-name=${{ matrix.browser }}
- name: Upload Staging test report
uses: actions/upload-artifact@v3
with:
name: test-report-staging-${{ matrix.browser }}
path: latest_logs/
# - name: Upload error screenshots
# if: failure() # Only upload if the job fails
# uses: actions/upload-artifact@v3
# with:
# name: error-screenshots
# path: latest_logs/errors/
#
# - name: Upload test report
# uses: actions/upload-artifact@v3
# with:
# name: test-report
# path: latest_logs/report.html
# # Step 7: Slack notification on success
# - name: Notify Slack on Success
# if: success()
# env:
# SLACK_WEBHOOK_URL_PASS: ${{ secrets.SLACK_WEBHOOK_URL_PASS }}
# run: |
# curl -X POST -H 'Content-type: application/json' \
# --data "{\"text\":\":white_check_mark: Test pipeline succeeded in *${{ github.repository }}*. Branch: *${{ github.ref_name }}*\", \"username\":\"GitHub Actions\", \"icon_emoji\":\":rocket:\"}" \
# $SLACK_WEBHOOK_URL_PASS
#
## Step 8: Slack notification on failure
# - name: Notify Slack on Failure
# if: failure()
# env:
# SLACK_WEBHOOK_URL_FAIL: ${{ secrets.SLACK_WEBHOOK_URL_FAIL }}
# run: |
# curl -X POST -H 'Content-type: application/json' \
# --data "{\"text\":\":x: Test pipeline failed in *${{ github.repository }}*. Branch: *${{ github.ref_name }}*. Check the logs for details.\", \"username\":\"GitHub Actions\", \"icon_emoji\":\":warning:\"}" \
# $SLACK_WEBHOOK_URL_FAIL