Skip to content

Commit 8602eaa

Browse files
committed
[py] use ClientConfig for keep_alive, proxy, timeout and certificate path settings
1 parent c545f2c commit 8602eaa

15 files changed

Lines changed: 241 additions & 114 deletions

File tree

py/selenium/webdriver/chrome/webdriver.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2121
from selenium.webdriver.common.driver_finder import DriverFinder
2222

23+
from ..remote.client_config import ClientConfig
2324
from .options import Options
2425
from .service import DEFAULT_EXECUTABLE_PATH
2526
from .service import Service
2627

2728
DEFAULT_PORT = 0
2829
DEFAULT_SERVICE_LOG_PATH = None
29-
DEFAULT_KEEP_ALIVE = None
3030

3131

3232
class WebDriver(ChromiumDriver):
@@ -46,7 +46,8 @@ def __init__(
4646
service_log_path=DEFAULT_SERVICE_LOG_PATH,
4747
chrome_options=None,
4848
service: Service = None,
49-
keep_alive=DEFAULT_KEEP_ALIVE,
49+
keep_alive=None,
50+
client_config: ClientConfig = ClientConfig(),
5051
) -> None:
5152
"""Creates a new instance of the chrome driver. Starts the service and
5253
then creates new instance of chrome driver.
@@ -69,12 +70,6 @@ def __init__(
6970
if chrome_options:
7071
warnings.warn("use options instead of chrome_options", DeprecationWarning, stacklevel=2)
7172
options = chrome_options
72-
if keep_alive != DEFAULT_KEEP_ALIVE:
73-
warnings.warn(
74-
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
75-
)
76-
else:
77-
keep_alive = True
7873
if not options:
7974
options = self.create_options()
8075
if not service:
@@ -91,6 +86,7 @@ def __init__(
9186
service_log_path,
9287
service,
9388
keep_alive,
89+
client_config,
9490
)
9591

9692
def create_options(self) -> Options:

py/selenium/webdriver/chromium/remote_connection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
1817

18+
from selenium.webdriver.remote.client_config import ClientConfig
1919
from selenium.webdriver.remote.remote_connection import RemoteConnection
2020

2121

@@ -25,10 +25,9 @@ def __init__(
2525
remote_server_addr: str,
2626
vendor_prefix: str,
2727
browser_name: str,
28-
keep_alive: bool = True,
29-
ignore_proxy: typing.Optional[bool] = False,
28+
client_config: ClientConfig = ClientConfig(),
3029
) -> None:
31-
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
30+
super().__init__(remote_server_addr, client_config=client_config)
3231
self.browser_name = browser_name
3332
self._commands["launchApp"] = ("POST", "/session/$sessionId/chromium/launch_app")
3433
self._commands["setPermissions"] = ("POST", "/session/$sessionId/permissions")

py/selenium/webdriver/chromium/webdriver.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import warnings
1919

2020
from selenium.webdriver.chrome.options import Options as ChromeOptions
21-
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
2221
from selenium.webdriver.common.options import BaseOptions
2322
from selenium.webdriver.common.service import Service
2423
from selenium.webdriver.edge.options import Options as EdgeOptions
24+
from selenium.webdriver.remote.client_config import ClientConfig
2525
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2626

2727
DEFAULT_PORT = 0
2828
DEFAULT_SERVICE_LOG_PATH = None
29-
DEFAULT_KEEP_ALIVE = None
3029

3130

3231
class ChromiumDriver(RemoteWebDriver):
@@ -43,7 +42,8 @@ def __init__(
4342
desired_capabilities=None,
4443
service_log_path=DEFAULT_SERVICE_LOG_PATH,
4544
service: Service = None,
46-
keep_alive=DEFAULT_KEEP_ALIVE,
45+
keep_alive=None,
46+
client_config: ClientConfig = ClientConfig(),
4747
) -> None:
4848
"""Creates a new WebDriver instance of the ChromiumDriver. Starts the
4949
service and then creates new WebDriver instance of ChromiumDriver.
@@ -74,34 +74,29 @@ def __init__(
7474
DeprecationWarning,
7575
stacklevel=2,
7676
)
77-
if keep_alive != DEFAULT_KEEP_ALIVE and type(self) == __class__:
78-
warnings.warn(
79-
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
80-
)
81-
else:
82-
keep_alive = True
8377

