Path: blob/trunk/py/selenium/webdriver/safari/options.py
1864 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617from selenium.webdriver.common.desired_capabilities import DesiredCapabilities18from selenium.webdriver.common.options import ArgOptions192021class _SafariOptionsDescriptor:22"""_SafariOptionsDescriptor is an implementation of Descriptor protocol:2324: Any look-up or assignment to the below attributes in `Options` class will be intercepted25by `__get__` and `__set__` method respectively.2627- `automatic_inspection`28- `automatic_profiling`29- `use_technology_preview`3031: When an attribute lookup happens,32Example:33`self.automatic_inspection`34`__get__` method does a dictionary look up in the dictionary `_caps` of `Options` class35and returns the value of key `safari:automaticInspection`36: When an attribute assignment happens,37Example:38`self.automatic_inspection` = True39`__set__` method sets/updates the value of the key `safari:automaticInspection` in `_caps`40dictionary in `Options` class.41"""4243def __init__(self, name, expected_type):44self.name = name45self.expected_type = expected_type4647def __get__(self, obj, cls):48if self.name == "Safari Technology Preview":49return obj._caps.get("browserName") == self.name50return obj._caps.get(self.name)5152def __set__(self, obj, value):53if not isinstance(value, self.expected_type):54raise TypeError(f"{self.name} must be of type {self.expected_type}")55if self.name == "Safari Technology Preview":56obj._caps["browserName"] = self.name if value else "safari"57else:58obj._caps[self.name] = value596061class Options(ArgOptions):62# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari63AUTOMATIC_INSPECTION = "safari:automaticInspection"64AUTOMATIC_PROFILING = "safari:automaticProfiling"65SAFARI_TECH_PREVIEW = "Safari Technology Preview"6667# creating descriptor objects68automatic_inspection = _SafariOptionsDescriptor(AUTOMATIC_INSPECTION, bool)69"""Get or Set Automatic Inspection value:7071Usage:72------73- Get74- `self.automatic_inspection`75- Set76- `self.automatic_inspection` = `value`7778Parameters:79-----------80`value`: `bool`81"""82automatic_profiling = _SafariOptionsDescriptor(AUTOMATIC_PROFILING, bool)83"""Get or Set Automatic Profiling value:8485Usage:86------87- Get88- `self.automatic_profiling`89- Set90- `self.automatic_profiling` = `value`9192Parameters:93-----------94`value`: `bool`95"""96use_technology_preview = _SafariOptionsDescriptor(SAFARI_TECH_PREVIEW, bool)97"""Get and Set Technology Preview:9899Usage:100------101- Get102- `self.use_technology_preview`103- Set104- `self.use_technology_preview` = `value`105106Parameters:107-----------108`value`: `bool`109"""110111@property112def default_capabilities(self) -> dict[str, str]:113return DesiredCapabilities.SAFARI.copy()114115116