Skip to content

Commit 78f28fd

Browse files
Consent2 (#31)
* Updates * Gillick consent * RAV * ScenarioIds * init * init * sessions fixture * RAV * gillick competence * Vaccs negative * positive
1 parent 76f50bc commit 78f28fd

38 files changed

+773
-557
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ venv/
2323
# Local
2424
logs/pytest.log
2525
main.py
26-
26+
reports/*
27+
working/*
28+
.vscode/*

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
"python.testing.unittestEnabled": false,
1111
"python.testing.pytestEnabled": true,
1212
"cSpell.words": [
13-
"dotenv"
13+
"dotenv",
14+
"downcasting",
15+
"fillna",
16+
"venv"
1417
],
1518
"[python]": {
1619
"editor.defaultFormatter": "ms-python.black-formatter",
1720
"editor.formatOnSave": true,
18-
}
21+
},
22+
"python.analysis.autoImportCompletions": true
1923
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Manage vaccinations in schools
2+
23
[![Run MAVIS tests on TEST](https://github.com/NHSDigital/manage-vaccinations-in-schools-testing/actions/workflows/MAVIS_TEST.yml/badge.svg)](https://github.com/NHSDigital/manage-vaccinations-in-schools-testing/actions/workflows/MAVIS_TEST.yml)
34

45
## Introduction
@@ -13,7 +14,7 @@ This test pack requires Python 3.10 installed on the system or greater to run.
1314

1415
To execute the tests from your system, please follow the 4 easy steps below:
1516

16-
1. Clone the repo to any local folder
17+
1. Clone the repository to any local folder
1718

1819
```console
1920
git clone https://github.com/NHSDigital/manage-vaccinations-in-schools-testing.git

conftest.py

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
2+
from playwright.sync_api import sync_playwright
23

34
from libs import CurrentExecution as ce
45
from libs import file_ops as fo
5-
from libs.constants import workflow_type
66
from libs.wrappers import *
77

88

@@ -12,31 +12,83 @@ def pytest_addoption(parser):
1212

1313
@pytest.fixture(scope="session")
1414
def start_exe_session(request):
15-
_browser_name = request.config.getoption("browser_or_device")
16-
ce.current_browser_name = _browser_name
1715
ce.get_env_values()
16+
ce.reset_environment()
1817
ce.session_screenshots_dir = create_session_screenshot_dir()
19-
ce.start_browser(browser_name=_browser_name)
20-
yield
21-
ce.quit_browser()
18+
ce.current_browser_name = request.config.getoption("browser_or_device")
2219

2320

24-
@pytest.fixture
25-
def create_browser_page(start_exe_session):
26-
ce.start_test(w_type=workflow_type.APPLICATION)
27-
yield ce.page
28-
ce.end_test()
21+
@pytest.fixture(scope="session")
22+
def start_playwright():
23+
with sync_playwright() as _playwright:
24+
_playwright.selectors.set_test_id_attribute("data-qa")
25+
yield _playwright
26+
27+
28+
@pytest.fixture()
29+
def start_mavis(start_exe_session, start_playwright):
30+
_browser, _context = start_browser(pw=start_playwright, browser_or_device=ce.current_browser_name)
31+
ce.browser = _browser
32+
ce.page = _context.new_page()
33+
ce.page.goto(url=ce.service_url)
34+
yield
35+
close_browser(browser=_browser, page=ce.page)
2936

3037

3138
@pytest.fixture
32-
def start_consent_workflow(start_exe_session):
33-
ce.start_test(w_type=workflow_type.PARENTAL_CONSENT)
34-
yield ce.page
35-
ce.end_test()
39+
def start_consent_workflow(start_exe_session, start_playwright):
40+
_browser, _context = start_browser(pw=start_playwright, browser_or_device=ce.current_browser_name)
41+
ce.page = _context.new_page()
42+
ce.page.goto(url=ce.parental_consent_url)
43+
yield
44+
close_browser(browser=_browser, page=ce.page)
3645

3746

3847
def create_session_screenshot_dir() -> str:
3948
if ce.capture_screenshot_flag:
4049
_session_name = f"{get_new_datetime()}-{ce.current_browser_name}"
4150
fo.file_operations().create_dir(dir_path=f"screenshots/{_session_name}")
4251
return f"screenshots/{_session_name}"
52+
53+
54+
def start_browser(pw, browser_or_device: str):
55+
_http_credentials = {
56+
"username": ce.base_auth_username,
57+
"password": ce.base_auth_password,
58+
}
59+
try:
60+
match browser_or_device.lower():
61+
case "iphone_12":
62+
_browser = pw.webkit.launch(headless=ce.headless_mode)
63+
_context = _browser.new_context(**pw.devices["iPhone 12"], http_credentials=_http_credentials)
64+
case "iphone_11":
65+
_browser = pw.chromium.launch(channel="chrome", headless=ce.headless_mode)
66+
_context = _browser.new_context(**pw.devices["iPhone 11"], http_credentials=_http_credentials)
67+
case "pixel_5":
68+
_browser = pw.webkit.launch(headless=ce.headless_mode)
69+
_context = _browser.new_context(**pw.devices["Pixel 5"], http_credentials=_http_credentials)
70+
case "s9+":
71+
_browser = pw.chromium.launch(channel="chromium", headless=ce.headless_mode)
72+
_context = _browser.new_context(**pw.devices["Galaxy S9+"], http_credentials=_http_credentials)
73+
case "chrome":
74+
_browser = pw.chromium.launch(channel="chrome", headless=ce.headless_mode)
75+
_context = _browser.new_context(http_credentials=_http_credentials)
76+
case "msedge":
77+
_browser = pw.chromium.launch(channel="msedge", headless=ce.headless_mode)
78+
_context = _browser.new_context(http_credentials=_http_credentials)
79+
case "firefox":
80+
_browser = pw.firefox.launch(headless=ce.headless_mode)
81+
_context = _browser.new_context(http_credentials=_http_credentials)
82+
case _: # Desktop Chromium for all other cases
83+
_browser = pw.chromium.launch(headless=ce.headless_mode)
84+
_context = _browser.new_context(http_credentials=_http_credentials)
85+
return _browser, _context
86+
except Exception as e:
87+
raise AssertionError(f"Error launching {browser_or_device}: {e}")
88+
89+
90+
def close_browser(browser, page):
91+
if page.get_by_role("button", name="Log out").is_visible():
92+
page.get_by_role("button", name="Log out").click()
93+
page.close()
94+
browser.close()

libs/__init__.py

Lines changed: 6 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import os
22

33
from dotenv import load_dotenv
4-
from playwright.sync_api import sync_playwright
54

6-
from libs.constants import workflow_type
5+
from libs import api_ops
76

87

98
class CurrentExecution:
109
page = None
11-
environment = None
10+
browser = None
11+
service_url: str = ""
1212
base_auth_username: str = ""
1313
base_auth_password: str = ""
1414
current_browser_name: str = ""
1515
headless_mode: bool = False
16-
playwright: bool = None
1716
session_screenshots_dir: str = ""
1817
screenshot_sequence: int = 0
1918
capture_screenshot_flag: bool = False
@@ -23,18 +22,10 @@ class CurrentExecution:
2322
reset_endpoint: str = ""
2423
api_token: str = ""
2524

26-
@staticmethod
27-
def start_test(w_type: workflow_type):
28-
CurrentExecution.start_page(w_type=w_type)
29-
30-
@staticmethod
31-
def end_test():
32-
CurrentExecution.close_page()
33-
3425
@staticmethod
3526
def get_env_values():
3627
load_dotenv()
37-
CurrentExecution.environment = os.getenv("TEST_URL")
28+
CurrentExecution.service_url = os.getenv("TEST_URL")
3829
CurrentExecution.base_auth_username = os.getenv("TEST_USERNAME")
3930
CurrentExecution.base_auth_password = os.getenv("TEST_PASSWORD")
4031
CurrentExecution.login_username = os.getenv("LOGIN_USERNAME")
@@ -46,122 +37,6 @@ def get_env_values():
4637
CurrentExecution.api_token = os.getenv("API_TOKEN")
4738

4839
@staticmethod
49-
def start_browser(browser_name: str):
50-
CurrentExecution.playwright = sync_playwright().start()
51-
CurrentExecution.playwright.selectors.set_test_id_attribute("data-qa")
52-
match browser_name.lower():
53-
case "chromium":
54-
CurrentExecution.launch_chromium()
55-
case "msedge":
56-
CurrentExecution.launch_edge()
57-
case "firefox":
58-
CurrentExecution.launch_firefox()
59-
case "chrome": # Google Chrome for all other cases
60-
CurrentExecution.launch_chrome()
61-
case _: # Mobile browsers
62-
CurrentExecution.launch_mobile_browser(device_name=browser_name)
63-
64-
@staticmethod
65-
def start_page(w_type: workflow_type):
66-
CurrentExecution.context = CurrentExecution.browser.new_context(
67-
http_credentials={
68-
"username": CurrentExecution.base_auth_username,
69-
"password": CurrentExecution.base_auth_password,
70-
}
71-
)
72-
CurrentExecution.page = CurrentExecution.context.new_page()
73-
match w_type.lower():
74-
case workflow_type.PARENTAL_CONSENT:
75-
CurrentExecution.page.goto(url=CurrentExecution.parental_consent_url)
76-
case _:
77-
CurrentExecution.reset_upload_data()
78-
CurrentExecution.page.goto(url=CurrentExecution.environment)
79-
80-
@staticmethod
81-
def quit_browser():
82-
CurrentExecution.browser.close()
83-
84-
@staticmethod
85-
def close_page():
86-
CurrentExecution.page.close()
87-
88-
@staticmethod
89-
def launch_chromium():
90-
try:
91-
CurrentExecution.browser = CurrentExecution.playwright.chromium.launch(
92-
headless=CurrentExecution.headless_mode, args=["--fullscreen"]
93-
)
94-
except Exception as e:
95-
raise AssertionError(f"Error launching Chromium: {e}")
96-
97-
@staticmethod
98-
def launch_edge():
99-
try:
100-
CurrentExecution.browser = CurrentExecution.playwright.chromium.launch(
101-
channel="msedge", headless=CurrentExecution.headless_mode, args=["--fullscreen"]
102-
)
103-
except Exception as e:
104-
raise AssertionError(f"Error launching Edge: {e}")
105-
106-
@staticmethod
107-
def launch_firefox():
108-
try:
109-
CurrentExecution.browser = CurrentExecution.playwright.firefox.launch(
110-
headless=CurrentExecution.headless_mode, args=["--fullscreen"]
111-
)
112-
except Exception as e:
113-
raise AssertionError(f"Error launching Firefox: {e}")
114-
115-
@staticmethod
116-
def launch_chrome():
117-
try:
118-
CurrentExecution.browser = CurrentExecution.playwright.chromium.launch(
119-
channel="chrome", headless=CurrentExecution.headless_mode, args=["--fullscreen"]
120-
)
121-
except Exception as e:
122-
raise AssertionError(f"Error launching Chrome: {e}")
123-
124-
@staticmethod
125-
def launch_mobile_browser(device_name: str):
126-
_http_credentials = {
127-
"username": CurrentExecution.base_auth_username,
128-
"password": CurrentExecution.base_auth_password,
129-
}
130-
try:
131-
match device_name.lower():
132-
case "iphone_12":
133-
CurrentExecution.browser = CurrentExecution.playwright.webkit.launch(
134-
headless=CurrentExecution.headless_mode
135-
)
136-
CurrentExecution.context = CurrentExecution.browser.new_context(
137-
**CurrentExecution.playwright.devices["iPhone 12"], http_credentials=_http_credentials
138-
)
139-
case "iphone_11":
140-
CurrentExecution.browser = CurrentExecution.playwright.chromium.launch(
141-
channel="chrome", headless=CurrentExecution.headless_mode
142-
)
143-
CurrentExecution.context = CurrentExecution.browser.new_context(
144-
**CurrentExecution.playwright.devices["iPhone 11"], http_credentials=_http_credentials
145-
)
146-
case "pixel_5":
147-
CurrentExecution.browser = CurrentExecution.playwright.webkit.launch(
148-
headless=CurrentExecution.headless_mode
149-
)
150-
CurrentExecution.context = CurrentExecution.browser.new_context(
151-
**CurrentExecution.playwright.devices["Pixel 5"], http_credentials=_http_credentials
152-
)
153-
case _:
154-
CurrentExecution.browser = CurrentExecution.playwright.chromium.launch(
155-
channel="chromium", headless=CurrentExecution.headless_mode
156-
)
157-
CurrentExecution.context = CurrentExecution.browser.new_context(
158-
**CurrentExecution.playwright.devices["Galaxy S9+"], http_credentials=_http_credentials
159-
)
160-
CurrentExecution.page = CurrentExecution.context.new_page()
161-
except Exception as e:
162-
raise AssertionError(f"Error launching device browser {device_name}: {e}")
163-
164-
@staticmethod
165-
def reset_upload_data():
40+
def reset_environment():
16641
_headers = {"Authorization": CurrentExecution.api_token}
167-
# _ = api_ops.api_operations().api_get(endpoint=CurrentExecution.reset_endpoint, header=_headers, param=None)
42+
_ = api_ops.api_operations().api_get(endpoint=CurrentExecution.reset_endpoint, header=_headers, param=None)

0 commit comments

Comments
 (0)