MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / log_screenshot

Function log_screenshot

seleniumbase/core/log_helper.py:22–51  ·  view source on GitHub ↗
(test_logpath, driver, screenshot=None, get=False)

Source from the content-addressed store, hash-verified

20
21
22def 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
54def get_master_time():

Callers

nothing calls this directly

Calls 2

writeMethod · 0.80
find_elementMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…