Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/chromium/remote_connection.py
1864 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
from typing import Optional
18
19
from selenium.webdriver.remote.client_config import ClientConfig
20
from selenium.webdriver.remote.remote_connection import RemoteConnection
21
22
23
class ChromiumRemoteConnection(RemoteConnection):
24
def __init__(
25
self,
26
remote_server_addr: str,
27
vendor_prefix: str,
28
browser_name: str,
29
keep_alive: bool = True,
30
ignore_proxy: Optional[bool] = False,
31
client_config: Optional[ClientConfig] = None,
32
) -> None:
33
client_config = client_config or ClientConfig(
34
remote_server_addr=remote_server_addr, keep_alive=keep_alive, timeout=120
35
)
36
super().__init__(
37
ignore_proxy=ignore_proxy,
38
client_config=client_config,
39
)
40
self.browser_name = browser_name
41
commands = self._remote_commands(vendor_prefix)
42
for key, value in commands.items():
43
self._commands[key] = value
44
45
def _remote_commands(self, vendor_prefix):
46
remote_commands = {
47
"launchApp": ("POST", "/session/$sessionId/chromium/launch_app"),
48
"setPermissions": ("POST", "/session/$sessionId/permissions"),
49
"setNetworkConditions": ("POST", "/session/$sessionId/chromium/network_conditions"),
50
"getNetworkConditions": ("GET", "/session/$sessionId/chromium/network_conditions"),
51
"deleteNetworkConditions": ("DELETE", "/session/$sessionId/chromium/network_conditions"),
52
"executeCdpCommand": ("POST", f"/session/$sessionId/{vendor_prefix}/cdp/execute"),
53
"getSinks": ("GET", f"/session/$sessionId/{vendor_prefix}/cast/get_sinks"),
54
"getIssueMessage": ("GET", f"/session/$sessionId/{vendor_prefix}/cast/get_issue_message"),
55
"setSinkToUse": ("POST", f"/session/$sessionId/{vendor_prefix}/cast/set_sink_to_use"),
56
"startDesktopMirroring": ("POST", f"/session/$sessionId/{vendor_prefix}/cast/start_desktop_mirroring"),
57
"startTabMirroring": ("POST", f"/session/$sessionId/{vendor_prefix}/cast/start_tab_mirroring"),
58
"stopCasting": ("POST", f"/session/$sessionId/{vendor_prefix}/cast/stop_casting"),
59
}
60
return remote_commands
61
62