Skip to content

Commit 546e9bc

Browse files
committed
Add protocol option for selecting a Selenium Grid server
1 parent 966f169 commit 546e9bc

File tree

8 files changed

+47
-1
lines changed

8 files changed

+47
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ The code above will leave your browser window open in case there's a failure. (i
350350
--var2=DATA # (Extra test data. Access with "self.var2" in tests.)
351351
--var3=DATA # (Extra test data. Access with "self.var3" in tests.)
352352
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
353+
--protocol=PROTOCOL # (The Selenium Grid protocol: http|https.)
353354
--server=SERVER # (The Selenium Grid server/IP used for tests.)
354355
--port=PORT # (The Selenium Grid port used by the test server.)
355356
--proxy=SERVER:PORT # (Connect to a proxy server:port for tests.)

examples/raw_parameter_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
sb.headed = False
3636
sb.start_page = None
3737
sb.locale_code = None
38+
sb.protocol = "http"
3839
sb.servername = "localhost"
3940
sb.port = 4444
4041
sb.data = None

help_docs/customizing_test_runs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
105105
--var2=DATA # (Extra test data. Access with "self.var2" in tests.)
106106
--var3=DATA # (Extra test data. Access with "self.var3" in tests.)
107107
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
108+
--protocol=PROTOCOL # (The Selenium Grid protocol: http|https.)
108109
--server=SERVER # (The Selenium Grid server/IP used for tests.)
109110
--port=PORT # (The Selenium Grid port used by the test server.)
110111
--proxy=SERVER:PORT # (Connect to a proxy server:port for tests.)

