Skip to content

Commit

Permalink
Rename host and port arguments for GRID (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil committed Aug 25, 2020
1 parent 2a7942d commit c36dc97
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
10 changes: 5 additions & 5 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ driver, as the accepted capabilities may differ::
pytest --driver Remote --capability browserName firefox

Note that if your server is not running locally or is running on an alternate
port you will need to specify the ``--host`` and ``--port`` command line
port you will need to specify the ``--selenium-host`` and ``--selenium-port`` command line
options, or by setting the ``SELENIUM_HOST`` and ``SELENIUM_PORT`` environment
variables::

pytest --driver Remote --host selenium.hostname --port 5555 --capability browserName firefox
pytest --driver Remote --selenium-host selenium.hostname --selenium-port 5555 --capability browserName firefox

Sauce Labs
----------
Expand Down Expand Up @@ -428,7 +428,7 @@ Local tunnel
~~~~~~~~~~~~

To run the tests using `TestingBot's local tunnel <https://testingbot.com/support/other/tunnel>`_
you'll also need to set the ``--host`` and ``--port`` command line arguments.
you'll also need to set the ``--selenium-host`` and ``--selenium-port`` command line arguments.

CrossBrowserTesting
-------------------
Expand Down Expand Up @@ -493,11 +493,11 @@ selection is determined using capabilities. Check the
for details of accepted values.

Note that if your Appium server is not running locally or is running on an
alternate port you will need to specify the ``--host`` and ``--port``
alternate port you will need to specify the ``--selenium-host`` and ``--selenium-port``
command line options, or by setting the ``APPIUM_HOST`` and ``APPIUM_PORT``
environment variables::

pytest --driver Appium --host appium.hostname --port 5555
pytest --driver Appium --selenium-host appium.hostname --selenium-port 5555

Specifying Capabilities
***********************
Expand Down
51 changes: 44 additions & 7 deletions pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from .utils import CaseInsensitiveDict
from . import drivers

import warnings

LOGGER = logging.getLogger(__name__)

SUPPORTED_DRIVERS = CaseInsensitiveDict(
Expand Down Expand Up @@ -162,8 +164,8 @@ def driver_kwargs(
firefox_options=firefox_options,
firefox_profile=firefox_profile,
edge_options=edge_options,
host=pytestconfig.getoption("host"),
port=pytestconfig.getoption("port"),
host=pytestconfig.getoption("selenium_host"),
port=pytestconfig.getoption("selenium_port"),
service_log_path=None,
request=request,
test=".".join(split_class_and_test_names(request.node.nodeid)),
Expand Down Expand Up @@ -228,6 +230,22 @@ def selenium(driver):

@pytest.hookimpl(trylast=True)
def pytest_configure(config):
if config.getoption("host"):
warnings.warn(
"--host has been deprecated and will be removed in a "
"future release. Please use --selenium-host instead.",
DeprecationWarning,
)
config.option.selenium_host = config.getoption("host")

if config.getoption("port"):
warnings.warn(
"--port has been deprecated and will be removed in a "
"future release. Please use --selenium-port instead.",
DeprecationWarning,
)
config.option.selenium_port = config.getoption("port")

capabilities = config._variables.get("capabilities", {})
capabilities.update({k: v for k, v in config.getoption("capabilities")})
config.addinivalue_line(
Expand All @@ -241,9 +259,9 @@ def pytest_configure(config):
if hasattr(config, "_metadata"):
config._metadata["Driver"] = config.getoption("driver")
config._metadata["Capabilities"] = capabilities
if all((config.getoption("host"), config.getoption("port"))):
if all((config.option.selenium_host, config.option.selenium_port)):
config._metadata["Server"] = "{0}:{1}".format(
config.getoption("host"), config.getoption("port")
config.option.selenium_host, config.option.selenium_port
)
config._capabilities = capabilities

Expand Down Expand Up @@ -395,8 +413,12 @@ def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values)
driver = getattr(drivers, values.lower())
# set the default host and port if specified in the driver module
namespace.host = namespace.host or getattr(driver, "HOST", None)
namespace.port = namespace.port or getattr(driver, "PORT", None)
namespace.selenium_host = namespace.selenium_host or getattr(
driver, "HOST", None
)
namespace.selenium_port = namespace.selenium_port or getattr(
driver, "PORT", None
)


def pytest_addoption(parser):
Expand Down Expand Up @@ -453,14 +475,29 @@ def pytest_addoption(parser):
group._addoption(
"--host",
metavar="str",
help="host that the selenium server is listening on, "
help="DEPRECATED host that the selenium server is listening on, "
"which will default to the cloud provider default "
"or localhost.",
)
group._addoption(
"--port",
type=int,
metavar="num",
help="DEPRECATED port that the selenium server is listening on, "
"which will default to the cloud provider default "
"or localhost.",
)
group._addoption(
"--selenium-host",
metavar="str",
help="host that the selenium server is listening on, "
"which will default to the cloud provider default "
"or localhost.",
)
group._addoption(
"--selenium-port",
type=int,
metavar="num",
help="port that the selenium server is listening on, "
"which will default to the cloud provider default "
"or localhost.",
Expand Down
24 changes: 21 additions & 3 deletions testing/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def test_pass(driver_kwargs):
testdir.quick_qa("--driver", "Remote", file_test, passed=1)


def test_arguments_order(testdir):
@pytest.mark.parametrize(
("host_arg_name", "port_arg_name"),
[("--selenium-host", "--selenium-port"), ("--host", "--port")],
)
def test_arguments_order(testdir, host_arg_name, port_arg_name):
host = "notlocalhost"
port = "4441"
file_test = testdir.makepyfile(
Expand All @@ -120,7 +124,14 @@ def test_pass(driver_kwargs):
)
)
testdir.quick_qa(
"--driver", "Remote", "--host", host, "--port", port, file_test, passed=1
"--driver",
"Remote",
host_arg_name,
host,
port_arg_name,
port,
file_test,
passed=1,
)


Expand All @@ -138,7 +149,14 @@ def test_pass(driver_kwargs):
)
)
testdir.quick_qa(
"--host", host, "--driver", "Remote", "--port", port, file_test, passed=1
"--selenium-host",
host,
"--driver",
"Remote",
"--selenium-port",
port,
file_test,
passed=1,
)


Expand Down
15 changes: 13 additions & 2 deletions testing/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def test_pass(metadata):
testdir.quick_qa("--driver", "Remote", file_test, passed=1)


def test_metadata_host_port(testdir):
@pytest.mark.parametrize(
("host_arg_name", "port_arg_name"),
[("--selenium-host", "--selenium-port"), ("--host", "--port")],
)
def test_metadata_host_port(testdir, host_arg_name, port_arg_name):
host = "notlocalhost"
port = "4441"
file_test = testdir.makepyfile(
Expand All @@ -37,5 +41,12 @@ def test_pass(metadata):
)
)
testdir.quick_qa(
"--driver", "Remote", "--host", host, "--port", port, file_test, passed=1
"--driver",
"Remote",
host_arg_name,
host,
port_arg_name,
port,
file_test,
passed=1,
)
2 changes: 1 addition & 1 deletion testing/test_testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_invalid_credentials_file(failure, monkeypatch, tmpdir):
def test_invalid_host(failure, monkeypatch, tmpdir):
monkeypatch.setattr(os.path, "expanduser", lambda p: str(tmpdir))
tmpdir.join(".testingbot").write("[credentials]\nkey=foo\nsecret=bar")
out = failure("--host", "foo.bar.com")
out = failure("--selenium-host", "foo.bar.com")
messages = [
"nodename nor servname provided, or not known",
"Name or service not known",
Expand Down

0 comments on commit c36dc97

Please sign in to comment.