11import os
22
33from dotenv import load_dotenv
4- from playwright .sync_api import sync_playwright
54
65from libs import api_ops
7- from libs .constants import workflow_type
86
97
108class CurrentExecution :
119 page = None
12- environment = None
10+ service_url : str = ""
1311 base_auth_username : str = ""
1412 base_auth_password : str = ""
1513 current_browser_name : str = ""
1614 headless_mode : bool = False
17- playwright : bool = None
1815 session_screenshots_dir : str = ""
1916 screenshot_sequence : int = 0
2017 capture_screenshot_flag : bool = False
@@ -24,18 +21,10 @@ class CurrentExecution:
2421 reset_endpoint : str = ""
2522 api_token : str = ""
2623
27- @staticmethod
28- def start_test (w_type : workflow_type ):
29- CurrentExecution .start_page (w_type = w_type )
30-
31- @staticmethod
32- def end_test ():
33- CurrentExecution .close_page ()
34-
3524 @staticmethod
3625 def get_env_values ():
3726 load_dotenv ()
38- CurrentExecution .environment = os .getenv ("TEST_URL" )
27+ CurrentExecution .service_url = os .getenv ("TEST_URL" )
3928 CurrentExecution .base_auth_username = os .getenv ("TEST_USERNAME" )
4029 CurrentExecution .base_auth_password = os .getenv ("TEST_PASSWORD" )
4130 CurrentExecution .login_username = os .getenv ("LOGIN_USERNAME" )
@@ -47,144 +36,6 @@ def get_env_values():
4736 CurrentExecution .api_token = os .getenv ("API_TOKEN" )
4837
4938 @staticmethod
50- def start_browser (browser_name : str ):
51- CurrentExecution .playwright = sync_playwright ().start ()
52- CurrentExecution .playwright .selectors .set_test_id_attribute ("data-qa" )
53- match browser_name .lower ():
54- case "chromium" :
55- CurrentExecution .launch_chromium ()
56- case "msedge" :
57- CurrentExecution .launch_edge ()
58- case "firefox" :
59- CurrentExecution .launch_firefox ()
60- case "chrome" : # Google Chrome for all other cases
61- CurrentExecution .launch_chrome ()
62- case _: # Mobile browsers
63- CurrentExecution .launch_mobile_browser (device_name = browser_name )
64-
65- @staticmethod
66- def start_page (w_type : workflow_type ):
67- CurrentExecution .page = CurrentExecution .context .new_page ()
68- match w_type .lower ():
69- case workflow_type .PARENTAL_CONSENT :
70- CurrentExecution .page .goto (url = CurrentExecution .parental_consent_url )
71- case _:
72- CurrentExecution .reset_upload_data ()
73- CurrentExecution .page .goto (url = CurrentExecution .environment )
74-
75- @staticmethod
76- def quit_browser ():
77- CurrentExecution .browser .close ()
78-
79- @staticmethod
80- def close_page ():
81- if CurrentExecution .page .get_by_role ("button" , name = "Log out" ).is_visible ():
82- CurrentExecution .page .get_by_role ("button" , name = "Log out" ).click ()
83- CurrentExecution .page .close ()
84-
85- @staticmethod
86- def launch_chromium ():
87- try :
88- CurrentExecution .browser = CurrentExecution .playwright .chromium .launch (
89- headless = CurrentExecution .headless_mode , args = ["--fullscreen" ]
90- )
91- CurrentExecution .context = CurrentExecution .browser .new_context (
92- http_credentials = {
93- "username" : CurrentExecution .base_auth_username ,
94- "password" : CurrentExecution .base_auth_password ,
95- }
96- )
97- except Exception as e :
98- raise AssertionError (f"Error launching Chromium: { e } " )
99-
100- @staticmethod
101- def launch_edge ():
102- try :
103- CurrentExecution .browser = CurrentExecution .playwright .chromium .launch (
104- channel = "msedge" , headless = CurrentExecution .headless_mode , args = ["--fullscreen" ]
105- )
106- CurrentExecution .context = CurrentExecution .browser .new_context (
107- http_credentials = {
108- "username" : CurrentExecution .base_auth_username ,
109- "password" : CurrentExecution .base_auth_password ,
110- }
111- )
112-
113- except Exception as e :
114- raise AssertionError (f"Error launching Edge: { e } " )
115-
116- @staticmethod
117- def launch_firefox ():
118- try :
119- CurrentExecution .browser = CurrentExecution .playwright .firefox .launch (
120- headless = CurrentExecution .headless_mode , args = ["--fullscreen" ]
121- )
122- CurrentExecution .context = CurrentExecution .browser .new_context (
123- http_credentials = {
124- "username" : CurrentExecution .base_auth_username ,
125- "password" : CurrentExecution .base_auth_password ,
126- }
127- )
128-
129- except Exception as e :
130- raise AssertionError (f"Error launching Firefox: { e } " )
131-
132- @staticmethod
133- def launch_chrome ():
134- try :
135- CurrentExecution .browser = CurrentExecution .playwright .chromium .launch (
136- channel = "chrome" , headless = CurrentExecution .headless_mode , args = ["--fullscreen" ]
137- )
138- CurrentExecution .context = CurrentExecution .browser .new_context (
139- http_credentials = {
140- "username" : CurrentExecution .base_auth_username ,
141- "password" : CurrentExecution .base_auth_password ,
142- }
143- )
144-
145- except Exception as e :
146- raise AssertionError (f"Error launching Chrome: { e } " )
147-
148- @staticmethod
149- def launch_mobile_browser (device_name : str ):
150- _http_credentials = {
151- "username" : CurrentExecution .base_auth_username ,
152- "password" : CurrentExecution .base_auth_password ,
153- }
154- try :
155- match device_name .lower ():
156- case "iphone_12" :
157- CurrentExecution .browser = CurrentExecution .playwright .webkit .launch (
158- headless = CurrentExecution .headless_mode
159- )
160- CurrentExecution .context = CurrentExecution .browser .new_context (
161- ** CurrentExecution .playwright .devices ["iPhone 12" ], http_credentials = _http_credentials
162- )
163- case "iphone_11" :
164- CurrentExecution .browser = CurrentExecution .playwright .chromium .launch (
165- channel = "chrome" , headless = CurrentExecution .headless_mode
166- )
167- CurrentExecution .context = CurrentExecution .browser .new_context (
168- ** CurrentExecution .playwright .devices ["iPhone 11" ], http_credentials = _http_credentials
169- )
170- case "pixel_5" :
171- CurrentExecution .browser = CurrentExecution .playwright .webkit .launch (
172- headless = CurrentExecution .headless_mode
173- )
174- CurrentExecution .context = CurrentExecution .browser .new_context (
175- ** CurrentExecution .playwright .devices ["Pixel 5" ], http_credentials = _http_credentials
176- )
177- case _:
178- CurrentExecution .browser = CurrentExecution .playwright .chromium .launch (
179- channel = "chromium" , headless = CurrentExecution .headless_mode
180- )
181- CurrentExecution .context = CurrentExecution .browser .new_context (
182- ** CurrentExecution .playwright .devices ["Galaxy S9+" ], http_credentials = _http_credentials
183- )
184- except Exception as e :
185- raise AssertionError (f"Error launching device browser { device_name } : { e } " )
186-
187- @staticmethod
188- def reset_upload_data ():
39+ def reset_environment ():
18940 _headers = {"Authorization" : CurrentExecution .api_token }
190- # _ = api_ops.api_operations().api_get(endpoint=CurrentExecution.reset_endpoint, header=_headers, param=None)
41+ _ = api_ops .api_operations ().api_get (endpoint = CurrentExecution .reset_endpoint , header = _headers , param = None )
0 commit comments