Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/unit/selenium/webdriver/common/common_options_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 pytest
19
20
from selenium.webdriver import Proxy
21
from selenium.webdriver.common.options import ArgOptions
22
from selenium.webdriver.common.proxy import ProxyType
23
24
25
@pytest.fixture
26
def options():
27
return ArgOptions()
28
29
30
def test_add_arguments(options):
31
options.add_argument("foo")
32
assert "foo" in options._arguments
33
34
35
def test_get_arguments(options):
36
options._arguments = ["foo"]
37
assert "foo" in options.arguments
38
39
40
def test_enables_mobile(options):
41
options.enable_mobile(android_package="cheese")
42
assert options.mobile_options["androidPackage"] == "cheese"
43
assert not hasattr(options.mobile_options, "androidActivity")
44
assert not hasattr(options.mobile_options, "androidDeviceSerial")
45
46
47
def test_enable_mobile_errors_without_package(options):
48
with pytest.raises(AttributeError):
49
options.enable_mobile()
50
51
52
def test_enable_mobile_with_activity(options):
53
options.enable_mobile(android_package="sausages", android_activity="eating")
54
assert options.mobile_options["androidActivity"] == "eating"
55
56
57
def test_enable_mobile_with_device_serial(options):
58
options.enable_mobile(android_package="cheese", android_activity="crackers", device_serial="1234")
59
options.mobile_options["androidDeviceSerial"] == "1234"
60
61
62
def test_missing_capabilities_return_false_rather_than_none():
63
options = ArgOptions()
64
assert options.strict_file_interactability is False
65
assert options.set_window_rect is False
66
assert options.accept_insecure_certs is False
67
68
69
def test_add_proxy():
70
options = ArgOptions()
71
proxy = Proxy({"proxyType": ProxyType.MANUAL})
72
proxy.http_proxy = "http://user:password@http_proxy.com:8080"
73
options.proxy = proxy
74
caps = options.to_capabilities()
75
76
assert options.proxy == proxy
77
assert caps.get("proxy") == proxy.to_capabilities()
78
79
80
def test_default_bidi():
81
options = ArgOptions()
82
assert options.enable_bidi is False
83
assert options.web_socket_url is None
84
85
86
def test_enable_bidi():
87
options = ArgOptions()
88
options.enable_bidi = True
89
assert options.enable_bidi is True
90
assert options.web_socket_url is None
91
92
93
def test_set_socket_url():
94
options = ArgOptions()
95
options.web_socket_url = "socket_url"
96
assert options.enable_bidi is True
97
assert options.web_socket_url == "socket_url"
98
99