| 
4 | 4 | 
 
  | 
5 | 5 | from functools import partial  | 
6 | 6 | import os  | 
 | 7 | +import json  | 
7 | 8 | 
 
  | 
8 | 9 | import pytest  | 
9 | 10 | 
 
  | 
@@ -96,3 +97,101 @@ def test_invalid_job_access_value(failure, monkeypatch, tmpdir):  | 
96 | 97 |     monkeypatch.setattr(os.path, "expanduser", lambda p: str(tmpdir))  | 
97 | 98 |     tmpdir.join(".browserstack").write("[report]\njob_access=foo")  | 
98 | 99 |     assert "BrowserStack job_access invalid value `foo`" in failure()  | 
 | 100 | + | 
 | 101 | + | 
 | 102 | +def test_default_caps_in_jsonwp(monkeypatch, testdir):  | 
 | 103 | +    capabilities = {"browserName": "chrome"}  | 
 | 104 | +    test_name = "test_default_caps_in_jsonwp.test_bstack_capabilities"  | 
 | 105 | +    monkeypatch.setenv("BROWSERSTACK_USERNAME", "foo")  | 
 | 106 | +    monkeypatch.setenv("BROWSERSTACK_ACCESS_KEY", "bar")  | 
 | 107 | +    variables = testdir.makefile(  | 
 | 108 | +        ".json", '{{"capabilities": {}}}'.format(json.dumps(capabilities))  | 
 | 109 | +    )  | 
 | 110 | +    file_test = testdir.makepyfile(  | 
 | 111 | +        """  | 
 | 112 | +        import pytest  | 
 | 113 | +        @pytest.mark.nondestructive  | 
 | 114 | +        def test_bstack_capabilities(driver_kwargs):  | 
 | 115 | +            assert driver_kwargs['desired_capabilities']['browserstack.user'] == 'foo'  | 
 | 116 | +            assert driver_kwargs['desired_capabilities']['browserstack.key'] == 'bar'  | 
 | 117 | +            assert driver_kwargs['desired_capabilities']['name'] == '{0}'  | 
 | 118 | +    """.format(  | 
 | 119 | +            test_name  | 
 | 120 | +        )  | 
 | 121 | +    )  | 
 | 122 | +    testdir.quick_qa(  | 
 | 123 | +        "--driver", "BrowserStack", "--variables", variables, file_test, passed=1  | 
 | 124 | +    )  | 
 | 125 | + | 
 | 126 | + | 
 | 127 | +def test_default_caps_in_jsonwp_with_conflict(monkeypatch, testdir):  | 
 | 128 | +    capabilities = {"browserName": "chrome", "name": "conflicting_name"}  | 
 | 129 | +    monkeypatch.setenv("BROWSERSTACK_USERNAME", "foo")  | 
 | 130 | +    monkeypatch.setenv("BROWSERSTACK_ACCESS_KEY", "bar")  | 
 | 131 | +    variables = testdir.makefile(  | 
 | 132 | +        ".json", '{{"capabilities": {}}}'.format(json.dumps(capabilities))  | 
 | 133 | +    )  | 
 | 134 | +    file_test = testdir.makepyfile(  | 
 | 135 | +        """  | 
 | 136 | +        import pytest  | 
 | 137 | +        @pytest.mark.nondestructive  | 
 | 138 | +        def test_bstack_capabilities(driver_kwargs):  | 
 | 139 | +            assert driver_kwargs['desired_capabilities']['browserstack.user'] == 'foo'  | 
 | 140 | +            assert driver_kwargs['desired_capabilities']['browserstack.key'] == 'bar'  | 
 | 141 | +            assert driver_kwargs['desired_capabilities']['name'] == 'conflicting_name'  | 
 | 142 | +    """  | 
 | 143 | +    )  | 
 | 144 | +    testdir.quick_qa(  | 
 | 145 | +        "--driver", "BrowserStack", "--variables", variables, file_test, passed=1  | 
 | 146 | +    )  | 
 | 147 | + | 
 | 148 | + | 
 | 149 | +def test_default_caps_in_W3C(monkeypatch, testdir):  | 
 | 150 | +    capabilities = {"browserName": "chrome", "bstack:options": {}}  | 
 | 151 | +    monkeypatch.setenv("BROWSERSTACK_USERNAME", "foo")  | 
 | 152 | +    monkeypatch.setenv("BROWSERSTACK_ACCESS_KEY", "bar")  | 
 | 153 | +    variables = testdir.makefile(  | 
 | 154 | +        ".json", '{{"capabilities": {}}}'.format(json.dumps(capabilities))  | 
 | 155 | +    )  | 
 | 156 | +    file_test = testdir.makepyfile(  | 
 | 157 | +        """  | 
 | 158 | +        import pytest  | 
 | 159 | +        @pytest.mark.nondestructive  | 
 | 160 | +        def test_bstack_capabilities(driver_kwargs):  | 
 | 161 | +            assert driver_kwargs['desired_capabilities']['bstack:options'] == {  | 
 | 162 | +                'userName': 'foo',  | 
 | 163 | +                'accessKey': 'bar',  | 
 | 164 | +                'sessionName': 'test_default_caps_in_W3C.test_bstack_capabilities'  | 
 | 165 | +            }  | 
 | 166 | +    """  | 
 | 167 | +    )  | 
 | 168 | +    testdir.quick_qa(  | 
 | 169 | +        "--driver", "BrowserStack", "--variables", variables, file_test, passed=1  | 
 | 170 | +    )  | 
 | 171 | + | 
 | 172 | + | 
 | 173 | +def test_default_caps_in_W3C_with_conflict(monkeypatch, testdir):  | 
 | 174 | +    capabilities = {  | 
 | 175 | +        "browserName": "chrome",  | 
 | 176 | +        "bstack:options": {"sessionName": "conflicting_name"},  | 
 | 177 | +    }  | 
 | 178 | +    monkeypatch.setenv("BROWSERSTACK_USERNAME", "foo")  | 
 | 179 | +    monkeypatch.setenv("BROWSERSTACK_ACCESS_KEY", "bar")  | 
 | 180 | +    variables = testdir.makefile(  | 
 | 181 | +        ".json", '{{"capabilities": {}}}'.format(json.dumps(capabilities))  | 
 | 182 | +    )  | 
 | 183 | +    file_test = testdir.makepyfile(  | 
 | 184 | +        """  | 
 | 185 | +        import pytest  | 
 | 186 | +        @pytest.mark.nondestructive  | 
 | 187 | +        def test_bstack_capabilities(driver_kwargs):  | 
 | 188 | +            assert driver_kwargs['desired_capabilities']['bstack:options'] == {  | 
 | 189 | +                'userName': 'foo',  | 
 | 190 | +                'accessKey': 'bar',  | 
 | 191 | +                'sessionName': 'conflicting_name'  | 
 | 192 | +            }  | 
 | 193 | +    """  | 
 | 194 | +    )  | 
 | 195 | +    testdir.quick_qa(  | 
 | 196 | +        "--driver", "BrowserStack", "--variables", variables, file_test, passed=1  | 
 | 197 | +    )  | 
0 commit comments