Add option for Chrome's Incognito mode with "--incognito"
This commit is contained in:
parent
1e3bb4d998
commit
5767232bfc
|
@ -124,8 +124,9 @@ def _add_chrome_disable_csp_extension(chrome_options):
|
|||
|
||||
|
||||
def _set_chrome_options(
|
||||
downloads_path, headless, proxy_string, proxy_auth,
|
||||
proxy_user, proxy_pass, user_agent, disable_csp, enable_sync,
|
||||
downloads_path, headless,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass,
|
||||
user_agent, disable_csp, enable_sync, incognito,
|
||||
user_data_dir, extension_zip, extension_dir, servername,
|
||||
mobile_emulator, device_width, device_height, device_pixel_ratio):
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
|
@ -164,6 +165,8 @@ def _set_chrome_options(
|
|||
chrome_options.add_experimental_option(
|
||||
"excludeSwitches", ["disable-sync"])
|
||||
chrome_options.add_argument("--enable-sync")
|
||||
if incognito:
|
||||
chrome_options.add_argument("--incognito")
|
||||
if user_data_dir:
|
||||
abs_path = os.path.abspath(user_data_dir)
|
||||
chrome_options.add_argument("user-data-dir=%s" % abs_path)
|
||||
|
@ -323,7 +326,7 @@ def validate_proxy_string(proxy_string):
|
|||
def get_driver(browser_name, headless=False, use_grid=False,
|
||||
servername='localhost', port=4444, proxy_string=None,
|
||||
user_agent=None, cap_file=None, disable_csp=None,
|
||||
enable_sync=None, user_data_dir=None,
|
||||
enable_sync=None, incognito=None, user_data_dir=None,
|
||||
extension_zip=None, extension_dir=None, mobile_emulator=False,
|
||||
device_width=None, device_height=None, device_pixel_ratio=None):
|
||||
proxy_auth = False
|
||||
|
@ -358,14 +361,14 @@ def get_driver(browser_name, headless=False, use_grid=False,
|
|||
return get_remote_driver(
|
||||
browser_name, headless, servername, port,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
|
||||
cap_file, disable_csp, enable_sync, user_data_dir,
|
||||
cap_file, disable_csp, enable_sync, incognito, user_data_dir,
|
||||
extension_zip, extension_dir, mobile_emulator,
|
||||
device_width, device_height, device_pixel_ratio)
|
||||
else:
|
||||
return get_local_driver(
|
||||
browser_name, headless, servername,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
|
||||
disable_csp, enable_sync, user_data_dir,
|
||||
disable_csp, enable_sync, incognito, user_data_dir,
|
||||
extension_zip, extension_dir, mobile_emulator,
|
||||
device_width, device_height, device_pixel_ratio)
|
||||
|
||||
|
@ -373,7 +376,7 @@ def get_driver(browser_name, headless=False, use_grid=False,
|
|||
def get_remote_driver(
|
||||
browser_name, headless, servername, port, proxy_string, proxy_auth,
|
||||
proxy_user, proxy_pass, user_agent, cap_file, disable_csp,
|
||||
enable_sync, user_data_dir, extension_zip, extension_dir,
|
||||
enable_sync, incognito, user_data_dir, extension_zip, extension_dir,
|
||||
mobile_emulator, device_width, device_height, device_pixel_ratio):
|
||||
downloads_path = download_helper.get_downloads_folder()
|
||||
download_helper.reset_downloads_folder()
|
||||
|
@ -383,8 +386,9 @@ def get_remote_driver(
|
|||
desired_caps = capabilities_parser.get_desired_capabilities(cap_file)
|
||||
if browser_name == constants.Browser.GOOGLE_CHROME:
|
||||
chrome_options = _set_chrome_options(
|
||||
downloads_path, headless, proxy_string, proxy_auth,
|
||||
proxy_user, proxy_pass, user_agent, disable_csp, enable_sync,
|
||||
downloads_path, headless,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass,
|
||||
user_agent, disable_csp, enable_sync, incognito,
|
||||
user_data_dir, extension_zip, extension_dir, servername,
|
||||
mobile_emulator, device_width, device_height, device_pixel_ratio)
|
||||
capabilities = chrome_options.to_capabilities()
|
||||
|
@ -495,7 +499,7 @@ def get_remote_driver(
|
|||
def get_local_driver(
|
||||
browser_name, headless, servername,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
|
||||
disable_csp, enable_sync, user_data_dir,
|
||||
disable_csp, enable_sync, incognito, user_data_dir,
|
||||
extension_zip, extension_dir,
|
||||
mobile_emulator, device_width, device_height, device_pixel_ratio):
|
||||
'''
|
||||
|
@ -587,8 +591,8 @@ def get_local_driver(
|
|||
# The new Microsoft Edge browser is based on Chromium
|
||||
chrome_options = _set_chrome_options(
|
||||
downloads_path, headless,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass,
|
||||
user_agent, disable_csp, enable_sync, user_data_dir,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
|
||||
disable_csp, enable_sync, incognito, user_data_dir,
|
||||
extension_zip, extension_dir, servername, mobile_emulator,
|
||||
device_width, device_height, device_pixel_ratio)
|
||||
return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
|
||||
|
@ -616,8 +620,8 @@ def get_local_driver(
|
|||
try:
|
||||
chrome_options = _set_chrome_options(
|
||||
downloads_path, headless,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass,
|
||||
user_agent, disable_csp, enable_sync, user_data_dir,
|
||||
proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
|
||||
disable_csp, enable_sync, incognito, user_data_dir,
|
||||
extension_zip, extension_dir, servername, mobile_emulator,
|
||||
device_width, device_height, device_pixel_ratio)
|
||||
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
|
||||
|
|
|
@ -1363,7 +1363,7 @@ class BaseCase(unittest.TestCase):
|
|||
def get_new_driver(self, browser=None, headless=None,
|
||||
servername=None, port=None, proxy=None, agent=None,
|
||||
switch_to=True, cap_file=None, disable_csp=None,
|
||||
enable_sync=None, user_data_dir=None,
|
||||
enable_sync=None, incognito=None, user_data_dir=None,
|
||||
extension_zip=None, extension_dir=None, is_mobile=False,
|
||||
d_width=None, d_height=None, d_p_r=None):
|
||||
""" This method spins up an extra browser for tests that require
|
||||
|
@ -1379,7 +1379,8 @@ class BaseCase(unittest.TestCase):
|
|||
switch_to - the option to switch to the new driver (default = True)
|
||||
cap_file - the file containing desired capabilities for the browser
|
||||
disable_csp - an option to disable Chrome's Content Security Policy
|
||||
enable_sync - the option to enable the "Chrome Sync" feature
|
||||
enable_sync - the option to enable the Chrome Sync feature (Chrome)
|
||||
incognito - the option to enable Chrome's Incognito mode (Chrome)
|
||||
user_data_dir - Chrome's User Data Directory to use (Chrome-only)
|
||||
extension_zip - A Chrome Extension ZIP file to use (Chrome-only)
|
||||
extension_dir - A Chrome Extension folder to use (Chrome-only)
|
||||
|
@ -1432,6 +1433,8 @@ class BaseCase(unittest.TestCase):
|
|||
disable_csp = self.disable_csp
|
||||
if enable_sync is None:
|
||||
enable_sync = self.enable_sync
|
||||
if incognito is None:
|
||||
incognito = self.incognito
|
||||
if user_data_dir is None:
|
||||
user_data_dir = self.user_data_dir
|
||||
if extension_zip is None:
|
||||
|
@ -1467,6 +1470,7 @@ class BaseCase(unittest.TestCase):
|
|||
cap_file=cap_file,
|
||||
disable_csp=disable_csp,
|
||||
enable_sync=enable_sync,
|
||||
incognito=incognito,
|
||||
user_data_dir=user_data_dir,
|
||||
extension_zip=extension_zip,
|
||||
extension_dir=extension_dir,
|
||||
|
@ -4166,6 +4170,7 @@ class BaseCase(unittest.TestCase):
|
|||
self.verify_delay = sb_config.verify_delay
|
||||
self.disable_csp = sb_config.disable_csp
|
||||
self.enable_sync = sb_config.enable_sync
|
||||
self.incognito = sb_config.incognito
|
||||
self.user_data_dir = sb_config.user_data_dir
|
||||
self.extension_zip = sb_config.extension_zip
|
||||
self.extension_dir = sb_config.extension_dir
|
||||
|
@ -4306,6 +4311,7 @@ class BaseCase(unittest.TestCase):
|
|||
cap_file=self.cap_file,
|
||||
disable_csp=self.disable_csp,
|
||||
enable_sync=self.enable_sync,
|
||||
incognito=self.incognito,
|
||||
user_data_dir=self.user_data_dir,
|
||||
extension_zip=self.extension_zip,
|
||||
extension_dir=self.extension_dir,
|
||||
|
|
|
@ -41,6 +41,7 @@ def pytest_addoption(parser):
|
|||
--verify-delay=SECONDS (The delay before MasterQA verification checks.)
|
||||
--disable-csp (This disables the Content Security Policy of websites.)
|
||||
--enable-sync (The option to enable "Chrome Sync".)
|
||||
--incognito (The option to enable Chrome's Incognito mode.)
|
||||
--reuse-session (The option to reuse the browser session between tests.)
|
||||
--maximize-window (The option to start with the web browser maximized.)
|
||||
--save-screenshot (The option to save a screenshot after each test.)
|
||||
|
@ -310,6 +311,11 @@ def pytest_addoption(parser):
|
|||
dest='enable_sync',
|
||||
default=False,
|
||||
help="""Using this enables the "Chrome Sync" feature.""")
|
||||
parser.addoption('--incognito',
|
||||
action="store_true",
|
||||
dest='incognito',
|
||||
default=False,
|
||||
help="""Using this enables Chrome's Incognito mode.""")
|
||||
parser.addoption('--reuse_session', '--reuse-session',
|
||||
action="store_true",
|
||||
dest='reuse_session',
|
||||
|
@ -386,6 +392,7 @@ def pytest_configure(config):
|
|||
sb_config.verify_delay = config.getoption('verify_delay')
|
||||
sb_config.disable_csp = config.getoption('disable_csp')
|
||||
sb_config.enable_sync = config.getoption('enable_sync')
|
||||
sb_config.incognito = config.getoption('incognito')
|
||||
sb_config.reuse_session = config.getoption('reuse_session')
|
||||
sb_config.shared_driver = None # The default driver for session reuse
|
||||
sb_config.maximize_option = config.getoption('maximize_option')
|
||||
|
|
|
@ -34,6 +34,7 @@ class SeleniumBrowser(Plugin):
|
|||
--verify-delay=SECONDS (The delay before MasterQA verification checks.)
|
||||
--disable-csp (This disables the Content Security Policy of websites.)
|
||||
--enable-sync (The option to enable "Chrome Sync".)
|
||||
--incognito (The option to enable Chrome's Incognito mode.)
|
||||
--maximize-window (The option to start with the web browser maximized.)
|
||||
--save-screenshot (The option to save a screenshot after each test.)
|
||||
--visual-baseline (Set the visual baseline for Visual/Layout tests.)
|
||||
|
@ -239,6 +240,12 @@ class SeleniumBrowser(Plugin):
|
|||
dest='enable_sync',
|
||||
default=False,
|
||||
help="""Using this enables the "Chrome Sync" feature.""")
|
||||
parser.add_option(
|
||||
'--incognito',
|
||||
action="store_true",
|
||||
dest='incognito',
|
||||
default=False,
|
||||
help="""Using this enables Chrome's Incognito mode.""")
|
||||
parser.add_option(
|
||||
'--maximize_window', '--maximize-window', '--maximize',
|
||||
'--fullscreen',
|
||||
|
@ -303,6 +310,7 @@ class SeleniumBrowser(Plugin):
|
|||
test.test.verify_delay = self.options.verify_delay # MasterQA
|
||||
test.test.disable_csp = self.options.disable_csp
|
||||
test.test.enable_sync = self.options.enable_sync
|
||||
test.test.incognito = self.options.incognito
|
||||
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