Skip to content

Commit d7a2a12

Browse files
authored
Merge branch 'trunk' into edge_network_bidi_tests
2 parents fc77efd + 00b3c5e commit d7a2a12

File tree

5 files changed

+115
-38
lines changed

5 files changed

+115
-38
lines changed

common/repositories.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ js_library(
199199

200200
http_archive(
201201
name = "linux_chrome",
202-
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.95/linux64/chrome-linux64.zip",
203-
sha256 = "bf406b6de491825f7db9d4b635b9ba56a8e8b6e60fac130382f561bb62f12d7e",
202+
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.97/linux64/chrome-linux64.zip",
203+
sha256 = "dca0a86931162c85fbd054cc037519fcf855dca912c7fd2dc2e2e48fb7d59961",
204204
build_file_content = """
205205
load("@aspect_rules_js//js:defs.bzl", "js_library")
206206
package(default_visibility = ["//visibility:public"])
@@ -221,8 +221,8 @@ js_library(
221221

222222
http_archive(
223223
name = "mac_chrome",
224-
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.95/mac-x64/chrome-mac-x64.zip",
225-
sha256 = "949f46e9fd58b96a3c5fc436dde9b4aa04e683258a83867d6f0ec8abb58537ec",
224+
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.97/mac-x64/chrome-mac-x64.zip",
225+
sha256 = "53880ac98a04490c647d1a5649eb0ebd8001741bb17501df34908e8826fe516f",
226226
strip_prefix = "chrome-mac-x64",
227227
patch_cmds = [
228228
"mv 'Google Chrome for Testing.app' Chrome.app",
@@ -243,8 +243,8 @@ js_library(
243243

244244
http_archive(
245245
name = "linux_chromedriver",
246-
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.95/linux64/chromedriver-linux64.zip",
247-
sha256 = "64e1f8bf5bbb94983dff82874b79f45039e5463323e8912d38b83a1277f9e272",
246+
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.97/linux64/chromedriver-linux64.zip",
247+
sha256 = "12a0e6e8035b3671a7a884e33949f1f5154d2d2ca68593715851f6f3a5e836ec",
248248
strip_prefix = "chromedriver-linux64",
249249
build_file_content = """
250250
load("@aspect_rules_js//js:defs.bzl", "js_library")
@@ -261,8 +261,8 @@ js_library(
261261

262262
http_archive(
263263
name = "mac_chromedriver",
264-
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.95/mac-x64/chromedriver-mac-x64.zip",
265-
sha256 = "9bf330af1a080d6bbda6dc80cf064de371941e65b826cfc5a589628d1c78aef9",
264+
url = "https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.97/mac-x64/chromedriver-mac-x64.zip",
265+
sha256 = "2eedf6406ca4e9f11a4c196ce56e8d25c15dc68bd8ea07c7da8423d2327e9aa1",
266266
strip_prefix = "chromedriver-mac-x64",
267267
build_file_content = """
268268
load("@aspect_rules_js//js:defs.bzl", "js_library")

py/selenium/webdriver/common/bidi/script.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
from dataclasses import dataclass
1919
from typing import List
2020

21-
from .session import session_subscribe
22-
from .session import session_unsubscribe
21+
from .session import Session
2322

2423

2524
class Script:
@@ -43,12 +42,14 @@ def remove_console_message_handler(self, id):
4342

4443
def _subscribe_to_log_entries(self):
4544
if not self.log_entry_subscribed:
46-
self.conn.execute(session_subscribe(LogEntryAdded.event_class))
45+
session = Session(self.conn)
46+
self.conn.execute(session.subscribe(LogEntryAdded.event_class))
4747
self.log_entry_subscribed = True
4848

4949
def _unsubscribe_from_log_entries(self):
5050
if self.log_entry_subscribed and LogEntryAdded.event_class not in self.conn.callbacks:
51-
self.conn.execute(session_unsubscribe(LogEntryAdded.event_class))
51+
session = Session(self.conn)
52+
self.conn.execute(session.unsubscribe(LogEntryAdded.event_class))
5253
self.log_entry_subscribed = False
5354

5455
def _handle_log_entry(self, type, handler):

py/selenium/webdriver/common/bidi/session.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,43 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from selenium.webdriver.common.bidi.common import command_builder
1819

19-
def session_subscribe(*events, browsing_contexts=None):
20-
cmd_dict = {
21-
"method": "session.subscribe",
22-
"params": {
20+
21+
class Session:
22+
23+
def __init__(self, conn):
24+
self.conn = conn
25+
26+
def subscribe(self, *events, browsing_contexts=None):
27+
params = {
2328
"events": events,
24-
},
25-
}
26-
if browsing_contexts is None:
27-
browsing_contexts = []
28-
if browsing_contexts:
29-
cmd_dict["params"]["browsingContexts"] = browsing_contexts
30-
_ = yield cmd_dict
31-
return None
32-
33-
34-
def session_unsubscribe(*events, browsing_contexts=None):
35-
cmd_dict = {
36-
"method": "session.unsubscribe",
37-
"params": {
29+
}
30+
if browsing_contexts is None:
31+
browsing_contexts = []
32+
if browsing_contexts:
33+
params["browsingContexts"] = browsing_contexts
34+
return command_builder("session.subscribe", params)
35+
36+
def unsubscribe(self, *events, browsing_contexts=None):
37+
params = {
3838
"events": events,
39-
},
40-
}
41-
if browsing_contexts is None:
42-
browsing_contexts = []
43-
if browsing_contexts:
44-
cmd_dict["params"]["browsingContexts"] = browsing_contexts
45-
_ = yield cmd_dict
46-
return None
39+
}
40+
if browsing_contexts is None:
41+
browsing_contexts = []
42+
if browsing_contexts:
43+
params["browsingContexts"] = browsing_contexts
44+
return command_builder("session.unsubscribe", params)
45+
46+
def status(self):
47+
"""
48+
The session.status command returns information about the remote end's readiness
49+
to create new sessions and may include implementation-specific metadata.
50+
51+
Returns
52+
-------
53+
dict
54+
Dictionary containing the ready state (bool), message (str) and metadata
55+
"""
56+
cmd = command_builder("session.status", {})
57+
return self.conn.execute(cmd)

py/selenium/webdriver/remote/webdriver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from selenium.webdriver.common.bidi.browser import Browser
4747
from selenium.webdriver.common.bidi.network import Network
4848
from selenium.webdriver.common.bidi.script import Script
49+
from selenium.webdriver.common.bidi.session import Session
4950
from selenium.webdriver.common.by import By
5051
from selenium.webdriver.common.options import ArgOptions
5152
from selenium.webdriver.common.options import BaseOptions
@@ -262,6 +263,7 @@ def __init__(
262263
self._script = None
263264
self._network = None
264265
self._browser = None
266+
self._bidi_session = None
265267

266268
def __repr__(self):
267269
return f'<{type(self).__module__}.{type(self).__name__} (session="{self.session_id}")>'
@@ -1277,6 +1279,19 @@ def browser(self):
12771279

12781280
return self._browser
12791281

1282+
@property
1283+
def _session(self):
1284+
"""
1285+
Returns the BiDi session object for the current WebDriver session.
1286+
"""
1287+
if not self._websocket_connection:
1288+
self._start_bidi()
1289+
1290+
if self._bidi_session is None:
1291+
self._bidi_session = Session(self._websocket_connection)
1292+
1293+
return self._bidi_session
1294+
12801295
def _get_cdp_details(self):
12811296
import json
12821297

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
18+
import pytest
19+
20+
from selenium.webdriver.common.window import WindowTypes
21+
22+
23+
@pytest.mark.xfail_safari
24+
def test_session_status(driver):
25+
result = driver._session.status()
26+
assert result is not None
27+
assert "ready" in result
28+
assert "message" in result
29+
assert isinstance(result["ready"], bool)
30+
assert isinstance(result["message"], str)
31+
32+
33+
@pytest.mark.xfail_safari
34+
def test_session_status_not_closed_with_one_window(driver):
35+
# initial session status
36+
initial_status = driver._session.status()
37+
assert initial_status is not None
38+
39+
# Open new window and tab
40+
driver.switch_to.new_window(WindowTypes.WINDOW)
41+
driver.switch_to.new_window(WindowTypes.TAB)
42+
43+
# Close one window
44+
driver.close()
45+
46+
# Session should still be active
47+
status_after_closing = driver._session.status()
48+
assert status_after_closing is not None
49+
assert "ready" in status_after_closing
50+
assert "message" in status_after_closing

0 commit comments

Comments
 (0)