Skip to content

Commit 8f10986

Browse files
dlzhry2nhsKrupasindhu BaralJamesW1-NHSfimran08
authored
VED-1013 Introduce new e2e tests from automation testers (#1146)
Co-authored-by: Krupasindhu Baral <krupasindhu.baral@nhs.net> Co-authored-by: James W. <218585646+JamesW1-NHS@users.noreply.github.com> Co-authored-by: fimran08 <90399910+fimran08@users.noreply.github.com>
1 parent 0247e85 commit 8f10986

121 files changed

Lines changed: 9860 additions & 6148 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ updates:
6262
- "/lambdas/recordprocessor"
6363
- "/lambdas/redis_sync"
6464
- "/lambdas/shared"
65-
- "/tests/e2e"
66-
- "/tests/e2e_batch"
65+
- "/tests/e2e_automation"
6766
schedule:
6867
interval: "daily"
6968
open-pull-requests-limit: 1

.github/workflows/continuous-deployment.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,50 @@ jobs:
1818
# Technically the first step is not a pre-requisite - sandbox backend deployment is handled by APIM
1919
# Stipulating this condition simply makes it more likely the environment will be ready when tests are invoked
2020
needs: [deploy-internal-dev-backend]
21-
uses: ./.github/workflows/run-e2e-tests.yml
21+
uses: ./.github/workflows/run-e2e-automation-tests.yml
2222
with:
2323
apigee_environment: internal-dev-sandbox
2424
environment: dev
2525
sub_environment: internal-dev-sandbox
26+
service_under_test: all
27+
suite_to_run: sandbox
2628
secrets:
2729
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
2830
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
2931
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
32+
CIS2_E2E_USERNAME: ${{ secrets.CIS2_E2E_USERNAME }}
3033
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}
3134

3235
run-sandbox-tests:
3336
needs: [run-internal-dev-sandbox-tests]
34-
uses: ./.github/workflows/run-e2e-tests.yml
37+
uses: ./.github/workflows/run-e2e-automation-tests.yml
3538
with:
3639
apigee_environment: sandbox
3740
environment: dev
3841
sub_environment: sandbox
42+
service_under_test: all
43+
suite_to_run: sandbox
3944
secrets:
4045
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
4146
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
4247
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
48+
CIS2_E2E_USERNAME: ${{ secrets.CIS2_E2E_USERNAME }}
4349
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}
4450

4551
run-internal-dev-tests:
4652
needs: [deploy-internal-dev-backend]
47-
uses: ./.github/workflows/run-e2e-tests.yml
53+
uses: ./.github/workflows/run-e2e-automation-tests.yml
4854
with:
4955
apigee_environment: internal-dev
5056
environment: dev
5157
sub_environment: internal-dev
58+
service_under_test: all
59+
suite_to_run: smoke
5260
secrets:
5361
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
5462
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
5563
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
64+
CIS2_E2E_USERNAME: ${{ secrets.CIS2_E2E_USERNAME }}
5665
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}
5766

5867
deploy-higher-dev-envs:
@@ -72,13 +81,21 @@ jobs:
7281
strategy:
7382
matrix:
7483
sub_environment_name: [ref, internal-qa]
75-
uses: ./.github/workflows/run-e2e-tests.yml
84+
include:
85+
- sub_environment_name: ref
86+
required_test_suite: proxy_smoke
87+
- sub_environment_name: internal-qa
88+
required_test_suite: smoke
89+
uses: ./.github/workflows/run-e2e-automation-tests.yml
7690
with:
7791
apigee_environment: ${{ matrix.sub_environment_name }}
7892
environment: dev
7993
sub_environment: ${{ matrix.sub_environment_name }}
94+
service_under_test: all
95+
suite_to_run: ${{ matrix.required_test_suite }}
8096
secrets:
8197
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
8298
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
8399
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
100+
CIS2_E2E_USERNAME: ${{ secrets.CIS2_E2E_USERNAME }}
84101
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}

.github/workflows/pr-deploy-and-test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ jobs:
1313
environment: dev
1414
sub_environment: pr-${{github.event.pull_request.number}}
1515

