|
5 | 5 | import sys
|
6 | 6 | import time
|
7 | 7 | from seleniumbase.config import settings
|
| 8 | +from seleniumbase.fixtures import constants |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def log_screenshot(test_logpath, driver, screenshot=None, get=False):
|
11 | 12 | screenshot_name = settings.SCREENSHOT_NAME
|
12 | 13 | screenshot_path = "%s/%s" % (test_logpath, screenshot_name)
|
| 14 | + screenshot_warning = constants.Warnings.SCREENSHOT_UNDEFINED |
13 | 15 | try:
|
14 | 16 | if not screenshot:
|
15 | 17 | element = driver.find_element_by_tag_name('body')
|
16 | 18 | screenshot = element.screenshot_as_base64
|
17 |
| - with open(screenshot_path, "wb") as file: |
18 |
| - file.write(screenshot) |
| 19 | + if screenshot != screenshot_warning: |
| 20 | + with open(screenshot_path, "wb") as file: |
| 21 | + file.write(screenshot) |
| 22 | + else: |
| 23 | + print("WARNING: %s" % screenshot_warning) |
19 | 24 | if get:
|
20 | 25 | return screenshot
|
21 | 26 | except Exception:
|
22 | 27 | try:
|
23 | 28 | driver.get_screenshot_as_file(screenshot_path)
|
24 | 29 | except Exception:
|
25 |
| - print("WARNING: Unable to get screenshot for failure logs!") |
| 30 | + print("WARNING: %s" % screenshot_warning) |
26 | 31 |
|
27 | 32 |
|
28 | 33 | def get_master_time():
|
@@ -72,13 +77,15 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
|
72 | 77 | test_id = get_test_id(test)
|
73 | 78 | data_to_save = []
|
74 | 79 | data_to_save.append("%s" % test_id)
|
75 |
| - data_to_save.append("----------------------------------------------------") |
| 80 | + data_to_save.append( |
| 81 | + "--------------------------------------------------------------------") |
76 | 82 | data_to_save.append("Last Page: %s" % last_page)
|
77 | 83 | data_to_save.append(" Browser: %s" % browser)
|
78 | 84 | data_to_save.append("Timestamp: %s" % timestamp)
|
79 | 85 | data_to_save.append(" Date: %s" % the_date)
|
80 | 86 | data_to_save.append(" Time: %s" % the_time)
|
81 |
| - data_to_save.append("----------------------------------------------------") |
| 87 | + data_to_save.append( |
| 88 | + "--------------------------------------------------------------------") |
82 | 89 | if sys.version_info[0] >= 3 and hasattr(test, '_outcome') and (
|
83 | 90 | hasattr(test._outcome, 'errors') and test._outcome.errors):
|
84 | 91 | try:
|
@@ -128,6 +135,10 @@ def log_page_source(test_logpath, driver, source=None):
|
128 | 135 | except Exception:
|
129 | 136 | # Since we can't get the page source from here, skip saving it
|
130 | 137 | return
|
| 138 | + if source == constants.Warnings.PAGE_SOURCE_UNDEFINED: |
| 139 | + page_source = "<h3>Warning: " + source + ( |
| 140 | + "</h3>\n<h4>The browser window was either unreachable, " |
| 141 | + "unresponsive, or closed prematurely!</h4>") |
131 | 142 | html_file_path = "%s/%s" % (test_logpath, html_file_name)
|
132 | 143 | html_file = codecs.open(html_file_path, "w+", "utf-8")
|
133 | 144 | rendered_source = get_html_source_with_base_href(driver, page_source)
|
|
0 commit comments