Skip to content

Commit

Permalink
Merge pull request #68 from NHSDigital/RAVS-1658-Maintenance
Browse files Browse the repository at this point in the history
Ravs 1658 maintenance
  • Loading branch information
beno4-ravs authored Feb 19, 2025
2 parents 0a647da + 01c83e1 commit 298612a
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 332 deletions.
171 changes: 58 additions & 113 deletions .github/workflows/regression_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ on:
- RAVS
required: false
default: RAVS
browser:
description: 'Browser to run tests on'
type: choice
options:
- chrome
- firefox
- safari
- edge
- mobile
required: false
default: "edge"
device:
description: 'Device to run tests on'
type: choice
options:
- iphone_12
- iphone_11
- pixel_5
required: false
default: "iphone_12"
id:
description: 'Unique run identifier (Do not change this)'
required: false
Expand All @@ -32,26 +52,24 @@ on:
description: 'The GitHub tag to run the test pack from'
required: false
default: "main"

push:
branches:
- '**' # Triggers on push to any branch
- '**'

schedule:
# QA environment at 6:00 AM UTC
- cron: '0 6 * * *' # This will run the tests for the QA environment
# DEV environment at 6:30 AM UTC
- cron: '30 6 * * *' # This will run the tests for the DEV environment
- cron: '0 6 * * *'
- cron: '30 6 * * *'

jobs:
regression_tests:
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'push' && 'dev' || (github.event_name == 'schedule' && github.event.schedule == '0 6 * * *' && 'qa' || (github.event_name == 'workflow_dispatch' && inputs.environment || 'dev')) }} # Dynamically set environment based on event type
environment: ${{ github.event_name == 'push' && 'dev' || (github.event_name == 'schedule' && github.event.schedule == '0 6 * * *' && 'qa' || (github.event_name == 'workflow_dispatch' && inputs.environment || 'dev')) }}

steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v4