16-
run-e2e-tests:
16+
run-e2e-automation-tests:
1717
needs: [deploy-pr-backend]
1818
strategy:
1919
matrix:
2020
apigee_environment_name: [internal-dev, internal-dev-sandbox]
21-
uses: ./.github/workflows/run-e2e-tests.yml
21+
include:
22+
- apigee_environment_name: internal-dev
23+
required_test_suite: smoke
24+
- apigee_environment_name: internal-dev-sandbox
25+
required_test_suite: sandbox
26+
uses: ./.github/workflows/run-e2e-automation-tests.yml
2227
with:
2328
apigee_environment: ${{ matrix.apigee_environment_name }}
2429
environment: dev
2530
sub_environment: pr-${{github.event.pull_request.number}}
31+
service_under_test: all
32+
suite_to_run: ${{ matrix.required_test_suite }}
2633
secrets:
2734
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
2835
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
2936
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
37+
CIS2_E2E_USERNAME: ${{ secrets.CIS2_E2E_USERNAME }}
3038
STATUS_API_KEY: ${{ secrets.STATUS_API_KEY }}

.github/workflows/run-e2e-tests.yml renamed to .github/workflows/run-e2e-automation-tests.yml

Lines changed: 101 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run e2e Tests
1+
name: FHIR API and Batch Automation - E2E Tests
22

33
on:
44
workflow_call:
@@ -12,13 +12,21 @@ on:
1212
sub_environment:
1313
required: true
1414
type: string
15+
service_under_test:
16+
required: true
17+
type: string
18+
suite_to_run:
19+
required: true
20+
type: string
1521
secrets:
1622
APIGEE_PASSWORD:
1723
required: true
1824
APIGEE_BASIC_AUTH_TOKEN:
1925
required: true
2026
APIGEE_OTP_KEY:
2127
required: true
28+
CIS2_E2E_USERNAME:
29+
required: true
2230
STATUS_API_KEY:
2331
required: true
2432
workflow_dispatch:
@@ -33,19 +41,35 @@ on:
3341
- internal-qa
3442
- int
3543
- ref
36-
- prod
3744
environment:
3845
type: string
3946
description: Select the backend environment
4047
options:
4148
- dev
4249
- preprod
43-
- prod
4450
sub_environment:
4551
type: string
4652
description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments
53+
service_under_test:
54+
description: Select the service you want to test
55+
required: true
56+
type: choice
57+
options:
58+
- fhir_api
59+
- batch
60+
- all
61+
suite_to_run:
62+
description: Select the suite you would like to run
63+
default: "functional"
64+
type: choice
65+
options:
66+
- smoke
67+
- functional
68+
- sandbox
69+
- proxy_smoke
4770

4871
env:
72+
APIGEE_AUTH_ENV: ${{ inputs.apigee_environment == 'int' && inputs.apigee_environment || 'internal-dev' }}
4973
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
5074
ENVIRONMENT: ${{ inputs.environment }}
5175
SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
@@ -60,11 +84,9 @@ jobs:
6084
contents: read
6185
runs-on: ubuntu-latest
6286
environment: ${{ inputs.apigee_environment }}
63-
outputs:
64-
# Workaround for environment-level variables being unavailable in `jobs.<job-id>.if`.
65-
RUN_BATCH_E2E_TESTS: ${{ vars.RUN_BATCH_E2E_TESTS }}
6687
steps:
6788
- name: Wait for API to be available
89+
if: github.event_name != 'workflow_dispatch'
6890
run: |
6991
endpoint=""
7092
if [[ ${APIGEE_ENVIRONMENT} =~ "prod" ]]; then
@@ -106,16 +128,18 @@ jobs:
106128
exit 1
107129
fi
108130
109-
e2e-tests:
131+
e2e-automation-tests:
110132
permissions:
111133
id-token: write
112-
contents: read
134+
checks: write
135+
contents: write
113136
runs-on: ubuntu-latest
114137
needs: [wait-for-deployment]
115138
environment: ${{ inputs.apigee_environment }}
116139
env:
117140
APIGEE_USERNAME: ${{ vars.APIGEE_USERNAME }}
118-
TF_OUTPUTS_REQUIRED: ${{ vars.RUN_FULL_E2E_TESTS == 'true' || vars.RUN_PROXY_E2E_TESTS == 'true' }}
141+
TF_OUTPUTS_REQUIRED: ${{ inputs.suite_to_run != 'sandbox' }}
142+
119143
steps:
120144
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
121145

