Skip to content

Commit a423f49

Browse files
authored
Merge branch 'trunk' into rb_add_support_for_chrome_beta
2 parents 054de22 + 18f424b commit a423f49

File tree

16 files changed

+147
-20
lines changed

16 files changed

+147
-20
lines changed

common/src/web/service-worker.js

Whitespace-only changes.

common/src/web/service_worker.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Service Worker Test Page</title>
5+
<script>
6+
if (navigator.serviceWorker) {
7+
navigator.serviceWorker.register("/service-worker.js", { scope: "/" })
8+
.then(() => navigator.serviceWorker.ready)
9+
.then(() => console.debug("[Companion]", "Service worker registered!"));
10+
}
11+
</script>
12+
</head>
13+
<body>
14+
<h1>This page loads a service worker</h1>
15+
</body>
16+
</html>

dotnet/src/webdriver/BiDi/BiDi.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
using System;
2121
using System.Threading.Tasks;
2222
using OpenQA.Selenium.BiDi.Communication;
23-
using OpenQA.Selenium.BiDi.Communication.Transport;
2423

2524
namespace OpenQA.Selenium.BiDi;
2625

2726
public class BiDi : IAsyncDisposable
2827
{
29-
private readonly ITransport _transport;
3028
private readonly Broker _broker;
3129

3230
private readonly Lazy<Modules.Session.SessionModule> _sessionModule;
@@ -42,8 +40,7 @@ internal BiDi(string url)
4240
{
4341
var uri = new Uri(url);
4442

45-
_transport = new WebSocketTransport(new Uri(url));
46-
_broker = new Broker(this, _transport);
43+
_broker = new Broker(this, uri);
4744

4845
_sessionModule = new Lazy<Modules.Session.SessionModule>(() => new Modules.Session.SessionModule(_broker));
4946
_browsingContextModule = new Lazy<Modules.BrowsingContext.BrowsingContextModule>(() => new Modules.BrowsingContext.BrowsingContextModule(_broker));
@@ -83,10 +80,14 @@ public Task EndAsync(Modules.Session.EndOptions? options = null)
8380
return SessionModule.EndAsync(options);
8481
}
8582

86-
public async ValueTask DisposeAsync()
83+
public virtual async ValueTask DisposeAsyncCore()
8784
{
8885
await _broker.DisposeAsync().ConfigureAwait(false);
86+
}
8987

90-
_transport?.Dispose();
88+
public async ValueTask DisposeAsync()
89+
{
90+
await DisposeAsyncCore();
91+
GC.SuppressFinalize(this);
9192
}
9293
}

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class Broker : IAsyncDisposable
5454

5555
private readonly BiDiJsonSerializerContext _jsonSerializerContext;
5656

57-
internal Broker(BiDi bidi, ITransport transport)
57+
internal Broker(BiDi bidi, Uri url)
5858
{
5959
_bidi = bidi;
60-
_transport = transport;
60+
_transport = new WebSocketTransport(url);
6161

6262
var jsonSerializerOptions = new JsonSerializerOptions
6363
{
@@ -298,7 +298,7 @@ public async Task UnsubscribeAsync(Modules.Session.Subscription subscription, Ev
298298
}
299299
}
300300

301-
public async ValueTask DisposeAsync()
301+
public virtual async ValueTask DisposeAsyncCore()
302302
{
303303
_pendingEvents.CompleteAdding();
304304

@@ -308,5 +308,13 @@ public async ValueTask DisposeAsync()
308308
{
309309
await _eventEmitterTask.ConfigureAwait(false);
310310
}
311+
312+
_transport.Dispose();
313+
}
314+
315+
public async ValueTask DisposeAsync()
316+
{
317+
await DisposeAsyncCore();
318+
GC.SuppressFinalize(this);
311319
}
312320
}

rb/lib/selenium/webdriver/common/driver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def quit
188188
bridge.quit
189189
ensure
190190
@service_manager&.stop
191-
@devtools&.close
191+
@devtools&.each_value(&:close)
192192
end
193193

194194
#

rb/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ module HasDevTools
2727
# @return [DevTools]
2828
#
2929

30-
def devtools
31-
@devtools ||= begin
30+
def devtools(target_type: 'page')
31+
@devtools ||= {}
32+
@devtools[target_type] ||= begin
3233
require 'selenium/devtools'
3334
Selenium::DevTools.version ||= devtools_version
3435
Selenium::DevTools.load_version
35-
Selenium::WebDriver::DevTools.new(url: devtools_url)
36+
Selenium::WebDriver::DevTools.new(url: devtools_url, target_type: target_type)
3637
end
3738
end
3839
end # HasDevTools

