Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Require Dart 3.4 and add a dependency on `package:web`.
* Ensure HTTP clients are closed if creating a session fails.
* Update functions that return `List<int>` to return `Uint8List`.

## 3.1.0

Expand Down
5 changes: 3 additions & 2 deletions lib/src/async/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import '../../sync_core.dart' as sync_core;
import '../common/by.dart';
Expand Down Expand Up @@ -203,13 +204,13 @@ class WebDriver implements SearchContext {
_handler.core.parseScreenshotResponse);

/// Take a screenshot of the current page as PNG as list of uint8.
Future<List<int>> captureScreenshotAsList() async {
Future<Uint8List> captureScreenshotAsList() async {
final base64Encoded = captureScreenshotAsBase64();
return base64.decode(await base64Encoded);
}

/// Take a screenshot of the specified element as PNG as list of uint8.
Future<List<int>> captureElementScreenshotAsList(WebElement element) async {
Future<Uint8List> captureElementScreenshotAsList(WebElement element) async {
final base64Encoded = captureElementScreenshotAsBase64(element);
return base64.decode(await base64Encoded);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/zip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Archive {
/// This class represents a file in an archive.
class ArchiveFile {
final String name;
final List<int> content;
final Uint8List content;

ArchiveFile(this.name, this.content);

Expand Down
3 changes: 1 addition & 2 deletions lib/src/request/async_io_request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:convert';
import 'dart:io' show ContentType, HttpClient, HttpClientRequest, HttpHeaders;

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

import '../common/request.dart';
import '../common/request_client.dart';

Expand Down Expand Up @@ -52,7 +51,7 @@ class AsyncIoRequestClient extends AsyncRequestClient {
final response = await httpRequest.close();

return WebDriverResponse(response.statusCode, response.reasonPhrase,
await utf8.decodeStream(response.cast<List<int>>()));
await utf8.decodeStream(response));
} finally {
_lock.release();
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/sync/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import 'dart:convert' show base64;
import 'dart:typed_data';

import '../../async_core.dart' as async_core;
import '../common/by.dart';
Expand Down Expand Up @@ -213,13 +214,13 @@ class WebDriver implements SearchContext {
_handler.core.parseScreenshotResponse);

/// Take a screenshot of the current page as PNG as list of uint8.
List<int> captureScreenshotAsList() {
Uint8List captureScreenshotAsList() {
final base64Encoded = captureScreenshotAsBase64();
return base64.decode(base64Encoded);
}

/// Take a screenshot of the specified element as PNG as list of uint8.
List<int> captureElementScreenshotAsList(WebElement element) {
Uint8List captureElementScreenshotAsList(WebElement element) {
final base64Encoded = captureElementScreenshotAsBase64(element);
return base64.decode(base64Encoded);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/support/firefox_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import 'dart:collection';
import 'dart:convert' show LineSplitter, base64;
import 'dart:convert' show LineSplitter, base64, utf8;
import 'dart:io' as io;

import 'package:path/path.dart' as path;
Expand Down Expand Up @@ -237,11 +237,11 @@ class FirefoxProfile {
}

final prefsJsContent =
prefs.map((option) => option.asPrefString).join('\n').codeUnits;
utf8.encode(prefs.map((option) => option.asPrefString).join('\n'));
archive.addFile(ArchiveFile('prefs.js', prefsJsContent));

final userJsContent =
userPrefs.map((option) => option.asPrefString).join('\n').codeUnits;
utf8.encode(userPrefs.map((option) => option.asPrefString).join('\n'));
archive.addFile(ArchiveFile('user.js', userJsContent));

final zipData = ZipEncoder.encode(archive);
Expand Down
8 changes: 4 additions & 4 deletions lib/support/stdio_stepper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import 'dart:async' show StreamController;
import 'dart:convert' show Encoding, json;
import 'dart:io' show Stdin, exit, stdin, systemEncoding;
import 'dart:typed_data';

import '../src/async/stepper.dart';

Expand Down Expand Up @@ -82,7 +83,7 @@ class LineReader {
static const lf = 10;

bool _crPrevious = false;
final _bytes = <int>[];
final _bytes = BytesBuilder();
final _controller = StreamController<String>.broadcast();

final Encoding encoding;
Expand Down Expand Up @@ -113,10 +114,9 @@ class LineReader {
}
_crPrevious = byte == cr;
if (byte == cr || byte == lf) {
_controller.add(encoding.decode(_bytes));
_bytes.clear();
_controller.add(encoding.decode(_bytes.takeBytes()));
} else {
_bytes.add(byte);
_bytes.addByte(byte);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/configs/async_io_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Future<void> createTestServerAndGoToTestPage(WebDriver driver) async {
request.response
..statusCode = HttpStatus.ok
..headers.set('Content-type', 'text/html');
file.openRead().cast<List<int>>().pipe(request.response);
file.openRead().pipe(request.response);
} else {
request.response
..statusCode = HttpStatus.notFound
Expand Down
2 changes: 1 addition & 1 deletion test/configs/sync_io_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Future<void> _runServer(SendPort send) async {
request.response
..statusCode = HttpStatus.ok
..headers.set('Content-type', 'text/html');
file.openRead().cast<List<int>>().pipe(request.response);
file.openRead().pipe(request.response);
} else {
request.response
..statusCode = HttpStatus.notFound
Expand Down
6 changes: 2 additions & 4 deletions test/support/firefox_profile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ void main() {

final prefs = FirefoxProfile.loadPrefsFile(MockFile(
String.fromCharCodes(
zipArchive.files.firstWhere((f) => f.name == 'user.js').content
as List<int>,
zipArchive.files.firstWhere((f) => f.name == 'user.js').content,
),
));
expect(
Expand Down Expand Up @@ -179,8 +178,7 @@ void main() {
final prefs = FirefoxProfile.loadPrefsFile(
MockFile(
String.fromCharCodes(
zipArchive.files.firstWhere((f) => f.name == 'user.js').content
as List<int>,
zipArchive.files.firstWhere((f) => f.name == 'user.js').content,
),
),
);
Expand Down
6 changes: 3 additions & 3 deletions test/support/zip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ void main() {
var file = zipArchive.files[0];
expect(file.name, 'dart_test.yaml');
expect(file.size, 166);
expect(utf8.decode(file.content as List<int>),
expect(utf8.decode(file.content),
contains('See https://github.com/dart-lang/test/'));

file = zipArchive.files[1];
expect(file.name, 'lib/src/common/spec.dart');
expect(file.size, 209);
expect(utf8.decode(file.content as List<int>),
expect(utf8.decode(file.content),
contains('Defines the WebDriver spec to use'));
});

Expand Down Expand Up @@ -75,7 +75,7 @@ void main() {

group('crc32', () {
test('0 bytes', () {
expect(crc32([]), 0x00000000);
expect(crc32(<int>[]), 0x00000000);
});

test('1 byte', () {
Expand Down