55
66from behave .model import Scenario
77from dotenv import load_dotenv
8-
8+ from playwright . sync_api import sync_playwright
99from methods .api import eps_api_methods
1010
1111load_dotenv (override = True )
12-
12+ global _page
1313INTERNAL_QA_BASE_URL = "https://internal-qa.api.service.nhs.uk/"
1414INTERNAL_DEV_BASE_URL = "https://internal-dev.api.service.nhs.uk/"
1515INT_BASE_URL = "https://int.api.service.nhs.uk/"
1616SANDBOX_DEV_BASE_URL = "https://internal-dev-sandbox.api.service.nhs.uk/"
1717SANDBOX_INT_BASE_URL = "https://sandbox.api.service.nhs.uk/"
1818REF_BASE_URL = "https://ref.api.service.nhs.uk/"
1919
20+ AWS_BASE_URL = ".eps.national.nhs.uk/"
2021PFP_AWS_PR_URL = "https://pfp-{{aws_pull_request_id}}.dev.eps.national.nhs.uk/"
2122PFP_AWS_SANDBOX_PR_URL = (
2223 "https://pfp-{{aws_pull_request_id}}-sandbox.dev.eps.national.nhs.uk/"
2324)
25+ CPTS_UI_PR_URL = "https://cpt-ui-{{aws_pull_request_id}}.dev.eps.national.nhs.uk/"
26+ CPTS_UI_SANDBOX_PR_URL = (
27+ "https://cpt-ui-{{aws_pull_request_id}}sandbox.dev.eps.national.nhs.uk/"
28+ )
2429
25-
26- ENVS = {
30+ APIGEE_ENVS = {
2731 "INTERNAL-DEV" : INTERNAL_DEV_BASE_URL ,
2832 "INTERNAL-QA" : INTERNAL_QA_BASE_URL ,
2933 "INT" : INT_BASE_URL ,
3236 "SANDBOX" : SANDBOX_INT_BASE_URL ,
3337}
3438
39+ AWS_ENVS = {
40+ "INTERNAL-DEV" : f".dev{ AWS_BASE_URL } " ,
41+ "INTERNAL-QA" : f".qa{ AWS_BASE_URL } " ,
42+ "INT" : f".int{ AWS_BASE_URL } " ,
43+ "REF" : f".ref{ AWS_BASE_URL } " ,
44+ "INTERNAL-DEV-SANDBOX" : f".sandbox{ AWS_BASE_URL } " ,
45+ "SANDBOX" : f".sandbox.dev{ AWS_BASE_URL } " ,
46+ }
47+
3548CIS2_USERS = {
3649 "prescriber" : {"user_id" : "656005750107" , "role_id" : "555254242105" },
3750 "dispenser" : {"user_id" : "555260695103" , "role_id" : "555265434108" },
3851}
3952LOGIN_USERS = {"user_id" : "9449304130" }
4053
4154REPOS = {
55+ "CPTS-UI" : "https://github.com/NHSDigital/eps-prescription-tracker-ui" ,
4256 "EPS-FHIR" : "https://github.com/NHSDigital/electronic-prescription-service-api" ,
43- # TODO Add EPS Dispensing and Prescribing repo URLs
57+ "EPS-FHIR-PRESCRIBING" : "https://github.com/NHSDigital/electronic-prescription-service-api" ,
58+ "EPS-FHIR-DISPENSING" : "https://github.com/NHSDigital/electronic-prescription-service-api" ,
4459 "PFP-APIGEE" : "https://github.com/NHSDigital/prescriptions-for-patients" ,
4560 "PFP-AWS" : "https://github.com/NHSDigital/prescriptionsforpatients" ,
4661 "PSU" : "https://github.com/NHSDigital/eps-prescription-status-update-api" ,
5469JWT_PRIVATE_KEY = os .getenv ("JWT_PRIVATE_KEY" )
5570JWT_KID = os .getenv ("JWT_KID" )
5671
72+ CPTS_UI_PREFIX = "cpt-ui"
5773EPS_FHIR_SUFFIX = "electronic-prescriptions"
5874EPS_FHIR_PRESCRIBING_SUFFIX = "fhir-prescribing"
5975EPS_FHIR_DISPENSING_SUFFIX = "fhir-dispensing"
@@ -76,25 +92,41 @@ def count_of_scenarios_to_run(context):
7692
7793
7894def before_all (context ):
95+ product = context .config .userdata ["product" ].upper ()
7996 if count_of_scenarios_to_run (context ) != 0 :
8097 env = context .config .userdata ["env" ].upper ()
81- product = context .config .userdata ["product" ].upper ()
82- context .eps_fhir_base_url = os .path .join (select_base_url (env ), EPS_FHIR_SUFFIX )
98+ context .cpts_ui_base_url = f"https://{ CPTS_UI_PREFIX } " + select_aws_base_url (
99+ env
100+ )
101+ context .eps_fhir_base_url = os .path .join (
102+ select_apigee_base_url (env ), EPS_FHIR_SUFFIX
103+ )
83104 context .eps_fhir_prescribing_base_url = os .path .join (
84- select_base_url (env ), EPS_FHIR_PRESCRIBING_SUFFIX
105+ select_apigee_base_url (env ), EPS_FHIR_PRESCRIBING_SUFFIX
85106 )
86107 context .eps_fhir_dispensing_base_url = os .path .join (
87- select_base_url (env ), EPS_FHIR_DISPENSING_SUFFIX
108+ select_apigee_base_url (env ), EPS_FHIR_DISPENSING_SUFFIX
88109 )
89- context .pfp_base_url = os .path .join (select_base_url (env ), PFP_SUFFIX )
90- context .psu_base_url = os .path .join (select_base_url (env ), PSU_SUFFIX )
110+ context .pfp_base_url = os .path .join (select_apigee_base_url (env ), PFP_SUFFIX )
111+ context .psu_base_url = os .path .join (select_apigee_base_url (env ), PSU_SUFFIX )
91112 if PULL_REQUEST_ID :
92113 pull_request_id = PULL_REQUEST_ID .lower ()
93114 if "pr-" in pull_request_id :
94115 get_url_with_pr (context , env , product )
95116 else :
96117 raise RuntimeError ("no tests to run. Check your tags and try again" )
118+ if product == "CPTS-UI" :
119+ global _page
120+ playwright = sync_playwright ().start ()
121+ browser = playwright .chromium .launch (
122+ headless = True , slow_mo = 1000 , channel = "chrome"
123+ )
124+ context .page = browser .new_page ()
125+ _page = context .page
126+ set_page (context , _page )
127+
97128 eps_api_methods .calculate_eps_fhir_base_url (context )
129+ print ("CPTS-UI: " , context .cpts_ui_base_url )
98130 print ("EPS: " , context .eps_fhir_base_url )
99131 print ("EPS-PRESCRIBING: " , context .eps_fhir_prescribing_base_url )
100132 print ("EPS-DISPENSING: " , context .eps_fhir_dispensing_base_url )
@@ -120,23 +152,44 @@ def get_url_with_pr(context, env, product):
120152 context .pfp_base_url = os .path .join (
121153 INTERNAL_DEV_BASE_URL , f"{ PFP_SUFFIX } -{ PULL_REQUEST_ID } "
122154 )
123- if product == "PFP-AWS" :
124- context .pfp_base_url = os .path .join (
125- INTERNAL_DEV_BASE_URL , f"{ PFP_SUFFIX } -{ PULL_REQUEST_ID } "
126- )
127- if env == "INTERNAL-DEV" :
128- context .pfp_base_url = PFP_AWS_PR_URL .replace (
129- "{{aws_pull_request_id}}" , PULL_REQUEST_ID
130- )
131- if env == "INTERNAL-DEV-SANDBOX" :
132- context .pfp_base_url = PFP_AWS_SANDBOX_PR_URL .replace (
133- "{{aws_pull_request_id}}" , PULL_REQUEST_ID
134- )
135-
136155 if product == "PSU" :
137156 context .psu_base_url = os .path .join (
138157 INTERNAL_DEV_BASE_URL , f"{ PSU_SUFFIX } -{ PULL_REQUEST_ID } "
139158 )
159+ if product == "PFP-AWS" :
160+ handle_pfp_aws_pr_url (context , env )
161+ if product == "CPTS-UI" :
162+ handle_cpt_ui_pr_url (context , env )
163+
164+
165+ def handle_cpt_ui_pr_url (context , env ):
166+ assert PULL_REQUEST_ID is not None
167+ context .cpts_ui_base_url = (
168+ f"https://{ CPTS_UI_PREFIX } -{ PULL_REQUEST_ID } { select_apigee_base_url (env )} "
169+ )
170+ if env == "INTERNAL-DEV" :
171+ context .cpts_ui_base_url = CPTS_UI_PR_URL .replace (
172+ "{{aws_pull_request_id}}" , PULL_REQUEST_ID
173+ )
174+ if env == "INTERNAL-DEV-SANDBOX" :
175+ context .cpts_ui_base_url = CPTS_UI_SANDBOX_PR_URL .replace (
176+ "{{aws_pull_request_id}}" , PULL_REQUEST_ID
177+ )
178+
179+
180+ def handle_pfp_aws_pr_url (context , env ):
181+ assert PULL_REQUEST_ID is not None
182+ context .pfp_base_url = os .path .join (
183+ INTERNAL_DEV_BASE_URL , f"{ PFP_SUFFIX } -{ PULL_REQUEST_ID } "
184+ )
185+ if env == "INTERNAL-DEV" :
186+ context .pfp_base_url = PFP_AWS_PR_URL .replace (
187+ "{{aws_pull_request_id}}" , PULL_REQUEST_ID
188+ )
189+ if env == "INTERNAL-DEV-SANDBOX" :
190+ context .pfp_base_url = PFP_AWS_SANDBOX_PR_URL .replace (
191+ "{{aws_pull_request_id}}" , PULL_REQUEST_ID
192+ )
140193
141194
142195def after_all (context ):
@@ -167,6 +220,8 @@ def after_all(context):
167220 if os .path .exists (directory_path ) and os .path .isdir (directory_path ):
168221 print (f"Directory '{ directory_path } ' exists. Deleting..." )
169222 shutil .rmtree (directory_path )
223+ if _page :
224+ _page .close ()
170225
171226
172227def setup_logging (level : int = logging .INFO ):
@@ -179,9 +234,16 @@ def setup_logging(level: int = logging.INFO):
179234 )
180235
181236
182- def select_base_url (env ):
183- if env in ENVS :
184- return ENVS [env ]
237+ def select_apigee_base_url (env ):
238+ if env in APIGEE_ENVS :
239+ return APIGEE_ENVS [env ]
240+ else :
241+ raise ValueError (f"Unknown environment or missing base URL for: { env } ." )
242+
243+
244+ def select_aws_base_url (env ):
245+ if env in AWS_ENVS :
246+ return AWS_ENVS [env ]
185247 else :
186248 raise ValueError (f"Unknown environment or missing base URL for: { env } ." )
187249
@@ -199,3 +261,11 @@ def write_properties_file(file_path, properties_dict):
199261 with open (file_path , "w" ) as file :
200262 for key , value in properties_dict .items ():
201263 file .write (f"{ key } ={ value } \n " )
264+
265+
266+ def get_page (self ):
267+ return self ._page
268+
269+
270+ def set_page (self , _page ):
271+ self ._page = _page
0 commit comments