(test_logpath, driver, screenshot=None, get=False)
| 20 | |
| 21 | |
| 22 | def log_screenshot(test_logpath, driver, screenshot=None, get=False): |
| 23 | screenshot_name = settings.SCREENSHOT_NAME |
| 24 | screenshot_path = os.path.join(test_logpath, screenshot_name) |
| 25 | screenshot_skipped = constants.Warnings.SCREENSHOT_SKIPPED |
| 26 | screenshot_warning = constants.Warnings.SCREENSHOT_UNDEFINED |
| 27 | if ( |
| 28 | getattr(sb_config, "no_screenshot", None) |
| 29 | or screenshot == screenshot_skipped |
| 30 | ): |
| 31 | if get: |
| 32 | return screenshot |
| 33 | return |
| 34 | try: |
| 35 | if not screenshot: |
| 36 | element = driver.find_element("tag name", "body") |
| 37 | screenshot = element.screenshot_as_base64 |
| 38 | if screenshot != screenshot_warning: |
| 39 | with open(screenshot_path, mode="wb") as file: |
| 40 | file.write(screenshot) |
| 41 | with suppress(Exception): |
| 42 | shared_utils.make_writable(screenshot_path) |
| 43 | else: |
| 44 | print("WARNING: %s" % screenshot_warning) |
| 45 | if get: |
| 46 | return screenshot |
| 47 | except Exception: |
| 48 | try: |
| 49 | driver.get_screenshot_as_file(screenshot_path) |
| 50 | except Exception: |
| 51 | print("WARNING: %s" % screenshot_warning) |
| 52 | |
| 53 | |
| 54 | def get_master_time(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…