Path: blob/trunk/py/selenium/webdriver/safari/options.py
4076 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.2324Any look-up or assignment to the below attributes in `Options` class will be intercepted25by `__get__` and `__set__` method respectively when an attribute lookup happens:2627- `automatic_inspection`28- `automatic_profiling`29- `use_technology_preview`3031Example:32`self.automatic_inspection`33(`__get__` method does a dictionary look up in the dictionary `_caps` of `Options` class34and returns the value of key `safari:automaticInspection`)3536Example:37`self.automatic_inspection` = True38(`__set__` method sets/updates the value of the key `safari:automaticInspection` in `_caps`39dictionary in `Options` class)40"""4142def __init__(self, name, expected_type):43self.name = name44self.expected_type = expected_type4546def __get__(self, obj, cls):47if self.name == "Safari Technology Preview":48return obj._caps.get("browserName") == self.name49return obj._caps.get(self.name)5051def __set__(self, obj, value):52if not isinstance(value, self.expected_type):53raise TypeError(f"{self.name} must be of type {self.expected_type}")54if self.name == "Safari Technology Preview":55obj._caps["browserName"] = self.name if value else "safari"56else:57obj._caps[self.name] = value585960class Options(ArgOptions):61# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari62AUTOMATIC_INSPECTION = "safari:automaticInspection"63AUTOMATIC_PROFILING = "safari:automaticProfiling"64SAFARI_TECH_PREVIEW = "Safari Technology Preview"6566# creating descriptor objects67automatic_inspection = _SafariOptionsDescriptor(AUTOMATIC_INSPECTION, bool)68"""Whether to enable automatic inspection."""6970automatic_profiling = _SafariOptionsDescriptor(AUTOMATIC_PROFILING, bool)71"""Whether to enable automatic profiling."""7273use_technology_preview = _SafariOptionsDescriptor(SAFARI_TECH_PREVIEW, bool)74"""Whether to use Safari Technology Preview."""7576@property77def default_capabilities(self) -> dict[str, str]:78return DesiredCapabilities.SAFARI.copy()798081