@@ -146,11 +170,7 @@ jobs:
146170
if: ${{ env.TF_OUTPUTS_REQUIRED == 'true' }}
147171
working-directory: infrastructure/instance
148172
run: |
149-
echo "IMMS_DELTA_TABLE_NAME=$(make -s output name=imms_delta_table_name)" >> $GITHUB_ENV
150173
echo "AWS_DOMAIN_NAME=$(make -s output name=service_domain_name)" >> $GITHUB_ENV
151-
echo "DYNAMODB_TABLE_NAME=$(make -s output name=dynamodb_table_name)" >> $GITHUB_ENV
152-
echo "AWS_SQS_QUEUE_NAME=$(make -s output name=aws_sqs_queue_name)" >> $GITHUB_ENV
153-
echo "AWS_SNS_TOPIC_NAME=$(make -s output name=aws_sns_topic_name)" >> $GITHUB_ENV
154174
155175
- name: Install poetry
156176
run: pip install poetry==2.1.4
@@ -159,21 +179,21 @@ jobs:
159179
with:
160180
python-version: 3.11
161181
cache: "poetry"
162-
cache-dependency-path: tests/e2e/poetry.lock
182+
cache-dependency-path: tests/e2e_automation/poetry.lock
163183

164184
- name: Install e2e test dependencies
165-
working-directory: tests/e2e
185+
working-directory: tests/e2e_automation
166186
run: poetry install --no-root
167187

168188
- name: Get Apigee access token
169-
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
170-
working-directory: tests/e2e
189+
if: inputs.apigee_environment != 'int'
190+
working-directory: tests/e2e_automation
171191
env:
172192
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
173193
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
174194
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
175195
run: |
176-
CODE=$(poetry run python utils/compute_totp_code.py "$APIGEE_OTP_KEY")
196+
CODE=$(poetry run python utilities/compute_totp_code.py "$APIGEE_OTP_KEY")
177197
echo "::add-mask::$CODE"
178198
179199
echo "Requesting access token from Apigee..."
@@ -187,55 +207,73 @@ jobs:
187207
echo "::add-mask::$token"
188208
echo "APIGEE_ACCESS_TOKEN=$token" >> $GITHUB_ENV
189209
190-
- name: Run proxy e2e test suite
191-
if: ${{ vars.RUN_PROXY_E2E_TESTS == 'true' }}
192-
working-directory: tests/e2e
193-
run: poetry run python -m unittest test_proxy
194-
195-
- name: Run sandbox e2e test suite
196-
if: ${{ vars.RUN_SANDBOX_E2E_TESTS == 'true' }}
197-
working-directory: tests/e2e
198-
run: poetry run python -m unittest test_proxy.TestProxyHealthcheck
199-
200-
- name: Run full e2e test suite
201-
if: ${{ vars.RUN_FULL_E2E_TESTS == 'true' }}
202-
working-directory: tests/e2e
203-
run: poetry run python -m unittest
204-
205-
batch-e2e-tests:
206-
permissions:
207-
id-token: write
208-
contents: read
209-
needs: [wait-for-deployment, e2e-tests]
210-
# Only actually depend on wait-for-deployment, but run after e2e-tests
211-
if: ${{ !cancelled() && needs.wait-for-deployment.result == 'success' && needs.wait-for-deployment.outputs.RUN_BATCH_E2E_TESTS == 'true' }}
212-
runs-on: ubuntu-latest
213-
environment: ${{ inputs.apigee_environment }}
214-
steps:
215-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
210+
- name: Run Pytest-BDD ${{ inputs.service_under_test }} tests with the ${{ inputs.suite_to_run }} filter
211+
working-directory: tests/e2e_automation
212+
env:
213+
S3_env: ${{ inputs.sub_environment }}
214+
auth_url: https://${{ env.APIGEE_AUTH_ENV }}.api.service.nhs.uk/oauth2-mock/authorize
215+
token_url: https://${{ env.APIGEE_AUTH_ENV }}.api.service.nhs.uk/oauth2-mock/token
216+
baseUrl: https://${{ inputs.apigee_environment }}.api.service.nhs.uk/${{env.SERVICE_BASE_PATH}}
217+
callback_url: "https://oauth.pstmn.io/v1/callback"
218+
username: ${{ secrets.CIS2_E2E_USERNAME }}
219+
scope: "nhs-cis2"
220+
USE_STATIC_APPS: ${{ inputs.apigee_environment == 'int' && 'True' || 'False' }}
221+
Postman_Auth_client_Id: ${{ secrets.Postman_Auth_client_Id }} # The following static app values are only needed in INT
222+
Postman_Auth_client_Secret: ${{ secrets.Postman_Auth_client_Secret }}
223+
RAVS_client_Id: ${{ secrets.RAVS_client_Id }}
224+
RAVS_client_Secret: ${{ secrets.RAVS_client_Secret }}
225+
MAVIS_client_Id: ${{ secrets.MAVIS_client_Id }}
226+
MAVIS_client_Secret: ${{ secrets.MAVIS_client_Secret }}
227+
EMIS_client_Id: ${{ secrets.OPTUM_client_Id }}
228+
EMIS_client_Secret: ${{ secrets.OPTUM_client_Secret }}
229+
TPP_client_Id: ${{ secrets.TPP_client_Id }}
230+
TPP_client_Secret: ${{ secrets.TPP_client_Secret }}
231+
SONAR_client_Id: ${{ secrets.SONAR_client_Id }}
232+
SONAR_client_Secret: ${{ secrets.SONAR_client_Secret }}
233+
MEDICUS_client_Id: ${{ secrets.MEDICUS_client_Id }}
234+
MEDICUS_client_Secret: ${{ secrets.MEDICUS_client_Secret }}
235+
aws_token_refresh: "False"
236+
TEST_PATH: ${{ inputs.service_under_test == 'batch' && 'features/batchTests' || inputs.service_under_test == 'fhir_api' && 'features/APITests' || 'features' }}
237+
TEST_FILTER: ${{ inputs.suite_to_run == 'proxy_smoke' && 'Status_feature' || inputs.suite_to_run }}
238+
run: poetry run pytest "$TEST_PATH" -m "$TEST_FILTER" --junitxml=output/test-results.xml --alluredir=output/allure-results
216239

