Merge pull request #1363 from seleniumbase/window-size-option-and-logging-updates
Window Size option and logging output updates
This commit is contained in:
commit
53eb2ba8b7
|
@ -489,7 +489,8 @@ The code above will leave your browser window open in case there's a failure. (i
|
|||
--devtools # (Open Chrome's DevTools when the browser opens.)
|
||||
--reuse-session | --rs # (Reuse the browser session between tests.)
|
||||
--crumbs # (Delete all cookies between tests reusing a session.)
|
||||
--maximize # (Start tests with the web browser window maximized.)
|
||||
--window-size # (Set the browser window size: "Width,Height".)
|
||||
--maximize # (Start tests with the browser window maximized.)
|
||||
--screenshot # (Save a screenshot at the end of each test.)
|
||||
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
|
||||
--external-pdf # (Set Chrome "plugins.always_open_pdf_externally": True.)
|
||||
|
|
|
@ -69,6 +69,7 @@ if pure_python:
|
|||
sb._reuse_session = False
|
||||
sb._crumbs = False
|
||||
sb.visual_baseline = False
|
||||
sb.window_size = None
|
||||
sb.maximize_option = False
|
||||
sb.save_screenshot_after_test = False
|
||||
sb.timeout_multiplier = None
|
||||
|
|
|
@ -22,7 +22,7 @@ class AppleTests(BaseCase):
|
|||
self.click("link=%s" % title)
|
||||
self.assert_element("nav.documentation-nav")
|
||||
self.assert_text(title, "h1")
|
||||
self.highlight("div.description div.abstract")
|
||||
self.assert_text("Enable WebDriver and run a test.", "div.abstract")
|
||||
self.highlight("h2")
|
||||
h3 = "h3:nth-of-type(%s)"
|
||||
self.assert_text("Make Sure You Have Safari’s WebDriver", h3 % "1")
|
||||
|
|
|
@ -14,3 +14,4 @@ class ErrorPageTests(BaseCase):
|
|||
self.highlight('img[alt*="404"]')
|
||||
self.highlight("img#octobi_wan_catnobi")
|
||||
self.highlight("img#speeder")
|
||||
self.save_screenshot_after_test = True # Automatic if test fails
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
|
||||
|
@ -9,7 +10,9 @@ class MyTourClass(BaseCase):
|
|||
self.wait_for_element("#zoom", timeout=20)
|
||||
|
||||
self.create_tour(theme="introjs")
|
||||
self.add_tour_step("Welcome to Google Maps", title="SeleniumBase Tour")
|
||||
self.add_tour_step(
|
||||
"Welcome to Google Maps", title="✅ SeleniumBase Tours 🌎"
|
||||
)
|
||||
self.add_tour_step(
|
||||
"The location goes here.", "#searchboxinput", title="Search Box"
|
||||
)
|
||||
|
@ -45,7 +48,8 @@ class MyTourClass(BaseCase):
|
|||
alignment="left",
|
||||
)
|
||||
self.add_tour_step(
|
||||
"Thanks for using SeleniumBase Tours!", title="End of Guided Tour"
|
||||
"Thanks for using SeleniumBase Tours!",
|
||||
title="🚃 End of Guided Tour 🚃"
|
||||
)
|
||||
self.export_tour(filename="maps_introjs_tour.js")
|
||||
self.play_tour()
|
||||
|
|
|
@ -164,7 +164,8 @@ pytest my_first_test.py --settings-file=custom_settings.py
|
|||
--devtools # (Open Chrome's DevTools when the browser opens.)
|
||||
--reuse-session | --rs # (Reuse the browser session between tests.)
|
||||
--crumbs # (Delete all cookies between tests reusing a session.)
|
||||
--maximize # (Start tests with the web browser window maximized.)
|
||||
--window-size # (Set the browser window size: "Width,Height".)
|
||||
--maximize # (Start tests with the browser window maximized.)
|
||||
--screenshot # (Save a screenshot at the end of each test.)
|
||||
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
|
||||
--external-pdf # (Set Chrome "plugins.always_open_pdf_externally": True.)
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# seleniumbase package
|
||||
__version__ = "3.2.7"
|
||||
__version__ = "3.2.8"
|
||||
|
|
|
@ -75,7 +75,8 @@ behave -D agent="User Agent String" -D demo
|
|||
-D devtools (Open Chrome's DevTools when the browser opens.)
|
||||
-D reuse-session | -D rs (Reuse browser session between tests.)
|
||||
-D crumbs (Delete all cookies between tests reusing a session.)
|
||||
-D maximize (Start tests with the web browser window maximized.)
|
||||
-D window-size (Set the browser window size: "Width,Height".)
|
||||
-D maximize (Start tests with the browser window maximized.)
|
||||
-D screenshot (Save a screenshot at the end of each test.)
|
||||
-D visual-baseline (Set the visual baseline for Visual/Layout tests.)
|
||||
-D external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.)
|
||||
|
@ -160,6 +161,7 @@ def get_configured_sb(context):
|
|||
sb._reuse_session = False
|
||||
sb._crumbs = False
|
||||
sb.visual_baseline = False
|
||||
sb.window_size = None
|
||||
sb.maximize_option = False
|
||||
sb.save_screenshot_after_test = False
|
||||
sb.timeout_multiplier = None
|
||||
|
@ -469,6 +471,13 @@ def get_configured_sb(context):
|
|||
if low_key in ["visual-baseline", "visual_baseline"]:
|
||||
sb.visual_baseline = True
|
||||
continue
|
||||
# Handle: -D window-size=Width,Height / window_size=Width,Height
|
||||
if low_key in ["window-size", "window_size"]:
|
||||
window_size = userdata[key]
|
||||
if window_size == "true":
|
||||
window_size = sb.window_size # revert to default
|
||||
sb.window_size = window_size
|
||||
continue
|
||||
# Handle: -D maximize / fullscreen / maximize-window
|
||||
if low_key in [
|
||||
"maximize", "fullscreen", "maximize-window", "maximize_window"
|
||||
|
@ -693,13 +702,40 @@ def get_configured_sb(context):
|
|||
# If the port is "443", the protocol is "https"
|
||||
if str(sb.port) == "443":
|
||||
sb.protocol = "https"
|
||||
if sb.window_size:
|
||||
window_size = sb.window_size
|
||||
if window_size.count(",") != 1:
|
||||
message = (
|
||||
'\n\n window_size expects a "width,height" string!'
|
||||
'\n (Your input was: "%s")\n' % window_size
|
||||
)
|
||||
raise Exception(message)
|
||||
window_size = window_size.replace(" ", "")
|
||||
width = None
|
||||
height = None
|
||||
try:
|
||||
width = int(window_size.split(",")[0])
|
||||
height = int(window_size.split(",")[1])
|
||||
except Exception:
|
||||
message = (
|
||||
'\n\n Expecting integer values for "width,height"!'
|
||||
'\n (window_size input was: "%s")\n' % window_size
|
||||
)
|
||||
raise Exception(message)
|
||||
settings.CHROME_START_WIDTH = width
|
||||
settings.CHROME_START_HEIGHT = height
|
||||
settings.HEADLESS_START_WIDTH = width
|
||||
settings.HEADLESS_START_HEIGHT = height
|
||||
|
||||
# Set sb_config
|
||||
sb_config.browser = sb.browser
|
||||
sb_config.headless = sb.headless
|
||||
sb_config.headed = sb.headed
|
||||
sb_config.window_size = sb.window_size
|
||||
sb_config.maximize_option = sb.maximize_option
|
||||
sb_config.xvfb = sb.xvfb
|
||||
sb_config.save_screenshot = sb.save_screenshot_after_test
|
||||
sb_config._has_logs = False
|
||||
sb_config.variables = sb.variables
|
||||
sb_config.dashboard = sb.dashboard
|
||||
sb_config.dash_title = sb.dash_title
|
||||
|
@ -1035,7 +1071,11 @@ def _perform_behave_terminal_summary_():
|
|||
if sb_config.dashboard:
|
||||
# Print link a second time because the first one may be off-screen
|
||||
print("%s- Dashboard:%s %s" % (c2, cr, dash_path))
|
||||
if sb_config._has_exception or sb_config.save_screenshot:
|
||||
if (
|
||||
sb_config._has_exception
|
||||
or sb_config.save_screenshot
|
||||
or sb_config._has_logs
|
||||
):
|
||||
# Log files are generated during test failures and Screenshot Mode
|
||||
print("%s--- LogPath:%s %s" % (c2, cr, latest_logs_dir))
|
||||
if (
|
||||
|
|
|
@ -3259,6 +3259,7 @@ class BaseCase(unittest.TestCase):
|
|||
origin = self.get_origin()
|
||||
action = ["ss_tl", "", origin, time_stamp]
|
||||
self.__extra_actions.append(action)
|
||||
sb_config._has_logs = True
|
||||
return page_actions.save_screenshot(self.driver, name, test_logpath)
|
||||
|
||||
def save_page_source(self, name, folder=None):
|
||||
|
@ -11970,6 +11971,31 @@ class BaseCase(unittest.TestCase):
|
|||
self.extension_zip = sb_config.extension_zip
|
||||
self.extension_dir = sb_config.extension_dir
|
||||
self.external_pdf = sb_config.external_pdf
|
||||
self.window_size = sb_config.window_size
|
||||
window_size = self.window_size
|
||||
if window_size:
|
||||
if window_size.count(",") != 1:
|
||||
message = (
|
||||
'\n\n window_size expects a "width,height" string!'
|
||||
'\n (Your input was: "%s")\n' % window_size
|
||||
)
|
||||
raise Exception(message)
|
||||
window_size = window_size.replace(" ", "")
|
||||
width = None
|
||||
height = None
|
||||
try:
|
||||
width = int(window_size.split(",")[0])
|
||||
height = int(window_size.split(",")[1])
|
||||
except Exception:
|
||||
message = (
|
||||
'\n\n Expecting integer values for "width,height"!'
|
||||
'\n (window_size input was: "%s")\n' % window_size
|
||||
)
|
||||
raise Exception(message)
|
||||
settings.CHROME_START_WIDTH = width
|
||||
settings.CHROME_START_HEIGHT = height
|
||||
settings.HEADLESS_START_WIDTH = width
|
||||
settings.HEADLESS_START_HEIGHT = height
|
||||
self.maximize_option = sb_config.maximize_option
|
||||
self.save_screenshot_after_test = sb_config.save_screenshot
|
||||
self.visual_baseline = sb_config.visual_baseline
|
||||
|
@ -12945,6 +12971,7 @@ class BaseCase(unittest.TestCase):
|
|||
self.__set_last_page_screenshot()
|
||||
self.__set_last_page_url()
|
||||
self.__set_last_page_source()
|
||||
sb_config._has_logs = True
|
||||
if self.is_pytest:
|
||||
self.__add_pytest_html_extra()
|
||||
|
||||
|
@ -13025,6 +13052,7 @@ class BaseCase(unittest.TestCase):
|
|||
if has_exception:
|
||||
self.__add_pytest_html_extra()
|
||||
sb_config._has_exception = True
|
||||
sb_config._has_logs = True
|
||||
if (
|
||||
self.with_testing_base
|
||||
and not has_exception
|
||||
|
@ -13042,6 +13070,7 @@ class BaseCase(unittest.TestCase):
|
|||
self.__last_page_screenshot_png,
|
||||
)
|
||||
self.__add_pytest_html_extra()
|
||||
sb_config._has_logs = True
|
||||
if self.with_testing_base and has_exception:
|
||||
test_logpath = os.path.join(self.log_path, test_id)
|
||||
self.__create_log_path_as_needed(test_logpath)
|
||||
|
|
|
@ -86,7 +86,8 @@ def pytest_addoption(parser):
|
|||
--devtools (Open Chrome's DevTools when the browser opens.)
|
||||
--reuse-session | --rs (Reuse browser session between tests.)
|
||||
--crumbs (Delete all cookies between tests reusing a session.)
|
||||
--maximize (Start tests with the web browser window maximized.)
|
||||
--window-size (Set the browser window size: "Width,Height".)
|
||||
--maximize (Start tests with the browser window maximized.)
|
||||
--screenshot (Save a screenshot at the end of each test.)
|
||||
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
|
||||
--external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.)
|
||||
|
@ -893,6 +894,17 @@ def pytest_addoption(parser):
|
|||
that reuse the same browser session. This option
|
||||
is only needed when using "--reuse-session".""",
|
||||
)
|
||||
parser.addoption(
|
||||
"--window-size",
|
||||
"--window_size",
|
||||
action="store",
|
||||
dest="window_size",
|
||||
default=None,
|
||||
help="""The option to set the default window "width,height".
|
||||
Format: A comma-separated string with the 2 values.
|
||||
Example: "1200,800"
|
||||
Default: None. (Will use default values if None)""",
|
||||
)
|
||||
parser.addoption(
|
||||
"--maximize_window",
|
||||
"--maximize-window",
|
||||
|
@ -901,8 +913,8 @@ def pytest_addoption(parser):
|
|||
action="store_true",
|
||||
dest="maximize_option",
|
||||
default=False,
|
||||
help="""The option to start with the browser window
|
||||
maximized.""",
|
||||
help="""The option to start with a maximized browser window.
|
||||
(Overrides the "window-size" option if used.)""",
|
||||
)
|
||||
parser.addoption(
|
||||
"--screenshot",
|
||||
|
@ -1190,12 +1202,14 @@ def pytest_configure(config):
|
|||
sb_config.reuse_session = config.getoption("reuse_session")
|
||||
sb_config.crumbs = config.getoption("crumbs")
|
||||
sb_config.shared_driver = None # The default driver for session reuse
|
||||
sb_config.window_size = config.getoption("window_size")
|
||||
sb_config.maximize_option = config.getoption("maximize_option")
|
||||
sb_config.save_screenshot = config.getoption("save_screenshot")
|
||||
sb_config.visual_baseline = config.getoption("visual_baseline")
|
||||
sb_config.external_pdf = config.getoption("external_pdf")
|
||||
sb_config.timeout_multiplier = config.getoption("timeout_multiplier")
|
||||
sb_config._is_timeout_changed = False
|
||||
sb_config._has_logs = False
|
||||
sb_config._SMALL_TIMEOUT = settings.SMALL_TIMEOUT
|
||||
sb_config._LARGE_TIMEOUT = settings.LARGE_TIMEOUT
|
||||
sb_config.pytest_html_report = config.getoption("htmlpath") # --html=FILE
|
||||
|
@ -1461,7 +1475,11 @@ def pytest_terminal_summary(terminalreporter):
|
|||
# Print link a second time because the first one may be off-screen
|
||||
dashboard_file = os.getcwd() + "/dashboard.html"
|
||||
terminalreporter.write_sep("-", "Dashboard: %s" % dashboard_file)
|
||||
if sb_config._has_exception or sb_config.save_screenshot:
|
||||
if (
|
||||
sb_config._has_exception
|
||||
or sb_config.save_screenshot
|
||||
or sb_config._has_logs
|
||||
):
|
||||
# Log files are generated during test failures and Screenshot Mode
|
||||
terminalreporter.write_sep("-", "LogPath: %s" % latest_logs_dir)
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@ class SeleniumBrowser(Plugin):
|
|||
--incognito (Enable Chrome's Incognito mode.)
|
||||
--guest (Enable Chrome's Guest mode.)
|
||||
--devtools (Open Chrome's DevTools when the browser opens.)
|
||||
--maximize (Start tests with the web browser window maximized.)
|
||||
--window-size (Set the browser window size: "Width,Height".)
|
||||
--maximize (Start tests with the browser window maximized.)
|
||||
--screenshot (Save a screenshot at the end of each test.)
|
||||
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
|
||||
--external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.)
|
||||
|
@ -596,6 +597,17 @@ class SeleniumBrowser(Plugin):
|
|||
default=False,
|
||||
help="""Using this opens Chrome's DevTools.""",
|
||||
)
|
||||
parser.add_option(
|
||||
"--window-size",
|
||||
"--window_size",
|
||||
action="store",
|
||||
dest="window_size",
|
||||
default=None,
|
||||
help="""The option to set the default window "width,height".
|
||||
Format: A comma-separated string with the 2 values.
|
||||
Example: "1200,800"
|
||||
Default: None. (Will use default values if None)""",
|
||||
)
|
||||
parser.add_option(
|
||||
"--maximize_window",
|
||||
"--maximize-window",
|
||||
|
@ -604,7 +616,8 @@ class SeleniumBrowser(Plugin):
|
|||
action="store_true",
|
||||
dest="maximize_option",
|
||||
default=False,
|
||||
help="""The option to start with the web browser maximized.""",
|
||||
help="""The option to start with a maximized browser window.
|
||||
(Overrides the "window-size" option if used.)""",
|
||||
)
|
||||
parser.add_option(
|
||||
"--screenshot",
|
||||
|
@ -665,6 +678,30 @@ class SeleniumBrowser(Plugin):
|
|||
'\n (Your browser choice was: "%s")\n' % browser
|
||||
)
|
||||
raise Exception(message)
|
||||
window_size = self.options.window_size
|
||||
if window_size:
|
||||
if window_size.count(",") != 1:
|
||||
message = (
|
||||
'\n\n window_size expects a "width,height" string!'
|
||||
'\n (Your input was: "%s")\n' % window_size
|
||||
)
|
||||
raise Exception(message)
|
||||
window_size = window_size.replace(" ", "")
|
||||
width = None
|
||||
height = None
|
||||
try:
|
||||
width = int(window_size.split(",")[0])
|
||||
height = int(window_size.split(",")[1])
|
||||
except Exception:
|
||||
message = (
|
||||
'\n\n Expecting integer values for "width,height"!'
|
||||
'\n (window_size input was: "%s")\n' % window_size
|
||||
)
|
||||
raise Exception(message)
|
||||
settings.CHROME_START_WIDTH = width
|
||||
settings.CHROME_START_HEIGHT = height
|
||||
settings.HEADLESS_START_WIDTH = width
|
||||
settings.HEADLESS_START_HEIGHT = height
|
||||
test.test.is_nosetest = True
|
||||
test.test.browser = self.options.browser
|
||||
test.test.cap_file = self.options.cap_file
|
||||
|
@ -720,6 +757,7 @@ class SeleniumBrowser(Plugin):
|
|||
test.test.incognito = self.options.incognito
|
||||
test.test.guest_mode = self.options.guest_mode
|
||||
test.test.devtools = self.options.devtools
|
||||
test.test.window_size = self.options.window_size
|
||||
test.test.maximize_option = self.options.maximize_option
|
||||
test.test.save_screenshot_after_test = self.options.save_screenshot
|
||||
test.test.visual_baseline = self.options.visual_baseline
|
||||
|
|
Loading…
Reference in New Issue