Skip to content

Commit ecf25a8

Browse files
authored
Merge pull request #309 from seleniumbase/update-reports
Update test reports
2 parents cdc39f1 + 43bc8b9 commit ecf25a8

File tree

7 files changed

+53
-12
lines changed

7 files changed

+53
-12
lines changed

seleniumbase/config/proxy_list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"""
2020

2121
PROXY_LIST = {
22-
"example1": "159.122.164.163:8080", # (Example) - set your own proxy here
23-
"example2": "158.69.138.8:1080", # (Example) - set your own proxy here
22+
"example1": "158.69.138.8:1080", # (Example) - set your own proxy here
2423
"proxy1": None,
2524
"proxy2": None,
2625
"proxy3": None,

seleniumbase/core/log_helper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
from seleniumbase.config import settings
88

99

10-
def log_screenshot(test_logpath, driver, screenshot=None):
10+
def log_screenshot(test_logpath, driver, screenshot=None, get=False):
1111
screenshot_name = settings.SCREENSHOT_NAME
1212
screenshot_path = "%s/%s" % (test_logpath, screenshot_name)
1313
try:
1414
if not screenshot:
1515
element = driver.find_element_by_tag_name('body')
16-
screenshot = element.screenshot_as_png
16+
screenshot = element.screenshot_as_base64
1717
with open(screenshot_path, "wb") as file:
1818
file.write(screenshot)
19+
if get:
20+
return screenshot
1921
except Exception:
2022
try:
2123
driver.get_screenshot_as_file(screenshot_path)

seleniumbase/core/report_helper.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@
66
from seleniumbase.config import settings
77
from seleniumbase.core.style_sheet import style
88
from seleniumbase.fixtures import page_actions
9+
from seleniumbase import drivers
910

1011
LATEST_REPORT_DIR = settings.LATEST_REPORT_DIR
1112
ARCHIVE_DIR = settings.REPORT_ARCHIVE_DIR
1213
HTML_REPORT = settings.HTML_REPORT
1314
RESULTS_TABLE = settings.RESULTS_TABLE
15+
DRIVER_DIR = os.path.dirname(os.path.realpath(drivers.__file__))
16+
PLATFORM = sys.platform
17+
LOCAL_CHROMEDRIVER = None
18+
LOCAL_GECKODRIVER = None
19+
if "darwin" in PLATFORM or "linux" in PLATFORM:
20+
LOCAL_CHROMEDRIVER = DRIVER_DIR + '/chromedriver'
21+
LOCAL_GECKODRIVER = DRIVER_DIR + '/geckodriver'
22+
elif "win32" in PLATFORM or "win64" in PLATFORM or "x64" in PLATFORM:
23+
LOCAL_CHROMEDRIVER = DRIVER_DIR + '/chromedriver.exe'
24+
LOCAL_GECKODRIVER = DRIVER_DIR + '/geckodriver.exe'
1425

1526

1627
def get_timestamp():
@@ -35,8 +46,9 @@ def process_successes(test, test_count, duration):
3546
def process_failures(test, test_count, browser_type, duration):
3647
bad_page_image = "failure_%s.png" % test_count
3748
bad_page_data = "failure_%s.txt" % test_count
38-
page_actions.save_screenshot(
39-
test.driver, bad_page_image, folder=LATEST_REPORT_DIR)
49+
screenshot_path = "%s/%s" % (LATEST_REPORT_DIR, bad_page_image)
50+
with open(screenshot_path, "wb") as file:
51+
file.write(test._last_page_screenshot)
4052
page_actions.save_test_failure_data(
4153
test.driver, bad_page_data, browser_type, folder=LATEST_REPORT_DIR)
4254
exc_info = '(Unknown Failure)'
@@ -54,7 +66,7 @@ def process_failures(test, test_count, browser_type, duration):
5466
"FAILED!",
5567
bad_page_data,
5668
bad_page_image,
57-
test.driver.current_url,
69+
test._last_page_url,
5870
test.browser,
5971
get_timestamp()[:-3],
6072
duration,
@@ -222,10 +234,25 @@ def build_report(report_log_path, page_results_list,
222234
"\n* Files saved for this report are located at:\n" + report_log_path)
223235
print("")
224236
if show_report:
237+
browser = None
238+
profile = webdriver.FirefoxProfile()
239+
profile.set_preference("app.update.auto", False)
240+
profile.set_preference("app.update.enabled", False)
241+
profile.set_preference("browser.privatebrowsing.autostart", True)
225242
if browser_type == 'firefox':
226-
browser = webdriver.Firefox()
243+
if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
244+
browser = webdriver.Firefox(
245+
firefox_profile=profile, executable_path=LOCAL_GECKODRIVER)
246+
else:
247+
browser = webdriver.Firefox(firefox_profile=profile)
227248
else:
228-
browser = webdriver.Chrome()
249+
chrome_options = webdriver.ChromeOptions()
250+
chrome_options.add_argument("--disable-infobars")
251+
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
252+
browser = webdriver.Chrome(
253+
executable_path=LOCAL_CHROMEDRIVER, options=chrome_options)
254+
else:
255+
browser = webdriver.Chrome(options=chrome_options)
229256
browser.get("file://%s" % archived_results_file)
230257
print("\n*** Close the html report window to continue. ***")
231258
while len(browser.window_handles):

seleniumbase/fixtures/base_case.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3158,7 +3158,10 @@ def __set_last_page_screenshot(self):
31583158
if not self.__last_page_screenshot:
31593159
try:
31603160
element = self.driver.find_element_by_tag_name('body')
3161-
self.__last_page_screenshot = element.screenshot_as_base64
3161+
if self.is_pytest:
3162+
self.__last_page_screenshot = element.screenshot_as_base64
3163+
else:
3164+
self.__last_page_screenshot = element.screenshot_as_png
31623165
except Exception:
31633166
pass
31643167

@@ -3407,5 +3410,11 @@ def tearDown(self):
34073410
test_logpath,
34083411
self.driver,
34093412
self.__last_page_screenshot)
3413+
if self.report_on:
3414+
self._last_page_screenshot = self.__last_page_screenshot
3415+
try:
3416+
self._last_page_url = self.get_current_url()
3417+
except Exception:
3418+
self._last_page_url = "(Error: Unknown URL)"
34103419
# Finally close all open browser windows
34113420
self.__quit_all_drivers()

seleniumbase/fixtures/page_actions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ def save_screenshot(driver, name, folder=None):
424424
with open(screenshot_path, "wb") as file:
425425
file.write(element_png)
426426
except Exception:
427-
driver.get_screenshot_as_file(screenshot_path)
427+
if driver:
428+
driver.get_screenshot_as_file(screenshot_path)
429+
else:
430+
pass
428431

429432

430433
def _get_last_page(driver):

seleniumbase/plugins/base_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def beforeTest(self, test):
105105
test.test.env = self.options.environment # Add a shortened version
106106
test.test.data = self.options.data
107107
test.test.args = self.options
108+
test.test.report_on = self.report_on
108109
self.test_count += 1
109110
self.start_time = float(time.time())
110111

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.22.5',
20+
version='1.22.6',
2121
description='Reliable Browser Automation & Testing Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)