# Step 2: Cache Python dependencies
- name: Cache Python dependencies
uses: actions/cache@v4
with:
Expand All @@ -62,160 +80,87 @@ jobs:
- name: Set Environment Variables
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]; then
case "${{ github.event.schedule }}" in
"0 6 * * *")
echo ENV=qa >> $GITHUB_ENV
;;
"30 6 * * *")
echo ENV=dev >> $GITHUB_ENV
;;
*)
echo "Unrecognized schedule. Defaulting to dev."
echo ENV=dev >> $GITHUB_ENV
;;
esac
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo ENV=${{ inputs.environment }} >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "push" ]]; then
echo ENV=dev >> $GITHUB_ENV
else
echo "Unknown event. Defaulting to dev."
echo ENV=dev >> $GITHUB_ENV
fi
echo "ENV=${{ inputs.environment || 'dev' }}" >> $GITHUB_ENV
echo "BROWSER=${{ inputs.browser || 'edge' }}" >> $GITHUB_ENV
echo "DEVICE=${{ inputs.device || 'iphone_12' }}" >> $GITHUB_ENV
echo "PRODUCT=${{ inputs.product || 'RAVS' }}" >> $GITHUB_ENV
# - name: Notify Slack - Test Run Started
# if: ${{ github.event_name == 'workflow_dispatch' }}
# run: |
# BRANCH_NAME=${{ github.ref_name || 'manual trigger (branch not specified)' }}
# curl -X POST -H 'Content-type: application/json' \
# --data '{
# "text": "🚀 Tests have been kicked off manually by *${{ github.actor }}*.\n*Environment:* ${{ inputs.environment }}\n*Product:* RAVS\n*Run ID:* ${{ github.run_id }}\n*Branch:* '$BRANCH_NAME'"
# }' \
# ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Notify Slack - Test Run Started
if: ${{ github.event_name == 'workflow_dispatch' }}
- name: Notify Slack - Tests Started
run: |
# Detect Azure DevOps trigger
if [[ "${{ github.actor }}" == "azure-pipelines[bot]" ]] || [[ "${{ github.event.inputs.trigger_source }}" == "Azure devops" ]]; then
TRIGGER_SOURCE="Azure DevOps Pipeline"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TRIGGER_SOURCE="🚀 *Tests have been kicked off manually by* ${{ github.actor }}."
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
TRIGGER_SOURCE="🕒 *Tests have been triggered by a scheduled run.*"
elif [[ "${{ github.event_name }}" == "push" ]]; then
TRIGGER_SOURCE="🔄 *Tests have been triggered by a code push.*"
else
TRIGGER_SOURCE="manually by *${{ github.actor }}*"
TRIGGER_SOURCE="🔍 *Tests have started.*"
fi
# Branch name
BRANCH_NAME=${{ github.ref_name || 'manual trigger (branch not specified)' }}
# Notify Slack
curl -X POST -H 'Content-type: application/json' \
--data "{
\"text\": \"🚀 Tests have been kicked off $TRIGGER_SOURCE.\n*Environment:* ${{ inputs.environment }}\n*Product:* RAVS\n*Run ID:* ${{ github.run_id }}\n*Branch:* ${BRANCH_NAME}\"
}" \
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Notify Slack - Test Run Started
if: ${{ github.event_name == 'push' }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text": "🚀 Tests have been triggered by a push to branch *${{ github.ref_name }}*.\n*Environment:* ${{ env.ENV }}\n*Product:* RAVS\n*Run ID:* ${{ github.run_id }}"}' \
${{ secrets.SLACK_WEBHOOK_URL }}
BROWSER_MESSAGE="${{ env.BROWSER }}"
if [[ "${{ env.BROWSER }}" == "mobile" ]]; then
BROWSER_MESSAGE="Mobile (${{ env.DEVICE }})"
fi
- name: Notify Slack - Test Run Started
if: ${{ github.event_name == 'schedule' }}
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text": "🚀 Tests have been triggered by a scheduled run.\n*Environment:* ${{ env.ENV }}\n*Product:* RAVS\n*Run ID:* ${{ github.run_id }}"}' \
${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_MESSAGE="${TRIGGER_SOURCE}\n
*Environment:* ${{ env.ENV }}
*Product:* ${{ env.PRODUCT }}
*Run ID:* ${{ github.run_id }}
*Browser:* ${BROWSER_MESSAGE}
*Branch:* ${{ github.ref_name }}"
- name: Set up en_GB.UTF-8 locale
run: |
sudo apt-get update
sudo apt-get install -y locales
sudo locale-gen "en_GB.UTF-8"
sudo update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB:en LC_ALL=en_GB.UTF-8
env:
DEBIAN_FRONTEND: noninteractive
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"${SLACK_MESSAGE}\"}" ${{ secrets.SLACK_WEBHOOK_URL }}
# Step 3: Set up Python 3.11
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

# Step 4: Install Python dependencies from requirements.txt
- name: Install Python dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Step 5: Cache Playwright binaries
- name: Cache Playwright binaries
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ inputs.environment }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install xvfb
run: sudo apt-get install xvfb

# Step 6: Install Playwright dependencies
- name: Install Playwright dependencies
- name: Install Playwright
run: |
python -m pip install playwright
playwright install
playwright install --with-deps webkit
playwright install-deps
# Step 7: Install Allure Commandline
- name: Install Allure Commandline
run: |
curl -o allure-commandline-2.17.3.tgz -Ls https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.17.3/allure-commandline-2.17.3.tgz && \
tar -zxvf allure-commandline-2.17.3.tgz -C /opt/ && \
sudo ln -s /opt/allure-2.17.3/bin/allure /usr/bin/allure && \
rm -rf allure-commandline-2.17.3.tgz
# Step 8: Verify Allure Installation
- name: Verify Allure Installation
run: allure --version

# Step 9: Debug tox.ini content for visibility
- name: Debug tox.ini
run: cat tox.ini

- name: Debug regression_tests.yaml
run: cat .github/workflows/regression_tests.yaml


- name: Debug locale settings
run: |
echo "Current Locale:"
locale
# Step 10: Run Tests using tox
- name: Run Tests
env:
TZ: "Europe/London"
LANG: "en_GB.UTF-8"
LANGUAGE: "en_GB:en"
LC_ALL: "en_GB.UTF-8"
TEST_ENVIRONMENT: ${{ github.event_name == 'push' && 'dev' || (github.event_name == 'schedule' && github.event.schedule == '0 6 * * *' && 'qa' || (github.event_name == 'workflow_dispatch' && inputs.environment || 'dev')) }}
TEST_ENVIRONMENT: ${{ env.ENV }}
RAVS_PASSWORD: ${{ secrets.RAVS_PASSWORD }}
HEADLESS_MODE: "true"
BROWSER: "edge"
BROWSER: ${{ env.BROWSER }}
DEVICE: ${{ env.DEVICE }}
MARKER: ${{ inputs.marker || '' }}
AGENTS: 3
run: |
tox -v
continue-on-error: true

