Skip to content

Commit

Permalink
Merge 8602eaa into 2a6b075
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner authored May 14, 2023
2 parents 2a6b075 + 8602eaa commit 8cd2aa8
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 110 deletions.
12 changes: 4 additions & 8 deletions py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.driver_finder import DriverFinder

from ..remote.client_config import ClientConfig
from .options import Options
from .service import DEFAULT_EXECUTABLE_PATH
from .service import Service

DEFAULT_PORT = 0
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None


class WebDriver(ChromiumDriver):
Expand All @@ -46,7 +46,8 @@ def __init__(
service_log_path=DEFAULT_SERVICE_LOG_PATH,
chrome_options=None,
service: Service = None,
keep_alive=DEFAULT_KEEP_ALIVE,
keep_alive=None,
client_config: ClientConfig = ClientConfig(),
) -> None:
"""Creates a new instance of the chrome driver. Starts the service and
then creates new instance of chrome driver.
Expand All @@ -69,12 +70,6 @@ def __init__(
if chrome_options:
warnings.warn("use options instead of chrome_options", DeprecationWarning, stacklevel=2)
options = chrome_options
if keep_alive != DEFAULT_KEEP_ALIVE:
warnings.warn(
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
)
else:
keep_alive = True
if not options:
options = self.create_options()
if not service:
Expand All @@ -91,6 +86,7 @@ def __init__(
service_log_path,
service,
keep_alive,
client_config,
)

def create_options(self) -> Options:
Expand Down
7 changes: 3 additions & 4 deletions py/selenium/webdriver/chromium/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing

from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.remote_connection import RemoteConnection


Expand All @@ -25,10 +25,9 @@ def __init__(
remote_server_addr: str,
vendor_prefix: str,
browser_name: str,
keep_alive: bool = True,
ignore_proxy: typing.Optional[bool] = False,
client_config: ClientConfig = ClientConfig(),
) -> None:
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
super().__init__(remote_server_addr, client_config=client_config)
self.browser_name = browser_name
self._commands["launchApp"] = ("POST", "/session/$sessionId/chromium/launch_app")
self._commands["setPermissions"] = ("POST", "/session/$sessionId/permissions")
Expand Down
26 changes: 6 additions & 20 deletions py/selenium/webdriver/chromium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import warnings

from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
from selenium.webdriver.common.options import BaseOptions
from selenium.webdriver.common.service import Service
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

DEFAULT_PORT = 0
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None


class ChromiumDriver(RemoteWebDriver):
Expand All @@ -43,7 +42,8 @@ def __init__(
desired_capabilities=None,
service_log_path=DEFAULT_SERVICE_LOG_PATH,
service: Service = None,
keep_alive=DEFAULT_KEEP_ALIVE,
keep_alive=None,
client_config: ClientConfig = ClientConfig(),
) -> None:
"""Creates a new WebDriver instance of the ChromiumDriver. Starts the
service and then creates new WebDriver instance of ChromiumDriver.
Expand Down Expand Up @@ -74,26 +74,16 @@ def __init__(
DeprecationWarning,
stacklevel=2,
)
if keep_alive != DEFAULT_KEEP_ALIVE and type(self) == __class__:
warnings.warn(
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
)
else:
keep_alive = True

self.vendor_prefix = vendor_prefix

_ignore_proxy = None
if not options:
options = self.create_options()

if desired_capabilities:
for key, value in desired_capabilities.items():
options.set_capability(key, value)

if options._ignore_local_proxy:
_ignore_proxy = options._ignore_local_proxy

if not service:
raise AttributeError("service cannot be None")

