Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing in remote webdriver #14166

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import pkgutil
import tempfile
import types
import typing
import warnings
import zipfile
from abc import ABCMeta
Expand All @@ -31,33 +30,31 @@
from contextlib import asynccontextmanager
from contextlib import contextmanager
from importlib import import_module
from typing import Dict
from typing import List
from typing import Optional
from typing import Union

from selenium.common.exceptions import InvalidArgumentException
from selenium.common.exceptions import JavascriptException
from selenium.common.exceptions import NoSuchCookieException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import WebDriverException
from typing import Dict, List, Optional, Union, Type

from selenium.common.exceptions import (
InvalidArgumentException,
JavascriptException,
NoSuchCookieException,
NoSuchElementException,
WebDriverException
)
from selenium.webdriver.common.bidi.script import Script
from selenium.webdriver.common.by import By
from selenium.webdriver.common.options import BaseOptions
from selenium.webdriver.common.print_page_options import PrintOptions
from selenium.webdriver.common.timeouts import Timeouts
from selenium.webdriver.common.virtual_authenticator import Credential
from selenium.webdriver.common.virtual_authenticator import VirtualAuthenticatorOptions
from selenium.webdriver.common.virtual_authenticator import (
Credential,
VirtualAuthenticatorOptions,
required_virtual_authenticator,
)
from selenium.webdriver.support.relative_locator import RelativeBy

from .bidi_connection import BidiConnection
from .command import Command
from .errorhandler import ErrorHandler
from .file_detector import FileDetector
from .file_detector import LocalFileDetector
from .file_detector import FileDetector, LocalFileDetector
from .mobile import Mobile
from .remote_connection import RemoteConnection
from .script_key import ScriptKey
Expand Down Expand Up @@ -184,7 +181,6 @@ def __init__(
then default LocalFileDetector() will be used.
- options - instance of a driver options.Options class
"""

if isinstance(options, list):
capabilities = create_matches(options)
_ignore_local_proxy = False
Expand Down Expand Up @@ -222,9 +218,9 @@ def __enter__(self):

def __exit__(
self,
exc_type: typing.Optional[typing.Type[BaseException]],
exc: typing.Optional[BaseException],
traceback: typing.Optional[types.TracebackType],
exc_type: Optional[Type[BaseException]],
exc: Optional[BaseException],
traceback: Optional[types.TracebackType],
):
self.quit()

Expand Down Expand Up @@ -294,7 +290,6 @@ def start_session(self, capabilities: dict) -> None:
:Args:
- capabilities - a capabilities dict to start the session with.
"""

caps = _create_caps(capabilities)
response = self.execute(Command.NEW_SESSION, caps)["value"]
self.session_id = response.get("sessionId")
Expand Down Expand Up @@ -375,7 +370,8 @@ def title(self) -> str:

def pin_script(self, script: str, script_key=None) -> ScriptKey:
"""Store common javascript scripts to be executed later by a unique
hashable ID."""
hashable ID.
"""
script_key_instance = ScriptKey(script_key)
self.pinned_scripts[script_key_instance.id] = script
return script_key_instance
Expand Down Expand Up @@ -527,9 +523,7 @@ def print_page(self, print_options: Optional[PrintOptions] = None) -> str:

@property
def switch_to(self) -> SwitchTo:
"""
:Returns:
- SwitchTo: an object containing all options to switch focus into
"""Return the `SwitchTo` object containing all options for switching focus.

:Usage:
::
Expand Down Expand Up @@ -588,7 +582,7 @@ def get_cookies(self) -> List[dict]:
"""
return self.execute(Command.GET_ALL_COOKIES)["value"]

def get_cookie(self, name) -> typing.Optional[typing.Dict]:
def get_cookie(self, name) -> Optional[Dict]:
"""Get a single cookie by name. Returns the cookie if found, None if
not.

Expand Down Expand Up @@ -872,7 +866,6 @@ def get_window_size(self, windowHandle: str = "current") -> dict:

driver.get_window_size()
"""

self._check_if_window_handle_is_current(windowHandle)
size = self.get_window_rect()

Expand Down Expand Up @@ -904,7 +897,6 @@ def get_window_position(self, windowHandle="current") -> dict:

driver.get_window_position()
"""

self._check_if_window_handle_is_current(windowHandle)
position = self.get_window_rect()

Expand Down Expand Up @@ -939,7 +931,6 @@ def set_window_rect(self, x=None, y=None, width=None, height=None) -> dict:
driver.set_window_rect(width=100, height=200)
driver.set_window_rect(x=10, y=10, width=100, height=200)
"""

if (x is None and y is None) and (not height and not width):
raise InvalidArgumentException("x and y or height and width need values")

Expand Down Expand Up @@ -1158,7 +1149,7 @@ def remove_credential(self, credential_id: Union[str, bytearray]) -> None:
credential_id = urlsafe_b64encode(credential_id).decode()

self.execute(
Command.REMOVE_CREDENTIAL, {"credentialId": credential_id, "authenticatorId": self._authenticator_id}
Command.REMOVE_CREDENTIAL, {"credentialId": credential_id, "authenticatorId": self._authenticator_id},
)

@required_virtual_authenticator
Expand All @@ -1175,9 +1166,10 @@ def set_user_verified(self, verified: bool) -> None:
"""
self.execute(Command.SET_USER_VERIFIED, {"authenticatorId": self._authenticator_id, "isUserVerified": verified})

def get_downloadable_files(self) -> dict:
def get_downloadable_files(self) -> List[str]:
"""Retrieves the downloadable files as a map of file names and their
corresponding URLs."""
corresponding URLs.
"""
if "se:downloadsEnabled" not in self.capabilities:
raise WebDriverException("You must enable downloads in order to work with downloadable files.")

Expand Down
Loading