|
1 | | -# Copyright 2023 The MathWorks, Inc. |
| 1 | +# Copyright 2023-2024 The MathWorks, Inc. |
2 | 2 | # Utility functions for integration testing of jupyter-matlab-proxy |
3 | 3 |
|
4 | 4 | import asyncio |
@@ -148,45 +148,54 @@ def license_matlab_proxy(matlab_proxy_url): |
148 | 148 | TEST_PASSWORD = os.environ["TEST_PASSWORD"] |
149 | 149 |
|
150 | 150 | with sync_playwright() as playwright: |
151 | | - browser = playwright.chromium.launch(headless=True) |
152 | | - page = browser.new_page() |
153 | | - page.goto(matlab_proxy_url) |
154 | | - |
155 | | - # Find the MHLM licensing windows in matlab-proxy |
156 | | - mhlm_div = page.locator("#MHLM") |
157 | | - expect( |
158 | | - mhlm_div, |
159 | | - "Wait for MHLM licensing window to appear. This might fail if the MATLAB is already licensed", |
160 | | - ).to_be_visible(timeout=60000) |
161 | | - |
162 | | - # The login iframe is present within the MHLM Div |
163 | | - login_iframe = mhlm_div.frame_locator("#loginframe") |
164 | | - |
165 | | - # Fills in the username textbox |
166 | | - email_text_box = login_iframe.locator("#userId") |
167 | | - expect( |
168 | | - email_text_box, |
169 | | - "Wait for email ID textbox to appear", |
170 | | - ).to_be_visible(timeout=20000) |
171 | | - email_text_box.fill(TEST_USERNAME) |
172 | | - email_text_box.press("Enter") |
173 | | - |
174 | | - # Fills in the password textbox |
175 | | - password_text_box = login_iframe.locator("#password") |
176 | | - expect(password_text_box, "Wait for password textbox to appear").to_be_visible( |
177 | | - timeout=20000 |
178 | | - ) |
179 | | - password_text_box.fill(TEST_PASSWORD) |
180 | | - password_text_box.press("Enter") |
181 | | - password_text_box.press("Enter") |
182 | | - |
183 | | - # Verifies if licensing is successful by checking the status information |
184 | | - status_info = page.get_by_text("Status Information") |
185 | | - expect( |
186 | | - status_info, |
187 | | - "Verify if Licensing is successful. This might fail if incorrect credentials are provided", |
188 | | - ).to_be_visible(timeout=60000) |
189 | | - browser.close() |
| 151 | + try: |
| 152 | + browser = playwright.chromium.launch(headless=True) |
| 153 | + page = browser.new_page() |
| 154 | + page.goto(matlab_proxy_url) |
| 155 | + |
| 156 | + # Find the MHLM licensing windows in matlab-proxy |
| 157 | + mhlm_div = page.locator("#MHLM") |
| 158 | + expect( |
| 159 | + mhlm_div, |
| 160 | + "Wait for MHLM licensing window to appear. This might fail if the MATLAB is already licensed", |
| 161 | + ).to_be_visible(timeout=60000) |
| 162 | + |
| 163 | + # The login iframe is present within the MHLM Div |
| 164 | + login_iframe = mhlm_div.frame_locator("#loginframe") |
| 165 | + |
| 166 | + # Fills in the username textbox |
| 167 | + email_text_box = login_iframe.locator("#userId") |
| 168 | + expect( |
| 169 | + email_text_box, |
| 170 | + "Wait for email ID textbox to appear", |
| 171 | + ).to_be_visible(timeout=20000) |
| 172 | + email_text_box.fill(TEST_USERNAME) |
| 173 | + email_text_box.press("Enter") |
| 174 | + |
| 175 | + # Fills in the password textbox |
| 176 | + password_text_box = login_iframe.locator("#password") |
| 177 | + expect( |
| 178 | + password_text_box, "Wait for password textbox to appear" |
| 179 | + ).to_be_visible(timeout=20000) |
| 180 | + password_text_box.fill(TEST_PASSWORD) |
| 181 | + password_text_box.press("Enter") |
| 182 | + password_text_box.press("Enter") |
| 183 | + |
| 184 | + # Verifies if licensing is successful by checking the status information |
| 185 | + status_info = page.get_by_text("Status Information") |
| 186 | + expect( |
| 187 | + status_info, |
| 188 | + "Verify if Licensing is successful. This might fail if incorrect credentials are provided", |
| 189 | + ).to_be_visible(timeout=60000) |
| 190 | + except: |
| 191 | + # Grab screenshots |
| 192 | + log_dir = "./" |
| 193 | + file_name = "licensing-screenshot-failed.png" |
| 194 | + file_path = os.path.join(log_dir, file_name) |
| 195 | + os.makedirs(log_dir, exist_ok=True) |
| 196 | + page.screenshot(path=file_path) |
| 197 | + finally: |
| 198 | + browser.close() |
190 | 199 |
|
191 | 200 |
|
192 | 201 | def unlicense_matlab_proxy(matlab_proxy_url): |
|
0 commit comments