# Step 11: Upload Allure Results as an artifact
- name: Upload Allure Results
uses: actions/upload-artifact@v4
with:
name: allure-results
path: allure-results
if-no-files-found: error

# Step 12: Generate a token and trigger report generation
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
Expand All @@ -231,5 +176,5 @@ jobs:
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer ${{ steps.generate-token.outputs.token }}" \
-d '{"ref": "main", "inputs": {"run_id": "${{ github.run_id }}"}}' \
-d '{"ref": "main", "inputs": {"run_id": "${{ github.run_id }}", "browser": "${{ env.BROWSER }}", "device": "${{ env.DEVICE }}"}}' \
"https://api.github.com/repos/NHSDigital/ravs-test-reports/actions/workflows/publish_report.yml/dispatches"
24 changes: 4 additions & 20 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,6 @@
import logging
from test_data.get_values_from_models import *

# Define marks
pytest.mark.login = pytest.mark.mark(login=True)
pytest.mark.logout = pytest.mark.mark(logout=True)
pytest.mark.smoke = pytest.mark.mark(smoke=True)
pytest.mark.appointments = pytest.mark.mark(appointments=True)
pytest.mark.consent = pytest.mark.mark(consent=True)
pytest.mark.findpatient = pytest.mark.mark(findpatient=True)
pytest.mark.createpatient = pytest.mark.mark(createpatient=True)
pytest.mark.recordvaccine = pytest.mark.mark(recordvaccine=True)
pytest.mark.addvaccine = pytest.mark.mark(addvaccine=True)
pytest.mark.addbatches = pytest.mark.mark(addbatches=True)
pytest.mark.reports = pytest.mark.mark(reports=True)
pytest.mark.usermanagement = pytest.mark.mark(usermanagement=True)
pytest.mark.persistValues = pytest.mark.mark(persistValues=True)
pytest.mark.sflag = pytest.mark.mark(sflag=True)

@pytest.fixture(scope='function', autouse=True)
def report_browser_version(request):
browser_version = get_browser_version()
Expand Down Expand Up @@ -761,8 +745,8 @@ def step_see_patient_details_on_check_and_confirm_screen(shared_data, name, dob,
assert get_patient_vaccination_vaccinator_value() == shared_data['vaccinator']
attach_screenshot("check_and_confirm_screen_after_assertion")

@when("when I click confirm and save button, I should see a record saved dialogue")
@then("when I click confirm and save button, I should see a record saved dialogue")
@when("I click confirm and save button, I should see a record saved dialogue")
@then("I click confirm and save button, I should see a record saved dialogue")
def click_confirm_and_save_button_record_saved(shared_data):
attach_screenshot("patient_details_screen_with_immunisation_history")
click_confirm_details_and_save_button()
Expand All @@ -789,7 +773,7 @@ def immunisation_history_should_be_updated(shared_data):
else:
assert int(immunisation_history_records_count_after_vaccination) == int(shared_data["immunisation_history_records_count_before_vaccination"])

@then("when I click confirm and save button, the immunisation history of the patient should be updated in the patient details page")
@then("I click confirm and save button, the immunisation history of the patient should be updated in the patient details page")
def click_confirm_and_save_button_immunisation_history_should_be_updated(shared_data):
attach_screenshot("patient_details_screen_with_immunisation_history")
if shared_data["vaccinated_decision"].lower() == "yes" and shared_data["consent_decision"].lower() == "yes" and shared_data["eligibility_assessment_outcome"].lower() == "give vaccine":
Expand All @@ -815,7 +799,7 @@ def start_recording_the_vaccine_for_new_patient(shared_data, new_patient_name, n

@then("the delivery team, vaccine and vaccine product selection should persist on the choose vaccine page")
def check_values_persist_on_choose_vaccine_screen(shared_data):
assert get_selected_delivery_team_radio_button_value_on_choose_vaccine_page() == shared_data["site"]
assert get_selected_delivery_team_radio_button_value_on_choose_vaccine_page().lower() == shared_data["site"].lower()
attach_screenshot("delivery_team_selection_is_persisted")
assert get_selected_vaccine_radio_button_value_on_choose_vaccine_page() == shared_data["chosen_vaccine"]
attach_screenshot("vaccine_selection_is_persisted")
Expand Down
Loading

0 comments on commit 298612a

Please sign in to comment.