testing/web-platform/tests/webdriver/tests/new_session/invalid_capabilities.py
author Henrik Skupin <mail@hskupin.info>
Fri, 24 Aug 2018 10:24:52 +0200
changeset 481605 1fd335726c0088e8ffe303beff533442c973b083
parent 473269 bbccc02967d3eabdc30b32f4b33370c2a2a5d936
permissions -rw-r--r--
Bug 1485580 - [wdspec] Improve timeouts tests for "Set Timeout" and "New Session". r=jgraham

import pytest

from conftest import product, flatten

from tests.new_session.support.create import invalid_data, invalid_extensions
from tests.support.asserts import assert_error


@pytest.mark.parametrize("value", [None, 1, "{}", []])
def test_invalid_capabilites(new_session, value):
    response, _ = new_session({"capabilities": value})
    assert_error(response, "invalid argument")


@pytest.mark.parametrize("value", [None, 1, "{}", []])
def test_invalid_always_match(new_session, add_browser_capabilities, value):
    capabilities = {"alwaysMatch": value, "firstMatch": [add_browser_capabilities({})]}

    response, _ = new_session({"capabilities": capabilities})
    assert_error(response, "invalid argument")


@pytest.mark.parametrize("value", [None, 1, "[]", {}])
def test_invalid_first_match(new_session, add_browser_capabilities, value):
    capabilities = {"alwaysMatch": add_browser_capabilities({}), "firstMatch": value}

    response, _ = new_session({"capabilities": capabilities})
    assert_error(response, "invalid argument")


@pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
                                  lambda key, value: {"firstMatch": [{key: value}]}])
@pytest.mark.parametrize("key,value", flatten(product(*item) for item in invalid_data))
def test_invalid_values(new_session, add_browser_capabilities, body, key, value):
    capabilities = body(key, value)
    if "alwaysMatch" in capabilities:
        capabilities["alwaysMatch"] = add_browser_capabilities(capabilities["alwaysMatch"])
    else:
        capabilities["firstMatch"][0] = add_browser_capabilities(capabilities["firstMatch"][0])

    response, _ = new_session({"capabilities": capabilities})
    assert_error(response, "invalid argument")


@pytest.mark.parametrize("body", [lambda key, value: {"alwaysMatch": {key: value}},
                                  lambda key, value: {"firstMatch": [{key: value}]}])
@pytest.mark.parametrize("key", invalid_extensions)
def test_invalid_extensions(new_session, add_browser_capabilities, body, key):
    capabilities = body(key, {})
    if "alwaysMatch" in capabilities:
        capabilities["alwaysMatch"] = add_browser_capabilities(capabilities["alwaysMatch"])
    else:
        capabilities["firstMatch"][0] = add_browser_capabilities(capabilities["firstMatch"][0])

    response, _ = new_session({"capabilities": capabilities})
    assert_error(response, "invalid argument")