8478
self.vendor_prefix = vendor_prefix
8579

86-
_ignore_proxy = None
8780
if not options:
8881
options = self.create_options()
8982

9083
if desired_capabilities:
9184
for key, value in desired_capabilities.items():
9285
options.set_capability(key, value)
9386

94-
if options._ignore_local_proxy:
95-
_ignore_proxy = options._ignore_local_proxy
96-
9787
if not service:
9888
raise AttributeError("service cannot be None")
9989

10090
self.service = service
10191
self.service.start()
10292

10393
try:
104-
super().__init__(command_executor=self.service.service_url, options=options, keep_alive=keep_alive,)
94+
super().__init__(
95+
command_executor=self.service.service_url,
96+
options=options,
97+
keep_alive=keep_alive,
98+
client_config=client_config,
99+
)
105100
except Exception:
106101
self.quit()
107102
raise

py/selenium/webdriver/common/options.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import typing
18+
import warnings
1819
from abc import ABCMeta
1920
from abc import abstractmethod
2021

@@ -30,6 +31,7 @@ def __init__(self) -> None:
3031
self._caps = self.default_capabilities
3132
self.set_capability("pageLoadStrategy", "normal")
3233
self.mobile_options = None
34+
self._ignore_local_proxy = False
3335

3436
@property
3537
def capabilities(self):
@@ -223,12 +225,22 @@ def to_capabilities(self):
223225
def default_capabilities(self):
224226
"""Return minimal capabilities necessary as a dictionary."""
225227

228+
def ignore_local_proxy_environment_variables(self) -> None:
229+
"""By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
230+
being picked up and used."""
231+
warnings.warn(
232+
"setting ignore proxy in Options has been deprecated, "
233+
"set ProxyType.DIRECT in ClientConfig and pass to WebDriver constructor instead",
234+
DeprecationWarning,
235+
stacklevel=2,
236+
)
237+
self._ignore_local_proxy = True
238+
226239

227240
class ArgOptions(BaseOptions):
228241
def __init__(self) -> None:
229242
super().__init__()
230243
self._arguments = []
231-
self._ignore_local_proxy = False
232244

233245
@property
234246
def arguments(self):
@@ -248,11 +260,6 @@ def add_argument(self, argument):
248260
else:
249261
raise ValueError("argument can not be null")
250262

251-
def ignore_local_proxy_environment_variables(self) -> None:
252-
"""By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
253-
being picked up and used."""
254-
self._ignore_local_proxy = True
255-
256263
def to_capabilities(self):
257264
return self._caps
258265

py/selenium/webdriver/edge/webdriver.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2121
from selenium.webdriver.common.driver_finder import DriverFinder
2222

23+
from ..remote.client_config import ClientConfig
2324
from .options import Options
2425
from .service import DEFAULT_EXECUTABLE_PATH
2526
from .service import Service
@@ -44,7 +45,8 @@ def __init__(
4445
capabilities=None,
4546
service_log_path=DEFAULT_SERVICE_LOG_PATH,
4647
service: Service = None,
47-
keep_alive=False,
48+
keep_alive=None,
49+
client_config: ClientConfig = ClientConfig(),
4850
verbose=False, # Todo: Why is this now unused?
4951
) -> None:
5052
"""Creates a new instance of the edge driver. Starts the service and
@@ -59,7 +61,7 @@ def __init__(
5961
capabilities only, such as "proxy" or "loggingPref".
6062
- service_log_path - Deprecated: Where to log information from the driver.
6163
- service - Service object for handling the browser driver if you need to pass extra details
62-
- keep_alive - Whether to configure EdgeRemoteConnection to use HTTP keep-alive.
64+
- keep_alive - Deprecated: Whether to configure EdgeRemoteConnection to use HTTP keep-alive.
6365
- verbose - whether to set verbose logging in the service.
6466
"""
6567
if executable_path != "msedgedriver":
@@ -83,6 +85,7 @@ def __init__(
8385
service_log_path,
8486
service,
8587
keep_alive,
88+
client_config,
8689
)
8790

8891
def create_options(self) -> Options:

py/selenium/webdriver/firefox/remote_connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
# under the License.
1717

1818
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
19+
from selenium.webdriver.remote.client_config import ClientConfig
1920
from selenium.webdriver.remote.remote_connection import RemoteConnection
2021

2122

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

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

2829
self._commands["GET_CONTEXT"] = ("GET", "/session/$sessionId/moz/context")
2930
self._commands["SET_CONTEXT"] = ("POST", "/session/$sessionId/moz/context")

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
from selenium.webdriver.common.driver_finder import DriverFinder
2828
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2929

30+
from ..remote.client_config import ClientConfig
3031
from .firefox_binary import FirefoxBinary
3132
from .firefox_profile import FirefoxProfile
3233
from .options import Options
33-
from .remote_connection import FirefoxRemoteConnection
3434
from .service import DEFAULT_EXECUTABLE_PATH
3535
from .service import Service
3636

@@ -58,7 +58,8 @@ def __init__(
5858
service=None,
5959
desired_capabilities=None,
6060
log_path=DEFAULT_LOG_PATH,
61-
keep_alive=True, # Todo: Why is this now unused?
61+
keep_alive=None,
62+
client_config: ClientConfig = ClientConfig(),
6263
) -> None:
6364
"""Starts a new local session of Firefox.
6465
@@ -106,7 +107,7 @@ def __init__(
106107
:param desired_capabilities: Deprecated: alias of capabilities. In future
107108
versions of this library, this will replace 'capabilities'.
108109
This will make the signature consistent with RemoteWebDriver.
109-
:param keep_alive: Whether to configure remote_connection.RemoteConnection to use
110+
:param keep_alive - Deprecated: Whether to configure remote_connection.RemoteConnection to use
110111
HTTP keep-alive.
111112
"""
112113

@@ -195,7 +196,12 @@ def __init__(
195196
self.service.path = DriverFinder.get_path(self.service, options)
196197
self.service.start()
197198

198-
super().__init__(command_executor=self.service.service_url, options=options, keep_alive=keep_alive)
199+
super().__init__(
200+
command_executor=self.service.service_url,
201+
options=options,
202+
keep_alive=keep_alive,
203+
client_config=client_config,
204+
)
199205

200206
self._is_remote = False
201207

py/selenium/webdriver/ie/webdriver.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from selenium.webdriver.common.driver_finder import DriverFinder
2222
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2323

24+
from ..remote.client_config import ClientConfig
2425
from .options import Options
2526
from .service import DEFAULT_EXECUTABLE_PATH
2627
from .service import Service
@@ -30,7 +31,6 @@
3031
DEFAULT_HOST = None
3132
DEFAULT_LOG_LEVEL = None
3233
DEFAULT_SERVICE_LOG_PATH = None
33-
DEFAULT_KEEP_ALIVE = None
3434

3535

3636
class WebDriver(RemoteWebDriver):
@@ -49,7 +49,8 @@ def __init__(
4949
options: Options = None,
5050
service: Service = None,
5151
desired_capabilities=None,
52-
keep_alive=DEFAULT_KEEP_ALIVE,
52+
keep_alive=None,
53+
client_config: ClientConfig = ClientConfig(),
5354
) -> None:
5455
"""Creates a new instance of the Ie driver.
5556
@@ -102,12 +103,6 @@ def __init__(
102103
DeprecationWarning,
103104
stacklevel=2,
104105
)
105-
if keep_alive != DEFAULT_KEEP_ALIVE:
106-
warnings.warn(
107-
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
108-
)
109-
else:
110-
keep_alive = True
111106

112107
self.host = host
113108
self.port = port
@@ -127,7 +122,12 @@ def __init__(
127122
self.iedriver.path = DriverFinder.get_path(self.iedriver, options)
128123
self.iedriver.start()
129124

130-
super().__init__(command_executor=self.iedriver.service_url, options=options, keep_alive=keep_alive)
125+
super().__init__(
126+
command_executor=self.iedriver.service_url,
127+
options=options,
128+
keep_alive=keep_alive,
129+
client_config=client_config,
130+
)
131131
self._is_remote = False
132132

133133
def quit(self) -> None:

0 commit comments

Comments
 (0)