(test_logpath, driver, source=None)
| 354 | |
| 355 | |
| 356 | def log_page_source(test_logpath, driver, source=None): |
| 357 | html_file_name = settings.PAGE_SOURCE_NAME |
| 358 | if source: |
| 359 | page_source = source |
| 360 | else: |
| 361 | try: |
| 362 | page_source = None |
| 363 | if __is_cdp_swap_needed(driver): |
| 364 | page_source = driver.cdp.get_page_source() |
| 365 | else: |
| 366 | page_source = driver.page_source |
| 367 | page_source = get_html_source_with_base_href(driver, page_source) |
| 368 | except Exception: |
| 369 | source = constants.Warnings.PAGE_SOURCE_UNDEFINED |
| 370 | page_source = constants.Warnings.PAGE_SOURCE_UNDEFINED |
| 371 | if source == constants.Warnings.PAGE_SOURCE_UNDEFINED: |
| 372 | page_source = ( |
| 373 | "<h3>Warning: " |
| 374 | + source |
| 375 | + ( |
| 376 | "</h3>\n<h4>The browser window was either unreachable, " |
| 377 | "unresponsive, or closed prematurely!</h4>" |
| 378 | ) |
| 379 | ) |
| 380 | if not os.path.exists(test_logpath): |
| 381 | with suppress(Exception): |
| 382 | os.makedirs(test_logpath) |
| 383 | html_file_path = os.path.join(test_logpath, html_file_name) |
| 384 | with suppress(Exception): |
| 385 | html_file = open(html_file_path, mode="w+", encoding="utf-8") |
| 386 | html_file.write(page_source) |
| 387 | html_file.close() |
| 388 | shared_utils.make_writable(html_file_path) |
| 389 | |
| 390 | |
| 391 | def get_test_id(test): |
nothing calls this directly
no test coverage detected
searching dependent graphs…