|
4 | 4 |
|
5 | 5 | from functools import partial |
6 | 6 | import os |
| 7 | +import json |
7 | 8 |
|
8 | 9 | import pytest |
9 | 10 |
|
@@ -73,6 +74,95 @@ def test_invalid_credentials_file(failure, monkeypatch, tmpdir): |
73 | 74 | assert any(message in out for message in messages) |
74 | 75 |
|
75 | 76 |
|
| 77 | +def test_credentials_in_capabilities(monkeypatch, testdir): |
| 78 | + file_test = testdir.makepyfile(""" |
| 79 | + import pytest |
| 80 | + @pytest.mark.nondestructive |
| 81 | + def test_sauce_capabilities(driver_kwargs): |
| 82 | + assert driver_kwargs['desired_capabilities']['username'] == 'foo' |
| 83 | + assert driver_kwargs['desired_capabilities']['accessKey'] == 'bar' |
| 84 | + """) |
| 85 | + |
| 86 | + run_sauce_test(monkeypatch, testdir, file_test) |
| 87 | + |
| 88 | + |
| 89 | +def test_no_sauce_options(monkeypatch, testdir): |
| 90 | + file_test = testdir.makepyfile(""" |
| 91 | + import pytest |
| 92 | + @pytest.mark.nondestructive |
| 93 | + def test_sauce_capabilities(driver_kwargs): |
| 94 | + try: |
| 95 | + driver_kwargs['desired_capabilities']['sauce:options'] |
| 96 | + raise AssertionError('<sauce:options> should not be present!') |
| 97 | + except KeyError: |
| 98 | + pass |
| 99 | + """) |
| 100 | + |
| 101 | + run_sauce_test(monkeypatch, testdir, file_test) |
| 102 | + |
| 103 | + |
| 104 | +def run_sauce_test(monkeypatch, testdir, file_test): |
| 105 | + monkeypatch.setenv('SAUCELABS_USERNAME', 'foo') |
| 106 | + monkeypatch.setenv('SAUCELABS_API_KEY', 'bar') |
| 107 | + |
| 108 | + capabilities = {'browserName': 'chrome'} |
| 109 | + variables = testdir.makefile('.json', '{{"capabilities": {}}}'.format( |
| 110 | + json.dumps(capabilities))) |
| 111 | + |
| 112 | + testdir.quick_qa( |
| 113 | + '--driver', 'saucelabs', '--variables', |
| 114 | + variables, file_test, passed=1) |
| 115 | + |
| 116 | + |
| 117 | +def test_empty_sauce_options(monkeypatch, testdir): |
| 118 | + capabilities = {'browserName': 'chrome'} |
| 119 | + expected = {'name': 'test_empty_sauce_options.test_sauce_capabilities'} |
| 120 | + run_w3c_sauce_test(capabilities, expected, monkeypatch, testdir) |
| 121 | + |
| 122 | + |
| 123 | +def test_merge_sauce_options(monkeypatch, testdir): |
| 124 | + version = {'seleniumVersion': '3.8.1'} |
| 125 | + capabilities = {'browserName': 'chrome', 'sauce:options': version} |
| 126 | + expected = {'name': 'test_merge_sauce_options.test_sauce_capabilities'} |
| 127 | + expected.update(version) |
| 128 | + run_w3c_sauce_test(capabilities, expected, monkeypatch, testdir) |
| 129 | + |
| 130 | + |
| 131 | +def test_merge_sauce_options_with_conflict(monkeypatch, testdir): |
| 132 | + name = 'conflict' |
| 133 | + capabilities = {'browserName': 'chrome', 'sauce:options': {'name': name}} |
| 134 | + expected = {'name': name} |
| 135 | + run_w3c_sauce_test(capabilities, expected, monkeypatch, testdir) |
| 136 | + |
| 137 | + |
| 138 | +def run_w3c_sauce_test(capabilities, expected_result, monkeypatch, testdir): |
| 139 | + username = 'foo' |
| 140 | + access_key = 'bar' |
| 141 | + |
| 142 | + monkeypatch.setenv('SAUCELABS_USERNAME', username) |
| 143 | + monkeypatch.setenv('SAUCELABS_API_KEY', access_key) |
| 144 | + monkeypatch.setenv('SAUCELABS_W3C', 'true') |
| 145 | + |
| 146 | + expected_result.update({'username': username, |
| 147 | + 'accessKey': access_key, |
| 148 | + 'tags': ['nondestructive']}) |
| 149 | + |
| 150 | + variables = testdir.makefile('.json', '{{"capabilities": {}}}'.format( |
| 151 | + json.dumps(capabilities))) |
| 152 | + |
| 153 | + file_test = testdir.makepyfile(""" |
| 154 | + import pytest |
| 155 | + @pytest.mark.nondestructive |
| 156 | + def test_sauce_capabilities(driver_kwargs): |
| 157 | + actual = driver_kwargs['desired_capabilities']['sauce:options'] |
| 158 | + assert actual == {} |
| 159 | + """.format(expected_result)) |
| 160 | + |
| 161 | + testdir.quick_qa( |
| 162 | + '--driver', 'saucelabs', '--variables', |
| 163 | + variables, file_test, passed=1) |
| 164 | + |
| 165 | + |
76 | 166 | def test_auth_type_none(monkeypatch): |
77 | 167 | from pytest_selenium.drivers.saucelabs import SauceLabs, get_job_url |
78 | 168 |
|
|
0 commit comments