seleniumbase/core/browser_launcher.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ def get_driver(
536536
headless=False,
537537
locale_code=None,
538538
use_grid=False,
539+
protocol="http",
539540
servername="localhost",
540541
port=4444,
541542
proxy_string=None,
@@ -602,6 +603,7 @@ def get_driver(
602603
browser_name,
603604
headless,
604605
locale_code,
606+
protocol,
605607
servername,
606608
port,
607609
proxy_string,
@@ -671,6 +673,7 @@ def get_remote_driver(
671673
browser_name,
672674
headless,
673675
locale_code,
676+
protocol,
674677
servername,
675678
port,
676679
proxy_string,
@@ -703,7 +706,7 @@ def get_remote_driver(
703706
device_pixel_ratio,
704707
):
705708
downloads_path = download_helper.get_downloads_folder()
706-
address = "http://%s:%s/wd/hub" % (servername, port)
709+
address = "%s://%s:%s/wd/hub" % (protocol, servername, port)
707710
desired_caps = {}
708711
extra_caps = {}
709712
if cap_file:

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,7 @@ def get_new_driver(
22062206
browser=None,
22072207
headless=None,
22082208
locale_code=None,
2209+
protocol=None,
22092210
servername=None,
22102211
port=None,
22112212
proxy=None,
@@ -2242,6 +2243,7 @@ def get_new_driver(
22422243
browser - the browser to use. (Ex: "chrome", "firefox")
22432244
headless - the option to run webdriver in headless mode
22442245
locale_code - the Language Locale Code for the web browser
2246+
protocol - if using a Selenium Grid, set the host protocol here
22452247
servername - if using a Selenium Grid, set the host address here
22462248
port - if using a Selenium Grid, set the host port here
22472249
proxy - if using a proxy server, specify the "host:port" combo here
@@ -2302,6 +2304,8 @@ def get_new_driver(
23022304
headless = self.headless
23032305
if locale_code is None:
23042306
locale_code = self.locale_code
2307+
if protocol is None:
2308+
protocol = self.protocol
23052309
if servername is None:
23062310
servername = self.servername
23072311
if port is None:
@@ -2375,6 +2379,7 @@ def get_new_driver(
23752379
headless=headless,
23762380
locale_code=locale_code,
23772381
use_grid=use_grid,
2382+
protocol=protocol,
23782383
servername=servername,
23792384
port=port,
23802385
proxy_string=proxy_string,
@@ -8367,6 +8372,7 @@ def setUp(self, masterqa_mode=False):
83678372
self.with_page_source = sb_config.with_page_source
83688373
self.with_db_reporting = sb_config.with_db_reporting
83698374
self.with_s3_logging = sb_config.with_s3_logging
8375+
self.protocol = sb_config.protocol
83708376
self.servername = sb_config.servername
83718377
self.port = sb_config.port
83728378
self.proxy_string = sb_config.proxy_string
@@ -8604,6 +8610,7 @@ def setUp(self, masterqa_mode=False):
86048610
browser=self.browser,
86058611
headless=self.headless,
86068612
locale_code=self.locale_code,
8613+
protocol=self.protocol,
86078614
servername=self.servername,
86088615
port=self.port,
86098616
proxy=self.proxy_string,

seleniumbase/fixtures/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ class Browser:
385385
}
386386

387387

388+
class Protocol:
389+
HTTP = "http"
390+
HTTPS = "https"
391+
392+
388393
class State:
389394
PASSED = "Passed"
390395
FAILED = "Failed"

seleniumbase/plugins/pytest_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def pytest_addoption(parser):
3333
--var2=DATA (Extra test data. Access with "self.var2" in tests.)
3434
--var3=DATA (Extra test data. Access with "self.var3" in tests.)
3535
--user-data-dir=DIR (Set the Chrome user data directory to use.)
36+
--protocol=PROTOCOL (The Selenium Grid protocol: http|https.)
3637
--server=SERVER (The Selenium Grid server/IP used for tests.)
3738
--port=PORT (The Selenium Grid port used by the test server.)
3839
--cap-file=FILE (The web browser's desired capabilities to use.)
@@ -334,6 +335,18 @@ def pytest_addoption(parser):
334335
This option saves page source files on test failures.
335336
(Automatically on when using --with-testing_base)""",
336337
)
338+
parser.addoption(
339+
"--protocol",
340+
action="store",
341+
dest="protocol",
342+
choices=(
343+
constants.Protocol.HTTP,
344+
constants.Protocol.HTTPS,
345+
),
346+
default=constants.Protocol.HTTP,
347+
help="""Designates the Selenium Grid protocol to use.
348+
Default: http.""",
349+
)
337350
parser.addoption(
338351
"--server",
339352
action="store",
@@ -911,6 +924,7 @@ def pytest_configure(config):
911924
sb_config.with_screen_shots = config.getoption("with_screen_shots")
912925
sb_config.with_basic_test_info = config.getoption("with_basic_test_info")
913926
sb_config.with_page_source = config.getoption("with_page_source")
927+
sb_config.protocol = config.getoption("protocol")
914928
sb_config.servername = config.getoption("servername")
915929
sb_config.port = config.getoption("port")
916930
sb_config.proxy_string = config.getoption("proxy_string")

seleniumbase/plugins/selenium_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class SeleniumBrowser(Plugin):
1414
This plugin adds the following command-line options to nosetests:
1515
--browser=BROWSER (The web browser to use. Default: "chrome".)
1616
--user-data-dir=DIR (Set the Chrome user data directory to use.)
17+
--protocol=PROTOCOL (The Selenium Grid protocol: http|https.)
1718
--server=SERVER (The Selenium Grid server/IP used for tests.)
1819
--port=PORT (The Selenium Grid port used by the test server.)
1920
--cap-file=FILE (The web browser's desired capabilities to use.)
@@ -111,6 +112,18 @@ def options(self, parser, env):
111112
help="""The Chrome User Data Directory to use. (Chrome Profile)
112113
If the directory doesn't exist, it'll be created.""",
113114
)
115+
parser.add_option(
116+
"--protocol",
117+
action="store",
118+
dest="protocol",
119+
choices=(
120+
constants.Protocol.HTTP,
121+
constants.Protocol.HTTPS,
122+
),
123+
default=constants.Protocol.HTTP,
124+
help="""Designates the Selenium Grid protocol to use.
125+
Default: http.""",
126+
)
114127
parser.add_option(
115128
"--server",
116129
action="store",
@@ -532,6 +545,7 @@ def beforeTest(self, test):
532545
test.test.locale_code = self.options.locale_code
533546
test.test.interval = self.options.interval
534547
test.test.start_page = self.options.start_page
548+
test.test.protocol = self.options.protocol
535549
test.test.servername = self.options.servername
536550
test.test.port = self.options.port
537551
test.test.user_data_dir = self.options.user_data_dir

0 commit comments

Comments
 (0)