Skip to content

Commit

Permalink
Add support for other providers to use non-default host and port (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored and davehunt committed May 2, 2017
1 parent 0096850 commit 13c48ff
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
6 changes: 6 additions & 0 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ the ``--capability`` command line arguments. See the
`test options <http://testingbot.com/support/other/test-options>`_
for full details of what can be configured.

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.

CrossBrowserTesting
-------------------

Expand Down
21 changes: 4 additions & 17 deletions pytest_selenium/drivers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os

import pytest


def pytest_addoption(parser):
group = parser.getgroup('selenium', 'selenium')
group._addoption('--host',
default=os.environ.get('SELENIUM_HOST', 'localhost'),
metavar='str',
help='host that selenium server is listening on. '
'(default: %(default)s)')
group._addoption('--port',
type=int,
default=os.environ.get('SELENIUM_PORT', 4444),
metavar='num',
help='port that selenium server is listening on. '
'(default: %(default)s)')


def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs):
if 'browserName' not in capabilities:
# remote instances must at least specify a browserName capability
Expand All @@ -30,7 +14,10 @@ def driver_kwargs(capabilities, firefox_profile, host, port, **kwargs):
capabilities.setdefault('version', '') # default to any version
capabilities.setdefault('platform', 'ANY') # default to any platform

executor = 'http://{host}:{port}/wd/hub'.format(host=host, port=port)
executor = 'http://{host}:{port}/wd/hub'.format(
host=host or os.environ.get('SELENIUM_HOST', 'localhost'),
port=port or os.environ.get('SELENIUM_PORT', 4444))

kwargs = {
'command_executor': executor,
'desired_capabilities': capabilities,
Expand Down
13 changes: 9 additions & 4 deletions pytest_selenium/drivers/testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ class TestingBot(Provider):
API = 'https://api.testingbot.com/v1/tests/{session}'
JOB = 'http://testingbot.com/members/tests/{session}'

def __init__(self, host=None, port=None):
super(TestingBot, self).__init__()
self.host = host or 'hub.testingbot.com'
self.port = port or 80

@property
def auth(self):
return (self.key, self.secret)

@property
def executor(self):
return 'http://{0}:{1}@hub.testingbot.com/wd/hub'.format(
self.key, self.secret)
return 'http://{0.key}:{0.secret}@{0.host}:{0.port}/wd/hub'.format(
self)

@property
def key(self):
Expand Down Expand Up @@ -75,8 +80,8 @@ def pytest_selenium_runtest_makereport(item, report, summary, extra):
provider.name, e))


def driver_kwargs(request, test, capabilities, **kwargs):
provider = TestingBot()
def driver_kwargs(request, test, capabilities, host, port, **kwargs):
provider = TestingBot(host, port)
keywords = request.node.keywords
capabilities.setdefault('name', test)
markers = [m for m in keywords.keys() if isinstance(keywords[m], MarkInfo)]
Expand Down
11 changes: 11 additions & 0 deletions pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,14 @@ def pytest_addoption(parser):
metavar='str',
help='selenium eventlistener class, e.g. '
'package.module.EventListenerClassName.')
group._addoption('--host',
metavar='str',
help='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='port that the selenium server is listening on, '
'which will default to the cloud provider default '
'or localhost.')
7 changes: 7 additions & 0 deletions testing/test_testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ def test_invalid_credentials_file(failure, monkeypatch, tmpdir):
out = failure('--capability', 'browserName', 'firefox')
messages = ['incorrect TestingBot credentials', 'basic auth failed']
assert any(message in out for message in messages)


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')
assert "urlopen error" in out

0 comments on commit 13c48ff

Please sign in to comment.