Expand All @@ -102,14 +92,10 @@ def __init__(

try:
super().__init__(
command_executor=ChromiumRemoteConnection(
remote_server_addr=self.service.service_url,
browser_name=browser_name,
vendor_prefix=vendor_prefix,
keep_alive=keep_alive,
ignore_proxy=_ignore_proxy,
),
command_executor=self.service.service_url,
options=options,
keep_alive=keep_alive,
client_config=client_config,
)
except Exception:
self.quit()
Expand Down
19 changes: 13 additions & 6 deletions py/selenium/webdriver/common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import typing
import warnings
from abc import ABCMeta
from abc import abstractmethod

Expand All @@ -30,6 +31,7 @@ def __init__(self) -> None:
self._caps = self.default_capabilities
self.set_capability("pageLoadStrategy", "normal")
self.mobile_options = None
self._ignore_local_proxy = False

@property
def capabilities(self):
Expand Down Expand Up @@ -223,12 +225,22 @@ def to_capabilities(self):
def default_capabilities(self):
"""Return minimal capabilities necessary as a dictionary."""

def ignore_local_proxy_environment_variables(self) -> None:
"""By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
being picked up and used."""
warnings.warn(
"setting ignore proxy in Options has been deprecated, "
"set ProxyType.DIRECT in ClientConfig and pass to WebDriver constructor instead",
DeprecationWarning,
stacklevel=2,
)
self._ignore_local_proxy = True


class ArgOptions(BaseOptions):
def __init__(self) -> None:
super().__init__()
self._arguments = []
self._ignore_local_proxy = False

@property
def arguments(self):
Expand All @@ -248,11 +260,6 @@ def add_argument(self, argument):
else:
raise ValueError("argument can not be null")

def ignore_local_proxy_environment_variables(self) -> None:
"""By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
being picked up and used."""
self._ignore_local_proxy = True

def to_capabilities(self):
return self._caps

Expand Down
7 changes: 5 additions & 2 deletions py/selenium/webdriver/edge/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.driver_finder import DriverFinder

from ..remote.client_config import ClientConfig
from .options import Options
from .service import DEFAULT_EXECUTABLE_PATH
from .service import Service
Expand All @@ -44,7 +45,8 @@ def __init__(
capabilities=None,
service_log_path=DEFAULT_SERVICE_LOG_PATH,
service: Service = None,
keep_alive=False,
keep_alive=None,
client_config: ClientConfig = ClientConfig(),
verbose=False, # Todo: Why is this now unused?
) -> None:
"""Creates a new instance of the edge driver. Starts the service and
Expand All @@ -59,7 +61,7 @@ def __init__(
capabilities only, such as "proxy" or "loggingPref".
- service_log_path - Deprecated: Where to log information from the driver.
- service - Service object for handling the browser driver if you need to pass extra details
- keep_alive - Whether to configure EdgeRemoteConnection to use HTTP keep-alive.
- keep_alive - Deprecated: Whether to configure EdgeRemoteConnection to use HTTP keep-alive.
- verbose - whether to set verbose logging in the service.
"""
if executable_path != "msedgedriver":
Expand All @@ -83,6 +85,7 @@ def __init__(
service_log_path,
service,
keep_alive,
client_config,
)

def create_options(self) -> Options:
Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/firefox/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
# under the License.

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.remote_connection import RemoteConnection


class FirefoxRemoteConnection(RemoteConnection):
browser_name = DesiredCapabilities.FIREFOX["browserName"]

def __init__(self, remote_server_addr, keep_alive=True, ignore_proxy=False) -> None:
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
def __init__(self, remote_server_addr: str, client_config: ClientConfig = ClientConfig()) -> None:
super().__init__(remote_server_addr, client_config=client_config)

self._commands["GET_CONTEXT"] = ("GET", "/session/$sessionId/moz/context")
self._commands["SET_CONTEXT"] = ("POST", "/session/$sessionId/moz/context")
Expand Down
15 changes: 9 additions & 6 deletions py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from ..remote.client_config import ClientConfig
from .firefox_binary import FirefoxBinary
from .firefox_profile import FirefoxProfile
from .options import Options
from .remote_connection import FirefoxRemoteConnection
from .service import DEFAULT_EXECUTABLE_PATH
from .service import Service

Expand Down Expand Up @@ -58,7 +58,8 @@ def __init__(
service=None,
desired_capabilities=None,
log_path=DEFAULT_LOG_PATH,
keep_alive=True, # Todo: Why is this now unused?
keep_alive=None,
client_config: ClientConfig = ClientConfig(),
) -> None:
"""Starts a new local session of Firefox.
Expand Down Expand Up @@ -106,7 +107,7 @@ def __init__(
:param desired_capabilities: Deprecated: alias of capabilities. In future
versions of this library, this will replace 'capabilities'.
This will make the signature consistent with RemoteWebDriver.
:param keep_alive: Whether to configure remote_connection.RemoteConnection to use
:param keep_alive - Deprecated: Whether to configure remote_connection.RemoteConnection to use
HTTP keep-alive.
"""

Expand Down Expand Up @@ -195,10 +196,12 @@ def __init__(
self.service.path = DriverFinder.get_path(self.service, options)
self.service.start()

executor = FirefoxRemoteConnection(
remote_server_addr=self.service.service_url, ignore_proxy=options._ignore_local_proxy
super().__init__(
command_executor=self.service.service_url,
options=options,
keep_alive=keep_alive,
client_config=client_config,
)
super().__init__(command_executor=executor, options=options, keep_alive=True)

self._is_remote = False

Expand Down
18 changes: 9 additions & 9 deletions py/selenium/webdriver/ie/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

from ..remote.client_config import ClientConfig
from .options import Options
from .service import DEFAULT_EXECUTABLE_PATH
from .service import Service
Expand All @@ -30,7 +31,6 @@
DEFAULT_HOST = None
DEFAULT_LOG_LEVEL = None
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None


class WebDriver(RemoteWebDriver):
Expand All @@ -49,7 +49,8 @@ def __init__(
options: Options = None,
service: Service = None,
desired_capabilities=None,
keep_alive=DEFAULT_KEEP_ALIVE,
keep_alive=None,
client_config: ClientConfig = ClientConfig(),
) -> None:
"""Creates a new instance of the Ie driver.
Expand Down Expand Up @@ -102,12 +103,6 @@ def __init__(
DeprecationWarning,
stacklevel=2,
)
if keep_alive != DEFAULT_KEEP_ALIVE:
warnings.warn(
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
)
else:
keep_alive = True

self.host = host
self.port = port
Expand All @@ -127,7 +122,12 @@ def __init__(
self.iedriver.path = DriverFinder.get_path(self.iedriver, options)
self.iedriver.start()

super().__init__(command_executor=self.iedriver.service_url, options=options, keep_alive=keep_alive)
super().__init__(
command_executor=self.iedriver.service_url,
options=options,
keep_alive=keep_alive,
client_config=client_config,
)
self._is_remote = False

def quit(self) -> None:
Expand Down
Loading

0 comments on commit 8cd2aa8

Please sign in to comment.