14
14
# KIND, either express or implied. See the License for the
15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
-
18
17
"""The WebDriver implementation."""
19
18
20
19
import base64
75
74
from .websocket_connection import WebSocketConnection
76
75
77
76
cdp = None
78
- devtools = None
79
77
80
78
81
79
def import_cdp ():
@@ -267,6 +265,7 @@ def __init__(
267
265
self ._storage = None
268
266
self ._webextension = None
269
267
self ._permissions = None
268
+ self ._devtools = None
270
269
271
270
def __repr__ (self ):
272
271
return f'<{ type (self ).__module__ } .{ type (self ).__name__ } (session="{ self .session_id } ")>'
@@ -1182,32 +1181,28 @@ def orientation(self, value) -> None:
1182
1181
raise WebDriverException ("You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'" )
1183
1182
1184
1183
def start_devtools (self ):
1185
- global devtools
1186
- if self ._websocket_connection :
1187
- return devtools , self ._websocket_connection
1184
+ global cdp
1185
+ import_cdp ()
1186
+ if self .caps .get ("se:cdp" ):
1187
+ ws_url = self .caps .get ("se:cdp" )
1188
+ version = self .caps .get ("se:cdpVersion" ).split ("." )[0 ]
1188
1189
else :
1189
- global cdp
1190
- import_cdp ()
1191
-
1192
- if not devtools :
1193
- if self .caps .get ("se:cdp" ):
1194
- ws_url = self .caps .get ("se:cdp" )
1195
- version = self .caps .get ("se:cdpVersion" ).split ("." )[0 ]
1196
- else :
1197
- version , ws_url = self ._get_cdp_details ()
1198
-
1199
- if not ws_url :
1200
- raise WebDriverException ("Unable to find url to connect to from capabilities" )
1201
-
1202
- devtools = cdp .import_devtools (version )
1203
- if self .caps ["browserName" ].lower () == "firefox" :
1204
- raise RuntimeError ("CDP support for Firefox has been removed. Please switch to WebDriver BiDi." )
1205
- self ._websocket_connection = WebSocketConnection (ws_url )
1206
- targets = self ._websocket_connection .execute (devtools .target .get_targets ())
1207
- target_id = targets [0 ].target_id
1208
- session = self ._websocket_connection .execute (devtools .target .attach_to_target (target_id , True ))
1209
- self ._websocket_connection .session_id = session
1210
- return devtools , self ._websocket_connection
1190
+ version , ws_url = self ._get_cdp_details ()
1191
+
1192
+ if not ws_url :
1193
+ raise WebDriverException ("Unable to find url to connect to from capabilities" )
1194
+
1195
+ self ._devtools = cdp .import_devtools (version )
1196
+ if self ._websocket_connection :
1197
+ return self ._devtools , self ._websocket_connection
1198
+ if self .caps ["browserName" ].lower () == "firefox" :
1199
+ raise RuntimeError ("CDP support for Firefox has been removed. Please switch to WebDriver BiDi." )
1200
+ self ._websocket_connection = WebSocketConnection (ws_url )
1201
+ targets = self ._websocket_connection .execute (self ._devtools .target .get_targets ())
1202
+ target_id = targets [0 ].target_id
1203
+ session = self ._websocket_connection .execute (self ._devtools .target .attach_to_target (target_id , True ))
1204
+ self ._websocket_connection .session_id = session
1205
+ return self ._devtools , self ._websocket_connection
1211
1206
1212
1207
@asynccontextmanager
1213
1208
async def bidi_connection (self ):
@@ -1282,9 +1277,8 @@ def browser(self):
1282
1277
1283
1278
@property
1284
1279
def _session (self ):
1285
- """
1286
- Returns the BiDi session object for the current WebDriver session.
1287
- """
1280
+ """Returns the BiDi session object for the current WebDriver
1281
+ session."""
1288
1282
if not self ._websocket_connection :
1289
1283
self ._start_bidi ()
1290
1284
@@ -1295,7 +1289,8 @@ def _session(self):
1295
1289
1296
1290
@property
1297
1291
def browsing_context (self ):
1298
- """Returns a browsing context module object for BiDi browsing context commands.
1292
+ """Returns a browsing context module object for BiDi browsing context
1293
+ commands.
1299
1294
1300
1295
Returns:
1301
1296
--------
0 commit comments