Skip to content

Commit 1faeb8b

Browse files
authored
Merge branch 'trunk' into stop_driver
2 parents aef3785 + 0de6351 commit 1faeb8b

File tree

11 files changed

+73
-28
lines changed

11 files changed

+73
-28
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ body:
3535
label: Debugging Logs
3636
placeholder: |
3737
Note: the stack trace should be in the explanation section above
38-
Instructions for enabling logging can be found in the link below
38+
Instructions for enabling and referencing logs can be found in the links below
3939
render: logs
4040
- type: markdown
4141
id: link
4242
attributes:
4343
value: |
4444
**Read our [logging documentation](https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/)**
45+
**Link to a [gist](https://gist.github.com/) if logs are too long**
4546
 
4647
4748
## Help us Address Your Issue Faster!

.github/workflows/ci-ruby.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ jobs:
2222
cache-key: rb-docs
2323
run: bazel run //rb:docs
2424

25-
lint:
26-
name: Lint
27-
needs: build
28-
uses: ./.github/workflows/bazel.yml
29-
with:
30-
name: Lint
31-
cache-key: rb-lint
32-
run: bazel test //rb:lint
33-
3425
unit-tests:
3526
name: Unit Tests
3627
needs: build

.skipped-tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@
5757
-//rb/spec/integration/selenium/webdriver:element-chrome-bidi
5858
-//rb/spec/integration/selenium/webdriver:element-chrome-remote
5959
-//rb/spec/integration/selenium/webdriver:action_builder-firefox-beta-remote
60+
-//rb:lint

dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class WebSocketTransport(Uri _uri) : ITransport, IDisposable
3535
private readonly ArraySegment<byte> _receiveBuffer = new(new byte[1024 * 8]);
3636

3737
private readonly SemaphoreSlim _socketSendSemaphoreSlim = new(1, 1);
38+
private readonly MemoryStream _sharedMemoryStream = new();
3839

3940
public async Task ConnectAsync(CancellationToken cancellationToken)
4041
{
@@ -43,21 +44,19 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
4344

4445
public async Task<byte[]> ReceiveAsync(CancellationToken cancellationToken)
4546
{
46-
using var ms = new MemoryStream();
47+
_sharedMemoryStream.SetLength(0);
4748

4849
WebSocketReceiveResult result;
4950

5051
do
5152
{
5253
result = await _webSocket.ReceiveAsync(_receiveBuffer, cancellationToken).ConfigureAwait(false);
5354

54-
await ms.WriteAsync(_receiveBuffer.Array!, _receiveBuffer.Offset, result.Count, cancellationToken).ConfigureAwait(false);
55+
await _sharedMemoryStream.WriteAsync(_receiveBuffer.Array!, _receiveBuffer.Offset, result.Count, cancellationToken).ConfigureAwait(false);
5556
}
5657
while (!result.EndOfMessage);
5758

58-
ms.Seek(0, SeekOrigin.Begin);
59-
60-
byte[] data = ms.ToArray();
59+
byte[] data = _sharedMemoryStream.ToArray();
6160

6261
if (_logger.IsEnabled(LogEventLevel.Trace))
6362
{
@@ -69,10 +68,12 @@ public async Task<byte[]> ReceiveAsync(CancellationToken cancellationToken)
6968

7069
public async Task SendAsync(byte[] data, CancellationToken cancellationToken)
7170
{
72-
await _socketSendSemaphoreSlim.WaitAsync(cancellationToken);
71+
var semaphoreTask = _socketSendSemaphoreSlim.WaitAsync(cancellationToken);
7372

7473
try
7574
{
75+
await semaphoreTask.ConfigureAwait(false);
76+
7677
if (_logger.IsEnabled(LogEventLevel.Trace))
7778
{
7879
_logger.Trace($"BiDi SND --> {Encoding.UTF8.GetString(data)}");
@@ -89,5 +90,7 @@ public async Task SendAsync(byte[] data, CancellationToken cancellationToken)
8990
public void Dispose()
9091
{
9192
_webSocket.Dispose();
93+
_sharedMemoryStream.Dispose();
94+
_socketSendSemaphoreSlim.Dispose();
9295
}
9396
}

py/selenium/webdriver/remote/webdriver.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
"""The WebDriver implementation."""
19+
1820
import base64
1921
import contextlib
2022
import copy
@@ -343,9 +345,14 @@ def start_session(self, capabilities: dict) -> None:
343345
"""
344346

345347
caps = _create_caps(capabilities)
346-
response = self.execute(Command.NEW_SESSION, caps)["value"]
347-
self.session_id = response.get("sessionId")
348-
self.caps = response.get("capabilities")
348+
try:
349+
response = self.execute(Command.NEW_SESSION, caps)["value"]
350+
self.session_id = response.get("sessionId")
351+
self.caps = response.get("capabilities")
352+
except Exception:
353+
if self.service is not None:
354+
self.service.stop()
355+
raise
349356

350357
def _wrap_value(self, value):
351358
if isinstance(value, dict):

py/test/selenium/webdriver/chrome/chrome_service_tests.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import os
1819
import subprocess
1920
import time
2021
from unittest.mock import patch
2122

2223
import pytest
2324

24-
from selenium.common.exceptions import WebDriverException
25+
from selenium.common.exceptions import SessionNotCreatedException
26+
from selenium.webdriver.chrome.options import Options
2527
from selenium.webdriver.chrome.service import Service
2628

2729

28-
@pytest.mark.xfail_chrome(raises=WebDriverException)
2930
@pytest.mark.no_driver_after_test
3031
def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None:
3132
log_file = "chromedriver.log"
@@ -107,6 +108,17 @@ def test_log_output_null_default(driver, capfd) -> None:
107108
driver.quit()
108109

109110

111+
@pytest.mark.no_driver_after_test
112+
def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None:
113+
options = Options()
114+
options.add_argument("--user-data-dir=/no/such/location")
115+
service = Service()
116+
with pytest.raises(SessionNotCreatedException):
117+
clean_driver(options=options, service=service)
118+
assert not service.is_connectable()
119+
assert service.process.poll() is not None
120+
121+
110122
@pytest.fixture
111123
def service():
112124
return Service()

py/test/selenium/webdriver/common/api_example_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ def test_is_element_displayed(driver, pages):
239239
assert not not_visible
240240

241241

242-
@pytest.mark.xfail_chrome
242+
@pytest.mark.xfail_edge
243+
@pytest.mark.xfail_firefox(reason="https://github.com/mozilla/geckodriver/issues/2224")
243244
@pytest.mark.xfail_safari
244245
def test_move_window_position(driver, pages):
245246
pages.load("blank.html")

py/test/selenium/webdriver/common/window_tests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_should_get_the_size_of_the_current_window(driver):
4545
assert size.get("height") > 0
4646

4747

48+
@pytest.mark.xfail_edge
4849
def test_should_set_the_size_of_the_current_window(driver):
4950
size = driver.get_window_size()
5051

@@ -57,13 +58,15 @@ def test_should_set_the_size_of_the_current_window(driver):
5758
assert new_size.get("height") == target_height
5859

5960

60-
@pytest.mark.xfail_chrome
6161
def test_should_get_the_position_of_the_current_window(driver):
6262
position = driver.get_window_position()
6363
assert position.get("x") >= 0
6464
assert position.get("y") >= 0
6565

6666

67+
@pytest.mark.xfail_chrome
68+
@pytest.mark.xfail_edge
69+
@pytest.mark.xfail_firefox(reason="https://github.com/mozilla/geckodriver/issues/2224")
6770
def test_should_set_the_position_of_the_current_window(driver):
6871
position = driver.get_window_position()
6972

@@ -81,7 +84,6 @@ def test_should_set_the_position_of_the_current_window(driver):
8184

8285

8386
@pytest.mark.xfail_safari(raises=WebDriverException, reason="Get Window Rect command not implemented")
84-
@pytest.mark.xfail_chrome
8587
def test_should_get_the_rect_of_the_current_window(driver):
8688
rect = driver.get_window_rect()
8789
assert rect.get("x") >= 0
@@ -90,6 +92,8 @@ def test_should_get_the_rect_of_the_current_window(driver):
9092
assert rect.get("height") >= 0
9193

9294

95+
@pytest.mark.xfail_edge
96+
@pytest.mark.xfail_firefox(reason="https://github.com/mozilla/geckodriver/issues/2224")
9397
@pytest.mark.xfail_safari(raises=WebDriverException, reason="Get Window Rect command not implemented")
9498
def test_should_set_the_rect_of_the_current_window(driver):
9599
rect = driver.get_window_rect()

py/test/selenium/webdriver/edge/edge_service_tests.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import os
1819
import subprocess
1920
import time
2021
from unittest.mock import patch
2122

2223
import pytest
2324

24-
from selenium.common.exceptions import WebDriverException
25+
from selenium.common.exceptions import SessionNotCreatedException
26+
from selenium.webdriver.edge.options import Options
2527
from selenium.webdriver.edge.service import Service
2628

2729

28-
@pytest.mark.xfail_edge(raises=WebDriverException)
2930
@pytest.mark.no_driver_after_test
3031
def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None:
3132
log_file = "msedgedriver.log"
@@ -107,6 +108,17 @@ def test_log_output_null_default(driver, capfd) -> None:
107108
driver.quit()
108109

109110

111+
@pytest.mark.no_driver_after_test
112+
def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None:
113+
options = Options()
114+
options.add_argument("--user-data-dir=/no/such/location")
115+
service = Service()
116+
with pytest.raises(SessionNotCreatedException):
117+
clean_driver(options=options, service=service)
118+
assert not service.is_connectable()
119+
assert service.process.poll() is not None
120+
121+
110122
@pytest.fixture
111123
def service():
112124
return Service()

py/test/selenium/webdriver/firefox/firefox_service_tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import os
1819
import subprocess
1920
from unittest.mock import patch
2021

2122
import pytest
2223

24+
from selenium.common.exceptions import SessionNotCreatedException
2325
from selenium.webdriver import Firefox
26+
from selenium.webdriver.firefox.options import Options
2427
from selenium.webdriver.firefox.service import Service
2528

2629

@@ -61,6 +64,16 @@ def test_log_output_as_stdout(capfd) -> None:
6164
driver.quit()
6265

6366

67+
def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None:
68+
options = Options()
69+
options.add_argument("-profile=/no/such/location")
70+
service = Service()
71+
with pytest.raises(SessionNotCreatedException):
72+
clean_driver(options=options, service=service)
73+
assert not service.is_connectable()
74+
assert service.process.poll() is not None
75+
76+
6477
@pytest.fixture
6578
def service():
6679
return Service()

rb/.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ Style/OptionalBooleanParameter:
147147
Enabled: false
148148

149149
Lint/Debugger:
150-
IgnoredMethods:
151-
- save_screenshot
150+
Exclude:
151+
- 'lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb'
152152

153153
Lint/UselessConstantScoping:
154154
Enabled: false

0 commit comments

Comments
 (0)