Debian Codegraph @

selenium/webdriver/safari/options.py

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