Skip to content

Commit 4d87cbb

Browse files
authored
Merge branch 'trunk' into py-bidi-emulation
2 parents 96ce50a + d942194 commit 4d87cbb

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

py/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,19 @@ def clean_driver(request):
443443
except (AttributeError, TypeError):
444444
raise Exception("This test requires a --driver to be specified.")
445445
driver_reference = getattr(webdriver, driver_class)
446+
447+
# conditionally mark tests as expected to fail based on driver
448+
marker = request.node.get_closest_marker(f"xfail_{driver_class.lower()}")
449+
if marker is not None:
450+
if "run" in marker.kwargs:
451+
if marker.kwargs["run"] is False:
452+
pytest.skip()
453+
yield
454+
return
455+
if "raises" in marker.kwargs:
456+
marker.kwargs.pop("raises")
457+
pytest.xfail(**marker.kwargs)
458+
446459
yield driver_reference
447460
if request.node.get_closest_marker("no_driver_after_test"):
448461
driver_reference = None

py/selenium/webdriver/remote/webdriver.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
1817
"""The WebDriver implementation."""
1918

2019
import base64
@@ -76,7 +75,6 @@
7675
from .websocket_connection import WebSocketConnection
7776

7877
cdp = None
79-
devtools = None
8078

8179

8280
def import_cdp():
@@ -269,6 +267,7 @@ def __init__(
269267
self._webextension = None
270268
self._permissions = None
271269
self._emulation = None
270+
self._devtools = None
272271

273272
def __repr__(self):
274273
return f'<{type(self).__module__}.{type(self).__name__} (session="{self.session_id}")>'
@@ -1184,32 +1183,28 @@ def orientation(self, value) -> None:
11841183
raise WebDriverException("You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'")
11851184

11861185
def start_devtools(self):
1187-
global devtools
1188-
if self._websocket_connection:
1189-
return devtools, self._websocket_connection
1186+
global cdp
1187+
import_cdp()
1188+
if self.caps.get("se:cdp"):
1189+
ws_url = self.caps.get("se:cdp")
1190+
version = self.caps.get("se:cdpVersion").split(".")[0]
11901191
else:
1191-
global cdp
1192-
import_cdp()
1193-
1194-
if not devtools:
1195-
if self.caps.get("se:cdp"):
1196-
ws_url = self.caps.get("se:cdp")
1197-
version = self.caps.get("se:cdpVersion").split(".")[0]
1198-
else:
1199-
version, ws_url = self._get_cdp_details()
1200-
1201-
if not ws_url:
1202-
raise WebDriverException("Unable to find url to connect to from capabilities")
1203-
1204-
devtools = cdp.import_devtools(version)
1205-
if self.caps["browserName"].lower() == "firefox":
1206-
raise RuntimeError("CDP support for Firefox has been removed. Please switch to WebDriver BiDi.")
1207-
self._websocket_connection = WebSocketConnection(ws_url)
1208-
targets = self._websocket_connection.execute(devtools.target.get_targets())
1209-
target_id = targets[0].target_id
1210-
session = self._websocket_connection.execute(devtools.target.attach_to_target(target_id, True))
1211-
self._websocket_connection.session_id = session
1212-
return devtools, self._websocket_connection
1192+
version, ws_url = self._get_cdp_details()
1193+
1194+
if not ws_url:
1195+
raise WebDriverException("Unable to find url to connect to from capabilities")
1196+
1197+
self._devtools = cdp.import_devtools(version)
1198+
if self._websocket_connection:
1199+
return self._devtools, self._websocket_connection
1200+
if self.caps["browserName"].lower() == "firefox":
1201+
raise RuntimeError("CDP support for Firefox has been removed. Please switch to WebDriver BiDi.")
1202+
self._websocket_connection = WebSocketConnection(ws_url)
1203+
targets = self._websocket_connection.execute(self._devtools.target.get_targets())
1204+
target_id = targets[0].target_id
1205+
session = self._websocket_connection.execute(self._devtools.target.attach_to_target(target_id, True))
1206+
self._websocket_connection.session_id = session
1207+
return self._devtools, self._websocket_connection
12131208

12141209
@asynccontextmanager
12151210
async def bidi_connection(self):
@@ -1284,9 +1279,8 @@ def browser(self):
12841279

12851280
@property
12861281
def _session(self):
1287-
"""
1288-
Returns the BiDi session object for the current WebDriver session.
1289-
"""
1282+
"""Returns the BiDi session object for the current WebDriver
1283+
session."""
12901284
if not self._websocket_connection:
12911285
self._start_bidi()
12921286

@@ -1297,7 +1291,8 @@ def _session(self):
12971291

12981292
@property
12991293
def browsing_context(self):
1300-
"""Returns a browsing context module object for BiDi browsing context commands.
1294+
"""Returns a browsing context module object for BiDi browsing context
1295+
commands.
13011296
13021297
Returns:
13031298
--------

py/test/selenium/webdriver/common/devtools_tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ def test_check_console_messages(driver, pages, recwarn):
3838
assert console_api_calls[0].args[0].value == "I love cheese"
3939
assert console_api_calls[1].type_ == "error"
4040
assert console_api_calls[1].args[0].value == "I love bread"
41+
42+
43+
@pytest.mark.xfail_safari
44+
@pytest.mark.xfail_firefox
45+
@pytest.mark.xfail_remote
46+
def test_check_start_twice(clean_driver, clean_options):
47+
driver1 = clean_driver(options=clean_options)
48+
devtools1, connection1 = driver1.start_devtools()
49+
driver1.quit()
50+
51+
driver2 = clean_driver(options=clean_options)
52+
devtools2, connection2 = driver2.start_devtools()
53+
driver2.quit()

0 commit comments

Comments
 (0)