Skip to content

Commit

Permalink
Accept Sauce Labs own environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored and davehunt committed Apr 27, 2018
1 parent 70d3cb2 commit de4572d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ Sauce Labs
To run your automated tests using `Sauce Labs <https://saucelabs.com/>`_, you
must provide a valid username and API key. This can be done either by using
a ``.saucelabs`` configuration file in the working directory or your home
directory, or by setting the ``SAUCELABS_USERNAME`` and ``SAUCELABS_API_KEY``
environment variables.
directory, by setting the ``SAUCELABS_USERNAME`` and ``SAUCELABS_API_KEY``
environment variables, or by using the environment variables as detailed
`here <https://wiki.saucelabs.com/display/DOCS/
Best+Practice%3A+Use+Environment+Variables+for+Authentication+Credentials>`_

Alternatively, when using `Jenkins CI`_ declarative pipelines,
credentials can be set as environment variables as follows:
Expand Down
6 changes: 4 additions & 2 deletions pytest_selenium/drivers/saucelabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def name(self):
@property
def username(self):
return self.get_credential('username', ['SAUCELABS_USERNAME',
'SAUCELABS_USR'])
'SAUCELABS_USR',
'SAUCE_USERNAME'])

@property
def key(self):
return self.get_credential('key', ['SAUCELABS_API_KEY',
'SAUCELABS_PSW'])
'SAUCELABS_PSW',
'SAUCE_ACCESS_KEY'])


@pytest.mark.optionalhook
Expand Down
4 changes: 3 additions & 1 deletion testing/test_saucelabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def test_missing_api_key_file(failure, monkeypatch, tmpdir):
@pytest.mark.parametrize(('username', 'key'), [('SAUCELABS_USERNAME',
'SAUCELABS_API_KEY'),
('SAUCELABS_USR',
'SAUCELABS_PSW')])
'SAUCELABS_PSW'),
('SAUCE_USERNAME',
'SAUCE_ACCESS_KEY')])
def test_invalid_credentials_env(failure, monkeypatch, tmpdir, username, key):
monkeypatch.setattr(os.path, 'expanduser', lambda p: str(tmpdir))
monkeypatch.setenv(username, 'foo')
Expand Down

0 comments on commit de4572d

Please sign in to comment.