diff --git a/py/selenium/webdriver/chromium/options.py b/py/selenium/webdriver/chromium/options.py index 3edf2655462aa..14d974c514f96 100644 --- a/py/selenium/webdriver/chromium/options.py +++ b/py/selenium/webdriver/chromium/options.py @@ -151,17 +151,6 @@ def headless(self, value: bool): else: self._arguments = list(set(self._arguments) - args) - @property - def page_load_strategy(self) -> str: - return self._caps["pageLoadStrategy"] - - @page_load_strategy.setter - def page_load_strategy(self, strategy: str): - if strategy in ["normal", "eager", "none"]: - self.set_capability("pageLoadStrategy", strategy) - else: - raise ValueError("Strategy can only be one of the following: normal, eager, none") - def to_capabilities(self) -> dict: """ Creates a capabilities with all the options that have been set diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index 0fe46b5cb34b2..e940a4645a3b1 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -16,6 +16,9 @@ # under the License. from abc import ABCMeta, abstractmethod +from typing import NoReturn +from selenium.webdriver.common.proxy import Proxy +from selenium.common.exceptions import InvalidArgumentException class BaseOptions(metaclass=ABCMeta): @@ -37,6 +40,100 @@ def set_capability(self, name, value): """ Sets a capability """ self._caps[name] = value + @property + def browser_version(self) -> str: + """ + :returns: the version of the browser if set, otherwise None. + """ + return self._caps["browserVersion"] + + @browser_version.setter + def browser_version(self, version: str) -> NoReturn: + """ + Requires the major version of the browser to match provided value: + https://w3c.github.io/webdriver/#dfn-browser-version + + :param version: The required version of the browser + """ + self.set_capability("browserVersion", version) + + @property + def platform_name(self) -> str: + """ + :returns: The name of the platform + """ + return self._caps["platformName"] + + @platform_name.setter + def platform_name(self, platform: str) -> NoReturn: + """ + Requires the platform to match the provided value: https://w3c.github.io/webdriver/#dfn-platform-name + + :param platform: the required name of the platform + """ + self.set_capability("platformName", platform) + + @property + def page_load_strategy(self) -> str: + """ + :returns: page load strategy if set, the default is "normal" + """ + return self._caps["pageLoadStrategy"] + + @page_load_strategy.setter + def page_load_strategy(self, strategy: str) -> NoReturn: + """ + Determines the point at which a navigation command is returned: + https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies + + :param strategy: the strategy corresponding to a document readiness state + """ + if strategy in ["normal", "eager", "none"]: + self.set_capability("pageLoadStrategy", strategy) + else: + raise ValueError("Strategy can only be one of the following: normal, eager, none") + + @property + def unhandled_prompt_behavior(self) -> str: + """ + :returns: unhandled prompt behavior if set, the default is "dismiss and notify" + """ + return self._caps["unhandledPromptBehavior"] + + @unhandled_prompt_behavior.setter + def unhandled_prompt_behavior(self, behavior: str) -> NoReturn: + """ + How the driver should respond when an alert is present and the command sent is not handling the alert: + https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies + + :param behavior: behavior to use when an alert is encountered + """ + if behavior in ["dismiss", "accept", "dismiss and notify", "accept and notify", "ignore"]: + self.set_capability("unhandledPromptBehavior", behavior) + else: + raise ValueError("Behavior can only be one of the following: dismiss, accept, dismiss and notify, " + "accept and notify, ignore") + + @property + def timeouts(self) -> dict: + """ + :returns: Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds) + """ + return self._caps["timeouts"] + + @timeouts.setter + def timeouts(self, timeouts: dict) -> NoReturn: + """ + How long the driver should wait for actions to complete before returning an error + https://w3c.github.io/webdriver/#timeouts + + :param timeouts: values in milliseconds for implicit wait, page load and script timeout + """ + if all(x in timeouts.keys() for x in ["implicit", "pageLoad", "script"]): + self.set_capability("timeouts", timeouts) + else: + raise ValueError("Timeout keys can only be one of the following: implicit, pageLoad, script") + def enable_mobile(self, android_package: str = None, android_activity: str = None, device_serial: str = None): """ Enables mobile browser use for browsers that support it @@ -54,6 +151,69 @@ def enable_mobile(self, android_package: str = None, android_activity: str = Non if device_serial: self.mobile_options["androidDeviceSerial"] = device_serial + @property + def accept_insecure_certs(self) -> bool: + """ + :returns: whether the session accepts insecure certificates + """ + return self._caps.get('acceptInsecureCerts') + + @accept_insecure_certs.setter + def accept_insecure_certs(self, value: bool) -> NoReturn: + """ + Whether untrusted and self-signed TLS certificates are implicitly trusted: + https://w3c.github.io/webdriver/#dfn-insecure-tls-certificates + + :param value: whether to accept insecure certificates + """ + self._caps['acceptInsecureCerts'] = value + + @property + def strict_file_interactability(self) -> bool: + """ + :returns: whether session is strict about file interactability + """ + return self._caps.get('strictFileInteractability') + + @strict_file_interactability.setter + def strict_file_interactability(self, value: bool): + """ + Whether interactability checks will be applied to file type input elements. The default is false. + + :param value: whether file interactability is strict + """ + self._caps['strictFileInteractability'] = value + + @property + def set_window_rect(self) -> bool: + """ + :returns: whether the remote end supports setting window size and position + """ + return self._caps.get('setWindowRect') + + @set_window_rect.setter + def set_window_rect(self, value: bool): + """ + Whether the remote end supports all of the resizing and positioning commands. The default is false. + https://w3c.github.io/webdriver/#dfn-strict-file-interactability + + :param value: whether remote end must support setting window resizing and repositioning + """ + self._caps['setWindowRect'] = value + + @property + def proxy(self) -> Proxy: + """ + :Returns: Proxy if set, otherwise None. + """ + return self._proxy + + @proxy.setter + def proxy(self, value: Proxy): + if not isinstance(value, Proxy): + raise InvalidArgumentException("Only Proxy objects can be passed in.") + self._proxy = value + @abstractmethod def to_capabilities(self): """Convert options into capabilities dictionary.""" diff --git a/py/selenium/webdriver/firefox/options.py b/py/selenium/webdriver/firefox/options.py index a48504ea8607b..441dfe0965292 100644 --- a/py/selenium/webdriver/firefox/options.py +++ b/py/selenium/webdriver/firefox/options.py @@ -16,9 +16,7 @@ # under the License. from typing import Union import warnings -from selenium.common.exceptions import InvalidArgumentException from selenium.webdriver.common.desired_capabilities import DesiredCapabilities -from selenium.webdriver.common.proxy import Proxy from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver.firefox.firefox_profile import FirefoxProfile from selenium.webdriver.common.options import ArgOptions @@ -72,14 +70,6 @@ def binary_location(self, value: str): """ Sets the location of the browser binary by string """ self.binary = value - @property - def accept_insecure_certs(self) -> bool: - return self._caps.get('acceptInsecureCerts') - - @accept_insecure_certs.setter - def accept_insecure_certs(self, value: bool): - self._caps['acceptInsecureCerts'] = value - @property def preferences(self) -> dict: """:Returns: A dict of preferences.""" @@ -89,19 +79,6 @@ def set_preference(self, name: str, value: Union[str, int, bool]): """Sets a preference.""" self._preferences[name] = value - @property - def proxy(self) -> Proxy: - """ - :Returns: Proxy if set, otherwise None. - """ - return self._proxy - - @proxy.setter - def proxy(self, value: Proxy): - if not isinstance(value, Proxy): - raise InvalidArgumentException("Only Proxy objects can be passed in.") - self._proxy = value - @property def profile(self) -> FirefoxProfile: """ @@ -150,17 +127,6 @@ def headless(self, value: bool): elif '-headless' in self._arguments: self._arguments.remove('-headless') - @property - def page_load_strategy(self) -> str: - return self._caps["pageLoadStrategy"] - - @page_load_strategy.setter - def page_load_strategy(self, strategy: str): - if strategy in ["normal", "eager", "none"]: - self.set_capability("pageLoadStrategy", strategy) - else: - raise ValueError("Strategy can only be one of the following: normal, eager, none") - def enable_mobile(self, android_package: str = "org.mozilla.firefox", android_activity=None, device_serial=None): super().enable_mobile(android_package, android_activity, device_serial) diff --git a/py/selenium/webdriver/opera/options.py b/py/selenium/webdriver/opera/options.py index 5bc10b44c448f..4fc29c172d665 100644 --- a/py/selenium/webdriver/opera/options.py +++ b/py/selenium/webdriver/opera/options.py @@ -79,17 +79,6 @@ def android_command_line_file(self, value): """ self._android_command_line_file = value - @property - def page_load_strategy(self): - return self._caps["pageLoadStrategy"] - - @page_load_strategy.setter - def page_load_strategy(self, strategy): - if strategy in ["normal", "eager", "none"]: - self.set_capability("pageLoadStrategy", strategy) - else: - raise ValueError("Strategy can only be one of the following: normal, eager, none") - def to_capabilities(self): """ Creates a capabilities with all the options that have been set and diff --git a/py/selenium/webdriver/safari/options.py b/py/selenium/webdriver/safari/options.py index 4f78a57677cec..1687bf3c604d1 100644 --- a/py/selenium/webdriver/safari/options.py +++ b/py/selenium/webdriver/safari/options.py @@ -54,25 +54,6 @@ def binary_location(self, value: str): """ self._binary_location = value - @property - def accept_insecure_certs(self) -> bool: - return self._caps.get('acceptInsecureCerts') - - @accept_insecure_certs.setter - def accept_insecure_certs(self, value: bool): - self._caps['acceptInsecureCerts'] = value - - @property - def page_load_strategy(self) -> str: - return self._caps["pageLoadStrategy"] - - @page_load_strategy.setter - def page_load_strategy(self, strategy: str): - if strategy in ["normal", "eager", "none"]: - self.set_capability("pageLoadStrategy", strategy) - else: - raise ValueError("Strategy can only be one of the following: normal, eager, none") - def to_capabilities(self) -> dict: """Marshals the options to an desired capabilities object. """ diff --git a/py/selenium/webdriver/webkitgtk/options.py b/py/selenium/webdriver/webkitgtk/options.py index cbf5a620c9352..ad84c468336ae 100644 --- a/py/selenium/webdriver/webkitgtk/options.py +++ b/py/selenium/webdriver/webkitgtk/options.py @@ -61,17 +61,6 @@ def overlay_scrollbars_enabled(self, value): """ self._overlay_scrollbars_enabled = value - @property - def page_load_strategy(self): - return self._caps["pageLoadStrategy"] - - @page_load_strategy.setter - def page_load_strategy(self, strategy): - if strategy in ["normal", "eager", "none"]: - self.set_capability("pageLoadStrategy", strategy) - else: - raise ValueError("Strategy can only be one of the following: normal, eager, none") - def to_capabilities(self): """ Creates a capabilities with all the options that have been set and