Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/safari/options.py
1864 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
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
19
from selenium.webdriver.common.options import ArgOptions
20
21
22
class _SafariOptionsDescriptor:
23
"""_SafariOptionsDescriptor is an implementation of Descriptor protocol:
24
25
: Any look-up or assignment to the below attributes in `Options` class will be intercepted
26
by `__get__` and `__set__` method respectively.
27
28
- `automatic_inspection`
29
- `automatic_profiling`
30
- `use_technology_preview`
31
32
: When an attribute lookup happens,
33
Example:
34
`self.automatic_inspection`
35
`__get__` method does a dictionary look up in the dictionary `_caps` of `Options` class
36
and returns the value of key `safari:automaticInspection`
37
: When an attribute assignment happens,
38
Example:
39
`self.automatic_inspection` = True
40
`__set__` method sets/updates the value of the key `safari:automaticInspection` in `_caps`
41
dictionary in `Options` class.
42
"""
43
44
def __init__(self, name, expected_type):
45
self.name = name
46
self.expected_type = expected_type
47
48
def __get__(self, obj, cls):
49
if self.name == "Safari Technology Preview":
50
return obj._caps.get("browserName") == self.name
51
return obj._caps.get(self.name)
52
53
def __set__(self, obj, value):
54
if not isinstance(value, self.expected_type):
55
raise TypeError(f"{self.name} must be of type {self.expected_type}")
56
if self.name == "Safari Technology Preview":
57
obj._caps["browserName"] = self.name if value else "safari"
58
else:
59
obj._caps[self.name] = value
60
61
62
class Options(ArgOptions):
63
# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
64
AUTOMATIC_INSPECTION = "safari:automaticInspection"
65
AUTOMATIC_PROFILING = "safari:automaticProfiling"
66
SAFARI_TECH_PREVIEW = "Safari Technology Preview"
67
68
# creating descriptor objects
69
automatic_inspection = _SafariOptionsDescriptor(AUTOMATIC_INSPECTION, bool)
70
"""Get or Set Automatic Inspection value:
71
72
Usage:
73
------
74
- Get
75
- `self.automatic_inspection`
76
- Set
77
- `self.automatic_inspection` = `value`
78
79
Parameters:
80
-----------
81
`value`: `bool`
82
"""
83
automatic_profiling = _SafariOptionsDescriptor(AUTOMATIC_PROFILING, bool)
84
"""Get or Set Automatic Profiling value:
85
86
Usage:
87
------
88
- Get
89
- `self.automatic_profiling`
90
- Set
91
- `self.automatic_profiling` = `value`
92
93
Parameters:
94
-----------
95
`value`: `bool`
96
"""
97
use_technology_preview = _SafariOptionsDescriptor(SAFARI_TECH_PREVIEW, bool)
98
"""Get and Set Technology Preview:
99
100
Usage:
101
------
102
- Get
103
- `self.use_technology_preview`
104
- Set
105
- `self.use_technology_preview` = `value`
106
107
Parameters:
108
-----------
109
`value`: `bool`
110
"""
111
112
@property
113
def default_capabilities(self) -> dict[str, str]:
114
return DesiredCapabilities.SAFARI.copy()
115
116