11import os
22
33from 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
98class 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