rb/lib/selenium/webdriver/devtools.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class DevTools
2828
autoload :Request, 'selenium/webdriver/devtools/request'
2929
autoload :Response, 'selenium/webdriver/devtools/response'
3030

31-
def initialize(url:)
31+
def initialize(url:, target_type:)
3232
@ws = WebSocketConnection.new(url: url)
3333
@session_id = nil
34-
start_session
34+
start_session(target_type: target_type)
3535
end
3636

3737
def close
@@ -81,10 +81,12 @@ def respond_to_missing?(method, *_args)
8181

8282
private
8383

84-
def start_session
84+
def start_session(target_type:)
8585
targets = target.get_targets.dig('result', 'targetInfos')
86-
page_target = targets.find { |target| target['type'] == 'page' }
87-
session = target.attach_to_target(target_id: page_target['targetId'], flatten: true)
86+
found_target = targets.find { |target| target['type'] == target_type }
87+
raise Error::WebDriverError, "Target type '#{target_type}' not found" unless found_target
88+
89+
session = target.attach_to_target(target_id: found_target['targetId'], flatten: true)
8890
@session_id = session.dig('result', 'sessionId')
8991
end
9092

rb/spec/integration/selenium/webdriver/devtools_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ module WebDriver
5454
}.to raise_error(RuntimeError, 'This is fine!')
5555
end
5656

57+
describe '#target' do
58+
it 'target type defaults to page' do
59+
driver.devtools.page.navigate(url: url_for('xhtmlTest.html'))
60+
expect(driver.devtools.target.get_target_info.dig('result', 'targetInfo', 'type')).to eq 'page'
61+
end
62+
63+
it 'target type is service_worker' do
64+
driver.devtools.page.navigate(url: url_for('service_worker.html'))
65+
sleep 0.5 # wait for service worker to register
66+
target = driver.devtools(target_type: 'service_worker').target
67+
expect(target.get_target_info.dig('result', 'targetInfo', 'type')).to eq 'service_worker'
68+
end
69+
70+
it 'throws an error for unknown target type' do
71+
driver.devtools.page.navigate(url: url_for('xhtmlTest.html'))
72+
expect { driver.devtools(target_type: 'unknown') }
73+
.to raise_error(Selenium::WebDriver::Error::WebDriverError, "Target type 'unknown' not found")
74+
end
75+
end
76+
5777
describe '#register' do
5878
let(:username) { SpecSupport::RackServer::TestApp::BASIC_AUTH_CREDENTIALS.first }
5979
let(:password) { SpecSupport::RackServer::TestApp::BASIC_AUTH_CREDENTIALS.last }

rust/src/chrome.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use reqwest::Client;
3535
use serde::{Deserialize, Serialize};
3636
use std::collections::HashMap;
3737
use std::option::Option;
38-
use std::path::PathBuf;
38+
use std::path::{Path, PathBuf};
3939
use std::sync::mpsc;
4040
use std::sync::mpsc::{Receiver, Sender};
4141

@@ -50,6 +50,8 @@ const CFT_MACOS_APP_NAME: &str =
5050
"Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing";
5151
const MIN_CHROME_VERSION_CFT: i32 = 113;
5252
const MIN_CHROMEDRIVER_VERSION_CFT: i32 = 115;
53+
const CHROMIUM_SNAP_LINK: &str = "/snap/bin/chromium";
54+
const CHROMIUM_SNAP_BINARY: &str = "/snap/chromium/current/usr/lib/chromium-browser/chrome";
5355

5456
pub struct ChromeManager {
5557
pub browser_name: &'static str,
@@ -587,6 +589,15 @@ impl SeleniumManager for ChromeManager {
587589
fn set_download_browser(&mut self, download_browser: bool) {
588590
self.download_browser = download_browser;
589591
}
592+
593+
fn is_snap(&self, browser_path: &str) -> bool {
594+
LINUX.is(self.get_os())
595+
&& (browser_path.eq(CHROMIUM_SNAP_LINK) || browser_path.eq(CHROMIUM_SNAP_BINARY))
596+
}
597+
598+
fn get_snap_path(&self) -> Option<PathBuf> {
599+
Some(Path::new(CHROMIUM_SNAP_BINARY).to_path_buf())
600+
}
590601
}
591602

592603
#[derive(Serialize, Deserialize)]

rust/src/edge.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ impl SeleniumManager for EdgeManager {
551551
fn set_download_browser(&mut self, download_browser: bool) {
552552
self.download_browser = download_browser;
553553
}
554+
555+
fn is_snap(&self, _browser_path: &str) -> bool {
556+
false
557+
}
558+
559+
fn get_snap_path(&self) -> Option<PathBuf> {
560+
None
561+
}
554562
}
555563

556564
#[derive(Serialize, Deserialize, Debug)]

0 commit comments

Comments
 (0)