Skip to content

Add ability to set initial URL with "--start_page" cmd option #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 26, 2019
7 changes: 6 additions & 1 deletion seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def _create_firefox_profile(
profile.set_preference("app.update.auto", False)
profile.set_preference("app.update.enabled", False)
profile.set_preference("extensions.update.enabled", False)
profile.set_preference("browser.privatebrowsing.autostart", True)
profile.set_preference("extensions.allowPrivateBrowsingByDefault", True)
profile.set_preference("extensions.PrivateBrowsing.notification", False)
profile.set_preference("extensions.systemAddon.update.enabled", False)
profile.set_preference("extensions.update.autoUpdateDefault", False)
profile.set_preference("extensions.update.enabled", False)
profile.set_preference("devtools.errorconsole.enabled", True)
profile.set_preference(
"datareporting.healthreport.logging.consoleEnabled", False)
Expand Down Expand Up @@ -201,7 +207,6 @@ def _create_firefox_profile(
"browser.download.manager.showAlertOnComplete", False)
profile.set_preference("browser.shell.checkDefaultBrowser", False)
profile.set_preference("browser.startup.page", 0)
profile.set_preference("browser.privatebrowsing.autostart", True)
profile.set_preference("browser.download.panel.shown", False)
profile.set_preference(
"browser.download.animateNotifications", False)
Expand Down
16 changes: 12 additions & 4 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,7 @@ def get_new_driver(self, browser=None, headless=None,
if self.headless:
# Make sure the invisible browser window is big enough
try:
self.set_window_size(1440, 1080)
self.set_window_size(1440, 1880)
self.wait_for_ready_state_complete()
except Exception:
# This shouldn't fail, but in case it does,
Expand All @@ -2787,6 +2787,13 @@ def get_new_driver(self, browser=None, headless=None,
self.wait_for_ready_state_complete()
except Exception:
pass # Keep existing browser resolution
if self.start_page and len(self.start_page) >= 4:
if page_utils.is_valid_url(self.start_page):
self.open(self.start_page)
else:
new_start_page = "http://" + self.start_page
if page_utils.is_valid_url(new_start_page):
self.open(new_start_page)
return new_driver

def switch_to_driver(self, driver):
Expand Down Expand Up @@ -3175,6 +3182,7 @@ def setUp(self, masterqa_mode=False):
self.headless = sb_config.headless
self.headless_active = False
self.headed = sb_config.headed
self.start_page = sb_config.start_page
self.log_path = sb_config.log_path
self.with_testing_base = sb_config.with_testing_base
self.with_basic_test_info = sb_config.with_basic_test_info
Expand Down Expand Up @@ -3249,7 +3257,7 @@ def setUp(self, masterqa_mode=False):
if self.headless:
try:
from pyvirtualdisplay import Display
self.display = Display(visible=0, size=(1440, 1080))
self.display = Display(visible=0, size=(1440, 1880))
self.display.start()
self.headless_active = True
except Exception:
Expand Down Expand Up @@ -3524,7 +3532,7 @@ def tearDown(self):
test_id = "%s.%s.%s" % (self.__class__.__module__,
self.__class__.__name__,
self._testMethodName)
test_logpath = "latest_logs/" + test_id
test_logpath = self.log_path + "/" + test_id
if not os.path.exists(test_logpath):
try:
os.makedirs(test_logpath)
Expand All @@ -3544,7 +3552,7 @@ def tearDown(self):
test_id = "%s.%s.%s" % (self.__class__.__module__,
self.__class__.__name__,
self._testMethodName)
test_logpath = "latest_logs/" + test_id
test_logpath = self.log_path + "/" + test_id
if not os.path.exists(test_logpath):
try:
os.makedirs(test_logpath)
Expand Down
12 changes: 6 additions & 6 deletions seleniumbase/masterqa/master_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ def manual_page_check(self, *args):
elif instructions and "?" in instructions:
question = instructions

wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
if self.verify_delay:
wait_time_before_verify = float(self.verify_delay)
# Allow a moment to see the full page before the dialog box pops up
time.sleep(wait_time_before_verify)

use_jqc = False
self.wait_for_ready_state_complete()
if js_utils.is_jquery_confirm_activated(self.driver):
Expand All @@ -126,12 +132,6 @@ def manual_page_check(self, *args):
use_jqc = False

if use_jqc:
wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
if self.verify_delay:
wait_time_before_verify = float(self.verify_delay)
# Allow a moment to see the full page before the dialog box pops up
time.sleep(wait_time_before_verify)

# Use the jquery_confirm library for manual page checks
self.jq_confirm_dialog(question)
time.sleep(0.02)
Expand Down
13 changes: 5 additions & 8 deletions seleniumbase/plugins/base_plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""
This is the Nose plugin for saving logs and setting a test environment.
Vars include "env" and "log_path".
You can have tests behave differently based on the environment.
You can access the values of these variables from the tests.
"""
# -*- coding: utf-8 -*-
""" This is the Nose plugin for saving logs and setting a test environment. """

import os
import sys
Expand All @@ -17,8 +13,8 @@

class Base(Plugin):
"""
The base_plugin includes the following command-line options for nosetests:
--env=ENV (Set a test environment. Use "self.env" to access env in tests.)
This parser plugin includes the following command-line options for Nose:
--env=ENV (Set a test environment. Use "self.env" to use this in tests.)
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
--log_path=LOG_PATH (The directory where log files get saved to.)
--archive_logs (Archive old log files instead of deleting them.)
Expand Down Expand Up @@ -104,6 +100,7 @@ def beforeTest(self, test):
test.test.environment = self.options.environment
test.test.env = self.options.environment # Add a shortened version
test.test.data = self.options.data
test.test.log_path = self.options.log_path
test.test.args = self.options
test.test.report_on = self.report_on
self.test_count += 1
Expand Down
39 changes: 39 additions & 0 deletions seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@


def pytest_addoption(parser):
"""
This parser plugin includes the following command-line options for pytest:
--browser=BROWSER (The web browser to use.)
--cap_file=FILE (The web browser's desired capabilities to use.)
--env=ENV (Set a test environment. Use "self.env" to use this in tests.)
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
--user_data_dir=DIR (Set the Chrome user data directory to use.)
--server=SERVER (The server / IP address used by the tests.)
--port=PORT (The port that's used by the test server.)
--proxy=SERVER:PORT (This is the proxy server:port combo used by tests.)
--agent=STRING (This designates the web browser's User Agent to use.)
--extension_zip=ZIP (Load a Chrome Extension .zip file, comma-separated.)
--extension_dir=DIR (Load a Chrome Extension directory, comma-separated.)
--headless (The option to run tests headlessly. The default on Linux OS.)
--headed (The option to run tests with a GUI on Linux OS.)
--start_page=URL (The starting URL for the web browser when tests begin.)
--log_path=LOG_PATH (The directory where log files get saved to.)
--archive_logs (Archive old log files instead of deleting them.)
--demo_mode (The option to visually see test actions as they occur.)
--demo_sleep=SECONDS (The option to wait longer after Demo Mode actions.)
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
--message_duration=SECONDS (The time length for Messenger alerts.)
--check_js (The option to check for JavaScript errors after page loads.)
--ad_block (The option to block some display ads after page loads.)
--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".)
--save_screenshot (The option to save a screenshot after each test.)
--visual_baseline (Set the visual baseline for Visual/Layout tests.)
--timeout_multiplier=MULTIPLIER (Multiplies the default timeout values.)
"""
parser = parser.getgroup('SeleniumBase',
'SeleniumBase specific configuration options')
parser.addoption('--browser',
Expand Down Expand Up @@ -172,6 +203,13 @@ def pytest_addoption(parser):
(The default setting on Linux is headless.)
(The default setting on Mac or Windows is headed.)
""")
parser.addoption('--start_page', '--start-page', '--url',
action='store',
dest='start_page',
default=None,
help="""Designates the starting URL for the web browser
when each test begins.
Default: None.""")
parser.addoption('--is_pytest', '--is-pytest',
action="store_true",
dest='is_pytest',
Expand Down Expand Up @@ -269,6 +307,7 @@ def pytest_configure(config):
sb_config.user_agent = config.getoption('user_agent')
sb_config.headless = config.getoption('headless')
sb_config.headed = config.getoption('headed')
sb_config.start_page = config.getoption('start_page')
sb_config.extension_zip = config.getoption('extension_zip')
sb_config.extension_dir = config.getoption('extension_dir')
sb_config.with_testing_base = config.getoption('with_testing_base')
Expand Down
69 changes: 37 additions & 32 deletions seleniumbase/plugins/selenium_plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
This plugin gives the power of Selenium to nosetests
by providing a WebDriver object for the tests to use.
"""
# -*- coding: utf-8 -*-
""" This is the nosetests Selenium plugin for test configuration. """

import sys
from nose.plugins import Plugin
Expand All @@ -11,33 +9,31 @@

class SeleniumBrowser(Plugin):
"""
The plugin for Selenium tests. Takes in key arguments and then
creates a WebDriver object. All arguments are passed to the tests.

The following command line options are available to the tests:
self.options.browser -- the browser to use (--browser)
self.options.cap_file -- browser's desired capabilities file (--cap_file)
self.options.user_data_dir -- set Chrome's user data dir (--user_data_dir)
self.options.server -- the server used by the test (--server)
self.options.port -- the port used by the test (--port)
self.options.proxy -- designates the proxy server:port to use. (--proxy)
self.options.agent -- designates the User Agent for the browser. (--agent)
self.options.extension_zip -- load a Chrome Extension ZIP (--extension_zip)
self.options.extension_dir -- load a Chrome Extension DIR (--extension_dir)
self.options.headless -- the option to run headlessly (--headless)
self.options.headed -- the option to run with a GUI on Linux (--headed)
self.options.demo_mode -- the option to slow down Selenium (--demo_mode)
self.options.demo_sleep -- Selenium action delay in DemoMode (--demo_sleep)
self.options.highlights -- # of highlight animations shown (--highlights)
self.options.message_duration -- Messenger alert time (--message_duration)
self.options.js_checking_on -- option to check for js errors (--check_js)
self.options.ad_block -- the option to block some display ads (--ad_block)
self.options.verify_delay -- delay before MasterQA checks (--verify_delay)
self.options.disable_csp -- disable Content Security Policy (--disable_csp)
self.options.enable_sync -- option to enable "Chrome Sync" (--enable_sync)
self.options.save_screenshot -- save screen after test (--save_screenshot)
self.options.visual_baseline -- set the visual baseline (--visual_baseline)
self.options.timeout_multiplier -- increase defaults (--timeout_multiplier)
This parser plugin includes the following command-line options for Nose:
--browser=BROWSER (The web browser to use.)
--cap_file=FILE (The web browser's desired capabilities to use.)
--user_data_dir=DIR (Set the Chrome user data directory to use.)
--server=SERVER (The server / IP address used by the tests.)
--port=PORT (The port that's used by the test server.)
--proxy=SERVER:PORT (This is the proxy server:port combo used by tests.)
--agent=STRING (This designates the web browser's User Agent to use.)
--extension_zip=ZIP (Load a Chrome Extension .zip file, comma-separated.)
--extension_dir=DIR (Load a Chrome Extension directory, comma-separated.)
--headless (The option to run tests headlessly. The default on Linux OS.)
--headed (The option to run tests with a GUI on Linux OS.)
--start_page=URL (The starting URL for the web browser when tests begin.)
--demo_mode (The option to visually see test actions as they occur.)
--demo_sleep=SECONDS (The option to wait longer after Demo Mode actions.)
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
--message_duration=SECONDS (The time length for Messenger alerts.)
--check_js (The option to check for JavaScript errors after page loads.)
--ad_block (The option to block some display ads after page loads.)
--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".)
--save_screenshot (The option to save a screenshot after each test.)
--visual_baseline (Set the visual baseline for Visual/Layout tests.)
--timeout_multiplier=MULTIPLIER (Multiplies the default timeout values.)
"""
name = 'selenium' # Usage: --with-selenium

Expand Down Expand Up @@ -141,6 +137,14 @@ def options(self, parser, env):
a GUI when running tests on Linux machines.
(The default setting on Linux is headless.)
(The default setting on Mac or Windows is headed.)""")
parser.add_option(
'--start_page', '--start-page', '--url',
action='store',
dest='start_page',
default=None,
help="""Designates the starting URL for the web browser
when each test begins.
Default: None.""")
parser.add_option(
'--demo_mode', '--demo-mode', '--demo',
action="store_true",
Expand Down Expand Up @@ -245,6 +249,7 @@ def beforeTest(self, test):
test.test.cap_file = self.options.cap_file
test.test.headless = self.options.headless
test.test.headed = self.options.headed
test.test.start_page = self.options.start_page
test.test.servername = self.options.servername
test.test.port = self.options.port
test.test.user_data_dir = self.options.user_data_dir
Expand Down Expand Up @@ -281,7 +286,7 @@ def beforeTest(self, test):
if self.options.headless:
try:
from pyvirtualdisplay import Display
self.display = Display(visible=0, size=(1440, 1080))
self.display = Display(visible=0, size=(1440, 1880))
self.display.start()
self.headless_active = True
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='seleniumbase',
version='1.26.0',
version='1.26.1',
description='Reliable Browser Automation & Testing Framework',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down