Skip to content

Commit 0efb41b

Browse files
authored
Migrate async_html from dart:html to package:web (#315)
* Migrate async_html from dart:html to package:web * Update CI to test with Dart 3.4
1 parent 6085884 commit 0efb41b

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
fail-fast: false
4141
matrix:
4242
os: [ubuntu-latest]
43-
sdk: [3.1, stable, dev]
43+
sdk: [3.4, stable, dev]
4444
steps:
4545
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
4646
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
@@ -66,7 +66,7 @@ jobs:
6666
fail-fast: false
6767
matrix:
6868
os: [ubuntu-latest]
69-
sdk: [3.1, stable, dev]
69+
sdk: [3.4, stable, dev]
7070
steps:
7171
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
7272
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.2.0-wip
2+
3+
* Require Dart 3.4 and add a dependency on `package:web`.
4+
15
## 3.1.0
26

37
* Add a `reason` argument to `Clock.waitFor`.

lib/async_html.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final Uri defaultUri = Uri.parse('http://127.0.0.1:4444/wd/hub/');
2727

2828
/// Creates a new async WebDriver using [AsyncXhrRequestClient].
2929
///
30-
/// This will bring in dependency on `dart:html`.
30+
/// This will bring in a dependency on the Dart web platform.
3131
/// Note: WebDriver endpoints will be constructed using [resolve] against
3232
/// [uri]. Therefore, if [uri] does not end with a trailing slash, the
3333
/// last path component will be dropped.
@@ -45,7 +45,7 @@ Future<core.WebDriver> createDriver(
4545
/// Creates an async WebDriver from existing session using
4646
/// [AsyncXhrRequestClient].
4747
///
48-
/// This will bring in dependency on `dart:html`.
48+
/// This will bring in a dependency on the Dart web platform.
4949
/// Note: WebDriver endpoints will be constructed using [resolve] against
5050
/// [uri]. Therefore, if [uri] does not end with a trailing slash, the
5151
/// last path component will be dropped.
@@ -61,7 +61,7 @@ Future<core.WebDriver> fromExistingSession(String sessionId,
6161
/// [capabilities]) has to be given. Because otherwise, making a call to
6262
/// WebDriver server will make this function async.
6363
///
64-
/// This will bring in dependency on `dart:html`.
64+
/// This will bring in a dependency on the Dart web platform.
6565
/// Note: WebDriver endpoints will be constructed using [resolve] against
6666
/// [uri]. Therefore, if [uri] does not end with a trailing slash, the
6767
/// last path component will be dropped.

lib/src/request/async_xhr_request_client.dart

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import 'dart:async';
2-
import 'dart:html';
2+
3+
import 'package:web/web.dart' as web;
34

45
import '../../support/async.dart';
56

67
import '../common/request.dart';
78
import '../common/request_client.dart';
89

9-
/// Async request client using dart:html package.
10+
/// Async request client using `dart:js_interop` through `package:web`.
1011
///
1112
/// On the low level, it's using XMLHttpRequest object (XHR).
1213
class AsyncXhrRequestClient extends AsyncRequestClient {
@@ -20,33 +21,31 @@ class AsyncXhrRequestClient extends AsyncRequestClient {
2021
Future<WebDriverResponse> sendRaw(WebDriverRequest request) async {
2122
await _lock.acquire();
2223

23-
final headers = {
24-
'Accept': 'application/json',
25-
};
26-
27-
headers.addAll(_headers);
28-
if (request.body != null && request.body!.isNotEmpty) {
29-
headers['Content-Type'] ??= 'application/json';
30-
}
31-
32-
HttpRequest httpRequest;
33-
24+
web.XMLHttpRequest httpRequest;
3425
try {
35-
httpRequest = await HttpRequest.request(resolve(request.uri!).toString(),
36-
method: request.method!.name,
37-
requestHeaders: headers,
38-
sendData: request.body,
39-
mimeType: 'application/json');
40-
} on ProgressEvent catch (e) {
41-
httpRequest = e.target as HttpRequest;
26+
// ignore: deprecated_member_use
27+
httpRequest = await web.HttpRequest.request(
28+
resolve(request.uri!).toString(),
29+
method: request.method!.name,
30+
requestHeaders: {
31+
..._headers,
32+
'Accept': 'application/json',
33+
if (request.body?.isNotEmpty ?? false)
34+
'Content-Type': 'application/json',
35+
},
36+
sendData: request.body,
37+
mimeType: 'application/json',
38+
);
39+
} on web.ProgressEvent catch (e) {
40+
httpRequest = e.target as web.XMLHttpRequest;
4241
} finally {
4342
_lock.release();
4443
}
4544

4645
return WebDriverResponse(
4746
httpRequest.status,
4847
httpRequest.statusText,
49-
httpRequest.response as String?,
48+
httpRequest.responseText,
5049
);
5150
}
5251

pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
name: webdriver
2-
version: 3.1.0
2+
version: 3.2.0-wip
33
description: >-
44
Provides WebDriver bindings for Dart. Supports WebDriver JSON interface and
55
W3C spec. Requires the use of WebDriver remote server.
66
repository: https://github.com/google/webdriver.dart
77

88
environment:
9-
sdk: ^3.1.0
9+
sdk: ^3.4.0
1010

1111
dependencies:
1212
matcher: ^0.12.10
1313
path: ^1.8.0
1414
stack_trace: ^1.10.0
1515
sync_http: ^0.3.0
16+
web: ^1.1.0
1617

1718
dev_dependencies:
1819
archive: ^4.0.2

0 commit comments

Comments
 (0)