217-
- name: Connect to AWS
218-
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
240+
- uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
241+
if: always()
219242
with:
220-
aws-region: eu-west-2
221-
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
222-
role-session-name: github-actions
243+
name: BDD Test Summary
244+
path: "**/output/test-results.xml"
245+
reporter: java-junit
246+
fail-on-error: false
223247

224-
- name: Install poetry
225-
run: pip install poetry==2.1.4
248+
- name: Load test report history
249+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
250+
if: always()
251+
continue-on-error: true
252+
with:
253+
ref: gh-pages
254+
path: gh-pages
226255

227-
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
256+
- name: Build Allure report
257+
if: always()
258+
uses: simple-elf/allure-report-action@53ebb757a2097edc77c53ecef4d454fc2f2f774c
228259
with:
229-
python-version: 3.11
230-
cache: "poetry"
231-
cache-dependency-path: tests/e2e_batch/poetry.lock
260+
allure_results: tests/e2e_automation/output/allure-results
261+
gh_pages: gh-pages
262+
allure_report: allure-report
263+
allure_history: allure-history
232264

233-
- name: Install e2e test dependencies
234-
working-directory: tests/e2e_batch
235-
run: poetry install --no-root
265+
- name: Publish Allure report to GitHub Pages
266+
if: always()
267+
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847
268+
with:
269+
github_token: ${{ secrets.GITHUB_TOKEN }}
270+
publish_branch: gh-pages
271+
publish_dir: allure-history
236272

237-
- name: Run batch e2e test suite
238-
working-directory: tests/e2e_batch
239-
env:
240-
ENVIRONMENT: ${{ inputs.sub_environment }}
241-
run: poetry run python -m unittest -c -v
273+
- name: Add link to Allure report
274+
if: always()
275+
uses: actions/github-script@v6
276+
with:
277+
script: |
278+
const url = `https://${context.repo.owner}.github.io/${context.repo.repo}/`;
279+
core.summary.addHeading('Allure Report').addLink('View Report', url).write();

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ newman/
1212
**/*.iml
1313

1414
__pycache__/
15+
.pytest_cache/
1516
.venv/
1617
.env
1718
.envrc
@@ -30,3 +31,8 @@ openapi.json
3031

3132
devtools/volume/
3233
**/.coverage
34+
**/test-results.xml
35+
allure-results/
36+
allure-report/
37+
**/debugLog.log
38+
batch_files_directory/

0 commit comments

Comments
 (0)