Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/unit/selenium/webdriver/remote/remote_server_tests.py
1990 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
import os
19
import re
20
21
import pytest
22
23
from selenium.webdriver.remote.server import Server
24
25
26
def test_server_with_defaults():
27
server = Server()
28
assert server.host is None
29
assert server.port == 4444
30
assert server.path is None
31
assert server.version is None
32
assert server.log_level == "INFO"
33
assert server.env is None
34
35
36
def test_server_with_args():
37
server = Server("foo", 9999)
38
assert server.host == "foo"
39
assert server.port == 9999
40
41
42
def test_server_with_kwargs():
43
server = Server(host="foo", port=9999, version="1.1.1", log_level="WARNING", env={"FOO": "bar"})
44
assert server.host == "foo"
45
assert server.port == 9999
46
assert server.path is None
47
assert server.version == "1.1.1"
48
assert server.log_level == "WARNING"
49
assert server.env == {"FOO": "bar"}
50
51
52
def test_server_with_invalid_port():
53
port = "invalid"
54
msg = f"Server.__init__() got an invalid port: '{port}'"
55
with pytest.raises(TypeError, match=re.escape(msg)):
56
Server(port=port)
57
58
59
def test_server_with_port_out_of_range():
60
with pytest.raises(ValueError, match="port must be 0-65535"):
61
Server(port=99999)
62
63
64
def test_server_with_bad_path():
65
path = "/path/to/nowhere"
66
msg = f"Can't find server .jar located at {path}"
67
with pytest.raises(OSError, match=re.escape(msg)):
68
Server(path=path)
69
70
71
def test_server_with_invalid_version():
72
versions = ("0.0", "invalid")
73
for version in versions:
74
msg = f"Server.__init__() got an invalid version: '{version}'"
75
with pytest.raises(TypeError, match=re.escape(msg)):
76
Server(version=version)
77
78
79
def test_server_with_invalid_log_level():
80
msg = ", ".join(("SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST"))
81
with pytest.raises(TypeError, match=f"log_level must be one of: {msg}"):
82
Server(log_level="BAD")
83
84
85
def test_server_with_env_os_environ():
86
server = Server(env=os.environ)
87
assert isinstance(server.env, os._Environ)
88
89
90
def test_server_with_env_dict():
91
env = {}
92
server = Server(env=env)
93
assert isinstance(server.env, dict)
94
assert server.env == {}
95
96
97
def test_server_with_invalid_env():
98
with pytest.raises(TypeError, match="env must be a mapping of environment variables"):
99
Server(env=[])
100
101
102
def test_stopping_server_thats_not_running():
103
server = Server()
104
with pytest.raises(RuntimeError, match="Selenium server isn't running"):
105
server.stop()
106
assert server.process is None
107
108