Skip to content

Commit ce16150

Browse files
authored
Merge pull request #349 from seleniumbase/command-line-improvements
Add ability to set initial URL with ``--start_page=URL`` or ``--url=URL`` cmd option
2 parents 734444e + b0ca4f5 commit ce16150

File tree

7 files changed

+106
-52
lines changed

7 files changed

+106
-52
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ def _create_firefox_profile(
173173
profile.set_preference("app.update.auto", False)
174174
profile.set_preference("app.update.enabled", False)
175175
profile.set_preference("extensions.update.enabled", False)
176+
profile.set_preference("browser.privatebrowsing.autostart", True)
177+
profile.set_preference("extensions.allowPrivateBrowsingByDefault", True)
178+
profile.set_preference("extensions.PrivateBrowsing.notification", False)
179+
profile.set_preference("extensions.systemAddon.update.enabled", False)
180+
profile.set_preference("extensions.update.autoUpdateDefault", False)
181+
profile.set_preference("extensions.update.enabled", False)
176182
profile.set_preference("devtools.errorconsole.enabled", True)
177183
profile.set_preference(
178184
"datareporting.healthreport.logging.consoleEnabled", False)
@@ -201,7 +207,6 @@ def _create_firefox_profile(
201207
"browser.download.manager.showAlertOnComplete", False)
202208
profile.set_preference("browser.shell.checkDefaultBrowser", False)
203209
profile.set_preference("browser.startup.page", 0)
204-
profile.set_preference("browser.privatebrowsing.autostart", True)
205210
profile.set_preference("browser.download.panel.shown", False)
206211
profile.set_preference(
207212
"browser.download.animateNotifications", False)

seleniumbase/fixtures/base_case.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ def get_new_driver(self, browser=None, headless=None,
27672767
if self.headless:
27682768
# Make sure the invisible browser window is big enough
27692769
try:
2770-
self.set_window_size(1440, 1080)
2770+
self.set_window_size(1440, 1880)
27712771
self.wait_for_ready_state_complete()
27722772
except Exception:
27732773
# This shouldn't fail, but in case it does,
@@ -2787,6 +2787,13 @@ def get_new_driver(self, browser=None, headless=None,
27872787
self.wait_for_ready_state_complete()
27882788
except Exception:
27892789
pass # Keep existing browser resolution
2790+
if self.start_page and len(self.start_page) >= 4:
2791+
if page_utils.is_valid_url(self.start_page):
2792+
self.open(self.start_page)
2793+
else:
2794+
new_start_page = "http://" + self.start_page
2795+
if page_utils.is_valid_url(new_start_page):
2796+
self.open(new_start_page)
27902797
return new_driver
27912798

27922799
def switch_to_driver(self, driver):
@@ -3175,6 +3182,7 @@ def setUp(self, masterqa_mode=False):
31753182
self.headless = sb_config.headless
31763183
self.headless_active = False
31773184
self.headed = sb_config.headed
3185+
self.start_page = sb_config.start_page
31783186
self.log_path = sb_config.log_path
31793187
self.with_testing_base = sb_config.with_testing_base
31803188
self.with_basic_test_info = sb_config.with_basic_test_info
@@ -3249,7 +3257,7 @@ def setUp(self, masterqa_mode=False):
32493257
if self.headless:
32503258
try:
32513259
from pyvirtualdisplay import Display
3252-
self.display = Display(visible=0, size=(1440, 1080))
3260+
self.display = Display(visible=0, size=(1440, 1880))
32533261
self.display.start()
32543262
self.headless_active = True
32553263
except Exception:
@@ -3524,7 +3532,7 @@ def tearDown(self):
35243532
test_id = "%s.%s.%s" % (self.__class__.__module__,
35253533
self.__class__.__name__,
35263534
self._testMethodName)
3527-
test_logpath = "latest_logs/" + test_id
3535+
test_logpath = self.log_path + "/" + test_id
35283536
if not os.path.exists(test_logpath):
35293537
try:
35303538
os.makedirs(test_logpath)
@@ -3544,7 +3552,7 @@ def tearDown(self):
35443552
test_id = "%s.%s.%s" % (self.__class__.__module__,
35453553
self.__class__.__name__,
35463554
self._testMethodName)
3547-
test_logpath = "latest_logs/" + test_id
3555+
test_logpath = self.log_path + "/" + test_id
35483556
if not os.path.exists(test_logpath):
35493557
try:
35503558
os.makedirs(test_logpath)

seleniumbase/masterqa/master_qa.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def manual_page_check(self, *args):
111111
elif instructions and "?" in instructions:
112112
question = instructions
113113

114+
wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
115+
if self.verify_delay:
116+
wait_time_before_verify = float(self.verify_delay)
117+
# Allow a moment to see the full page before the dialog box pops up
118+
time.sleep(wait_time_before_verify)
119+
114120
use_jqc = False
115121
self.wait_for_ready_state_complete()
116122
if js_utils.is_jquery_confirm_activated(self.driver):
@@ -126,12 +132,6 @@ def manual_page_check(self, *args):
126132
use_jqc = False
127133

128134
if use_jqc:
129-
wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
130-
if self.verify_delay:
131-
wait_time_before_verify = float(self.verify_delay)
132-
# Allow a moment to see the full page before the dialog box pops up
133-
time.sleep(wait_time_before_verify)
134-
135135
# Use the jquery_confirm library for manual page checks
136136
self.jq_confirm_dialog(question)
137137
time.sleep(0.02)

seleniumbase/plugins/base_plugin.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
"""
2-
This is the Nose plugin for saving logs and setting a test environment.
3-
Vars include "env" and "log_path".
4-
You can have tests behave differently based on the environment.
5-
You can access the values of these variables from the tests.
6-
"""
1+
# -*- coding: utf-8 -*-
2+
""" This is the Nose plugin for saving logs and setting a test environment. """
73

84
import os
95
import sys
@@ -17,8 +13,8 @@
1713

1814
class Base(Plugin):
1915
"""
20-
The base_plugin includes the following command-line options for nosetests:
21-
--env=ENV (Set a test environment. Use "self.env" to access env in tests.)
16+
This parser plugin includes the following command-line options for Nose:
17+
--env=ENV (Set a test environment. Use "self.env" to use this in tests.)
2218
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
2319
--log_path=LOG_PATH (The directory where log files get saved to.)
2420
--archive_logs (Archive old log files instead of deleting them.)
@@ -104,6 +100,7 @@ def beforeTest(self, test):
104100
test.test.environment = self.options.environment
105101
test.test.env = self.options.environment # Add a shortened version
106102
test.test.data = self.options.data
103+
test.test.log_path = self.options.log_path
107104
test.test.args = self.options
108105
test.test.report_on = self.report_on
109106
self.test_count += 1

seleniumbase/plugins/pytest_plugin.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@
1111

1212

1313
def pytest_addoption(parser):
14+
"""
15+
This parser plugin includes the following command-line options for pytest:
16+
--browser=BROWSER (The web browser to use.)
17+
--cap_file=FILE (The web browser's desired capabilities to use.)
18+
--env=ENV (Set a test environment. Use "self.env" to use this in tests.)
19+
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
20+
--user_data_dir=DIR (Set the Chrome user data directory to use.)
21+
--server=SERVER (The server / IP address used by the tests.)
22+
--port=PORT (The port that's used by the test server.)
23+
--proxy=SERVER:PORT (This is the proxy server:port combo used by tests.)
24+
--agent=STRING (This designates the web browser's User Agent to use.)
25+
--extension_zip=ZIP (Load a Chrome Extension .zip file, comma-separated.)
26+
--extension_dir=DIR (Load a Chrome Extension directory, comma-separated.)
27+
--headless (The option to run tests headlessly. The default on Linux OS.)
28+
--headed (The option to run tests with a GUI on Linux OS.)
29+
--start_page=URL (The starting URL for the web browser when tests begin.)
30+
--log_path=LOG_PATH (The directory where log files get saved to.)
31+
--archive_logs (Archive old log files instead of deleting them.)
32+
--demo_mode (The option to visually see test actions as they occur.)
33+
--demo_sleep=SECONDS (The option to wait longer after Demo Mode actions.)
34+
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
35+
--message_duration=SECONDS (The time length for Messenger alerts.)
36+
--check_js (The option to check for JavaScript errors after page loads.)
37+
--ad_block (The option to block some display ads after page loads.)
38+
--verify_delay=SECONDS (The delay before MasterQA verification checks.)
39+
--disable_csp (This disables the Content Security Policy of websites.)
40+
--enable_sync (The option to enable "Chrome Sync".)
41+
--save_screenshot (The option to save a screenshot after each test.)
42+
--visual_baseline (Set the visual baseline for Visual/Layout tests.)
43+
--timeout_multiplier=MULTIPLIER (Multiplies the default timeout values.)
44+
"""
1445
parser = parser.getgroup('SeleniumBase',
1546
'SeleniumBase specific configuration options')
1647
parser.addoption('--browser',
@@ -172,6 +203,13 @@ def pytest_addoption(parser):
172203
(The default setting on Linux is headless.)
173204
(The default setting on Mac or Windows is headed.)
174205
""")
206+
parser.addoption('--start_page', '--start-page', '--url',
207+
action='store',
208+
dest='start_page',
209+
default=None,
210+
help="""Designates the starting URL for the web browser
211+
when each test begins.
212+
Default: None.""")
175213
parser.addoption('--is_pytest', '--is-pytest',
176214
action="store_true",
177215
dest='is_pytest',
@@ -269,6 +307,7 @@ def pytest_configure(config):
269307
sb_config.user_agent = config.getoption('user_agent')
270308
sb_config.headless = config.getoption('headless')
271309
sb_config.headed = config.getoption('headed')
310+
sb_config.start_page = config.getoption('start_page')
272311
sb_config.extension_zip = config.getoption('extension_zip')
273312
sb_config.extension_dir = config.getoption('extension_dir')
274313
sb_config.with_testing_base = config.getoption('with_testing_base')

seleniumbase/plugins/selenium_plugin.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"""
2-
This plugin gives the power of Selenium to nosetests
3-
by providing a WebDriver object for the tests to use.
4-
"""
1+
# -*- coding: utf-8 -*-
2+
""" This is the nosetests Selenium plugin for test configuration. """
53

64
import sys
75
from nose.plugins import Plugin
@@ -11,33 +9,31 @@
119

1210
class SeleniumBrowser(Plugin):
1311
"""
14-
The plugin for Selenium tests. Takes in key arguments and then
15-
creates a WebDriver object. All arguments are passed to the tests.
16-
17-
The following command line options are available to the tests:
18-
self.options.browser -- the browser to use (--browser)
19-
self.options.cap_file -- browser's desired capabilities file (--cap_file)
20-
self.options.user_data_dir -- set Chrome's user data dir (--user_data_dir)
21-
self.options.server -- the server used by the test (--server)
22-
self.options.port -- the port used by the test (--port)
23-
self.options.proxy -- designates the proxy server:port to use. (--proxy)
24-
self.options.agent -- designates the User Agent for the browser. (--agent)
25-
self.options.extension_zip -- load a Chrome Extension ZIP (--extension_zip)
26-
self.options.extension_dir -- load a Chrome Extension DIR (--extension_dir)
27-
self.options.headless -- the option to run headlessly (--headless)
28-
self.options.headed -- the option to run with a GUI on Linux (--headed)
29-
self.options.demo_mode -- the option to slow down Selenium (--demo_mode)
30-
self.options.demo_sleep -- Selenium action delay in DemoMode (--demo_sleep)
31-
self.options.highlights -- # of highlight animations shown (--highlights)
32-
self.options.message_duration -- Messenger alert time (--message_duration)
33-
self.options.js_checking_on -- option to check for js errors (--check_js)
34-
self.options.ad_block -- the option to block some display ads (--ad_block)
35-
self.options.verify_delay -- delay before MasterQA checks (--verify_delay)
36-
self.options.disable_csp -- disable Content Security Policy (--disable_csp)
37-
self.options.enable_sync -- option to enable "Chrome Sync" (--enable_sync)
38-
self.options.save_screenshot -- save screen after test (--save_screenshot)
39-
self.options.visual_baseline -- set the visual baseline (--visual_baseline)
40-
self.options.timeout_multiplier -- increase defaults (--timeout_multiplier)
12+
This parser plugin includes the following command-line options for Nose:
13+
--browser=BROWSER (The web browser to use.)
14+
--cap_file=FILE (The web browser's desired capabilities to use.)
15+
--user_data_dir=DIR (Set the Chrome user data directory to use.)
16+
--server=SERVER (The server / IP address used by the tests.)
17+
--port=PORT (The port that's used by the test server.)
18+
--proxy=SERVER:PORT (This is the proxy server:port combo used by tests.)
19+
--agent=STRING (This designates the web browser's User Agent to use.)
20+
--extension_zip=ZIP (Load a Chrome Extension .zip file, comma-separated.)
21+
--extension_dir=DIR (Load a Chrome Extension directory, comma-separated.)
22+
--headless (The option to run tests headlessly. The default on Linux OS.)
23+
--headed (The option to run tests with a GUI on Linux OS.)
24+
--start_page=URL (The starting URL for the web browser when tests begin.)
25+
--demo_mode (The option to visually see test actions as they occur.)
26+
--demo_sleep=SECONDS (The option to wait longer after Demo Mode actions.)
27+
--highlights=NUM (Number of highlight animations for Demo Mode actions.)
28+
--message_duration=SECONDS (The time length for Messenger alerts.)
29+
--check_js (The option to check for JavaScript errors after page loads.)
30+
--ad_block (The option to block some display ads after page loads.)
31+
--verify_delay=SECONDS (The delay before MasterQA verification checks.)
32+
--disable_csp (This disables the Content Security Policy of websites.)
33+
--enable_sync (The option to enable "Chrome Sync".)
34+
--save_screenshot (The option to save a screenshot after each test.)
35+
--visual_baseline (Set the visual baseline for Visual/Layout tests.)
36+
--timeout_multiplier=MULTIPLIER (Multiplies the default timeout values.)
4137
"""
4238
name = 'selenium' # Usage: --with-selenium
4339

@@ -141,6 +137,14 @@ def options(self, parser, env):
141137
a GUI when running tests on Linux machines.
142138
(The default setting on Linux is headless.)
143139
(The default setting on Mac or Windows is headed.)""")
140+
parser.add_option(
141+
'--start_page', '--start-page', '--url',
142+
action='store',
143+
dest='start_page',
144+
default=None,
145+
help="""Designates the starting URL for the web browser
146+
when each test begins.
147+
Default: None.""")
144148
parser.add_option(
145149
'--demo_mode', '--demo-mode', '--demo',
146150
action="store_true",
@@ -245,6 +249,7 @@ def beforeTest(self, test):
245249
test.test.cap_file = self.options.cap_file
246250
test.test.headless = self.options.headless
247251
test.test.headed = self.options.headed
252+
test.test.start_page = self.options.start_page
248253
test.test.servername = self.options.servername
249254
test.test.port = self.options.port
250255
test.test.user_data_dir = self.options.user_data_dir
@@ -281,7 +286,7 @@ def beforeTest(self, test):
281286
if self.options.headless:
282287
try:
283288
from pyvirtualdisplay import Display
284-
self.display = Display(visible=0, size=(1440, 1080))
289+
self.display = Display(visible=0, size=(1440, 1880))
285290
self.display.start()
286291
self.headless_active = True
287292
except Exception:

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.26.0',
20+
version='1.26.1',
2121
description='Reliable Browser Automation & Testing Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)