Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to apply new Dart 2.17 features for enums and super() constructor #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 3.0.1-dev

* Updates to apply new Dart 2.17 features for enums and super() constructor.

## 3.0.0

* Stable release for null safety.
Expand Down
8 changes: 3 additions & 5 deletions lib/async_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ Future<WebDriver> createDriver(
handler.session.buildCreateRequest(desired: desired),
handler.session.parseCreateResponse);

if (session.spec != WebDriverSpec.JsonWire &&
session.spec != WebDriverSpec.W3c) {
if (!session.spec.isRecognized()) {
throw 'Unexpected spec: ${session.spec}';
}

Expand All @@ -93,8 +92,7 @@ Future<WebDriver> fromExistingSession(
final session = await client.send(handler.session.buildInfoRequest(sessionId),
(response) => handler.session.parseInfoResponse(response, sessionId));

if (session.spec != WebDriverSpec.JsonWire &&
session.spec != WebDriverSpec.W3c) {
if (!session.spec.isRecognized()) {
throw 'Unexpected spec: ${session.spec}';
}

Expand All @@ -119,7 +117,7 @@ WebDriver fromExistingSessionSync(

capabilities ??= Capabilities.empty;

if (spec != WebDriverSpec.JsonWire && spec != WebDriverSpec.W3c) {
if (!spec.isRecognized()) {
throw 'Unexpected spec: $spec';
}

Expand Down
108 changes: 36 additions & 72 deletions lib/src/common/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class WebDriverException implements Exception {

@override
String toString() =>
'$runtimeType ($statusCode): ' +
(message?.isEmpty != false ? '<no message>' : message!);
'$runtimeType ($statusCode): ${message?.isEmpty != false ? '<no message>' : message!}';

@override
bool operator ==(other) =>
Expand All @@ -26,193 +25,158 @@ class WebDriverException implements Exception {
}

class InvalidArgumentException extends WebDriverException {
const InvalidArgumentException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidArgumentException(super.statusCode, super.message);
}

class InvalidRequestException extends WebDriverException {
const InvalidRequestException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidRequestException(super.statusCode, super.message);
}

class InvalidResponseException extends WebDriverException {
const InvalidResponseException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidResponseException(super.statusCode, super.message);
}

class UnknownException extends WebDriverException {
const UnknownException(int? statusCode, String? message)
: super(statusCode, message);
const UnknownException(super.statusCode, super.message);
}

class NoSuchDriverException extends WebDriverException {
const NoSuchDriverException(int? statusCode, String? message)
: super(statusCode, message);
const NoSuchDriverException(super.statusCode, super.message);
}

class NoSuchElementException extends WebDriverException {
const NoSuchElementException(int? statusCode, String? message)
: super(statusCode, message);
const NoSuchElementException(super.statusCode, super.message);
}

class NoSuchFrameException extends WebDriverException {
const NoSuchFrameException(int? statusCode, String? message)
: super(statusCode, message);
const NoSuchFrameException(super.statusCode, super.message);
}

class UnknownCommandException extends WebDriverException {
const UnknownCommandException(int? statusCode, String? message)
: super(statusCode, message);
const UnknownCommandException(super.statusCode, super.message);
}

class StaleElementReferenceException extends WebDriverException {
const StaleElementReferenceException(int? statusCode, String? message)
: super(statusCode, message);
const StaleElementReferenceException(super.statusCode, super.message);
}

class ElementNotVisibleException extends WebDriverException {
const ElementNotVisibleException(int? statusCode, String? message)
: super(statusCode, message);
const ElementNotVisibleException(super.statusCode, super.message);
}

class InvalidElementStateException extends WebDriverException {
const InvalidElementStateException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidElementStateException(super.statusCode, super.message);
}

class ElementIsNotSelectableException extends WebDriverException {
const ElementIsNotSelectableException(int? statusCode, String? message)
: super(statusCode, message);
const ElementIsNotSelectableException(super.statusCode, super.message);
}

class JavaScriptException extends WebDriverException {
const JavaScriptException(int? statusCode, String? message)
: super(statusCode, message);
const JavaScriptException(super.statusCode, super.message);
}

class XPathLookupException extends WebDriverException {
const XPathLookupException(int? statusCode, String? message)
: super(statusCode, message);
const XPathLookupException(super.statusCode, super.message);
}

class TimeoutException extends WebDriverException {
const TimeoutException(int? statusCode, String? message)
: super(statusCode, message);
const TimeoutException(super.statusCode, super.message);
}

class NoSuchWindowException extends WebDriverException {
const NoSuchWindowException(int? statusCode, String? message)
: super(statusCode, message);
const NoSuchWindowException(super.statusCode, super.message);
}

class InvalidCookieDomainException extends WebDriverException {
const InvalidCookieDomainException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidCookieDomainException(super.statusCode, super.message);
}

class UnableToSetCookieException extends WebDriverException {
const UnableToSetCookieException(int? statusCode, String? message)
: super(statusCode, message);
const UnableToSetCookieException(super.statusCode, super.message);
}

class UnexpectedAlertOpenException extends WebDriverException {
const UnexpectedAlertOpenException(int? statusCode, String? message)
: super(statusCode, message);
const UnexpectedAlertOpenException(super.statusCode, super.message);
}

class NoSuchAlertException extends WebDriverException {
const NoSuchAlertException(int? statusCode, String? message)
: super(statusCode, message);
const NoSuchAlertException(super.statusCode, super.message);
}

class ScriptTimeoutException extends WebDriverException {
const ScriptTimeoutException(int? statusCode, String? message)
: super(statusCode, message);
const ScriptTimeoutException(super.statusCode, super.message);
}

class InvalidElementCoordinatesException extends WebDriverException {
const InvalidElementCoordinatesException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidElementCoordinatesException(super.statusCode, super.message);
}

class IMENotAvailableException extends WebDriverException {
const IMENotAvailableException(int? statusCode, String? message)
: super(statusCode, message);
const IMENotAvailableException(super.statusCode, super.message);
}

class IMEEngineActivationFailedException extends WebDriverException {
const IMEEngineActivationFailedException(int? statusCode, String? message)
: super(statusCode, message);
const IMEEngineActivationFailedException(super.statusCode, super.message);
}

class InvalidSelectorException extends WebDriverException {
const InvalidSelectorException(int? statusCode, String? message)
: super(statusCode, message);
const InvalidSelectorException(super.statusCode, super.message);
}

class SessionNotCreatedException extends WebDriverException {
const SessionNotCreatedException(int? statusCode, String? message)
: super(statusCode, message);
const SessionNotCreatedException(super.statusCode, super.message);
}

class MoveTargetOutOfBoundsException extends WebDriverException {
const MoveTargetOutOfBoundsException(int? statusCode, String? message)
: super(statusCode, message);
const MoveTargetOutOfBoundsException(super.statusCode, super.message);
}

/// The Element Click command could not be completed because the element
/// receiving the events is obscuring the element that was requested clicked.
class ElementClickInterceptedException extends WebDriverException {
const ElementClickInterceptedException(int statusCode, String? message)
: super(statusCode, message);
const ElementClickInterceptedException(super.statusCode, super.message);
}

/// A command could not be completed because the element is not pointer- or
/// keyboard interactable.
class ElementNotInteractableException extends WebDriverException {
const ElementNotInteractableException(int statusCode, String? message)
: super(statusCode, message);
const ElementNotInteractableException(super.statusCode, super.message);
}

/// Navigation caused the user agent to hit a certificate warning, which is
/// usually the result of an expired or invalid TLS certificate.
class InsecureCertificateException extends WebDriverException {
const InsecureCertificateException(int statusCode, String? message)
: super(statusCode, message);
const InsecureCertificateException(super.statusCode, super.message);
}

/// Occurs if the given session id is not in the list of active sessions,
/// meaning the session either does not exist or that it’s not active.
class InvalidSessionIdException extends WebDriverException {
const InvalidSessionIdException(int statusCode, String? message)
: super(statusCode, message);
const InvalidSessionIdException(super.statusCode, super.message);
}

/// No cookie matching the given path name was found amongst the associated
/// cookies of the current browsing context’s active document.
class NoSuchCookieException extends WebDriverException {
const NoSuchCookieException(int statusCode, String? message)
: super(statusCode, message);
const NoSuchCookieException(super.statusCode, super.message);
}

/// A screen capture was made impossible.
class UnableToCaptureScreenException extends WebDriverException {
const UnableToCaptureScreenException(int statusCode, String? message)
: super(statusCode, message);
const UnableToCaptureScreenException(super.statusCode, super.message);
}

/// The requested command matched a known URL but did not match an method for
/// that URL.
class UnknownMethodException extends WebDriverException {
const UnknownMethodException(int statusCode, String? message)
: super(statusCode, message);
const UnknownMethodException(super.statusCode, super.message);
}

/// Indicates that a command that should have executed properly cannot be
/// supported for some reason.
class UnsupportedOperationException extends WebDriverException {
const UnsupportedOperationException(int statusCode, String? message)
: super(statusCode, message);
const UnsupportedOperationException(super.statusCode, super.message);
}

/// Temporary method to emulate the original json wire exception parsing logic.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/common/request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef SyncWebDriverListener = void Function(WebDriverCommandEvent event);
abstract class SyncRequestClient extends RequestClient {
final _commandListeners = <SyncWebDriverListener>[];

SyncRequestClient(Uri prefix) : super(prefix);
SyncRequestClient(super.prefix);

void addEventListener(SyncWebDriverListener listener) {
_commandListeners.add(listener);
Expand Down Expand Up @@ -73,7 +73,7 @@ typedef AsyncWebDriverListener = Future<dynamic> Function(
abstract class AsyncRequestClient extends RequestClient {
final _commandListeners = <AsyncWebDriverListener>[];

AsyncRequestClient(Uri prefix) : super(prefix);
AsyncRequestClient(super.prefix);

void addEventListener(AsyncWebDriverListener listener) {
_commandListeners.add(listener);
Expand Down
9 changes: 8 additions & 1 deletion lib/src/common/spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@

/// Defines the WebDriver spec to use. Auto = try to infer the spec based on
/// the response during session creation.
enum WebDriverSpec { Auto, JsonWire, W3c }
enum WebDriverSpec {
Auto,
JsonWire,
W3c;

bool isRecognized() =>
this == WebDriverSpec.JsonWire || this == WebDriverSpec.W3c;
}
5 changes: 2 additions & 3 deletions lib/src/request/async_io_request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ class AsyncIoRequestClient extends AsyncRequestClient {

final Lock _lock = Lock();

AsyncIoRequestClient(Uri prefix, {Map<String, String> headers = const {}})
: _headers = headers,
super(prefix);
AsyncIoRequestClient(super.prefix, {Map<String, String> headers = const {}})
: _headers = headers;

@override
Future<WebDriverResponse> sendRaw(WebDriverRequest request) async {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/request/async_xhr_request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class AsyncXhrRequestClient extends AsyncRequestClient {
final Lock _lock = Lock();
final Map<String, String> _headers;

AsyncXhrRequestClient(Uri prefix, {Map<String, String> headers = const {}})
: _headers = headers,
super(prefix);
AsyncXhrRequestClient(super.prefix, {Map<String, String> headers = const {}})
: _headers = headers;

@override
Future<WebDriverResponse> sendRaw(WebDriverRequest request) async {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/request/sync_http_request_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import '../common/request_client.dart';
/// Sync request client using sync_http package.
class SyncHttpRequestClient extends SyncRequestClient {
final Map<String, String> _headers;
SyncHttpRequestClient(Uri prefix, {Map<String, String> headers = const {}})
: _headers = headers,
super(prefix);
SyncHttpRequestClient(super.prefix, {Map<String, String> headers = const {}})
: _headers = headers;

@override
WebDriverResponse sendRaw(WebDriverRequest request) {
Expand Down
6 changes: 2 additions & 4 deletions lib/sync_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ WebDriver createDriver(
handler.session.buildCreateRequest(desired: desired),
handler.session.parseCreateResponse);

if (session.spec != WebDriverSpec.JsonWire &&
session.spec != WebDriverSpec.W3c) {
if (!session.spec.isRecognized()) {
throw 'Unexpected spec: ${session.spec}';
}

Expand Down Expand Up @@ -97,8 +96,7 @@ WebDriver fromExistingSession(String sessionId,
(response) => handler.session.parseInfoResponse(response, sessionId));
}

if (session.spec != WebDriverSpec.JsonWire &&
session.spec != WebDriverSpec.W3c) {
if (!session.spec.isRecognized()) {
throw 'Unexpected spec: ${session.spec}';
}

Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: >-
repository: https://github.com/google/webdriver.dart

environment:
sdk: '>=2.14.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
archive: ^3.0.0
Expand All @@ -19,5 +19,6 @@ dependencies:
sync_http: ^0.3.0

dev_dependencies:
lints: ^1.0.0
analyzer: ^4.2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
analyzer: ^4.2.0

lints: ^2.0.0
test: ^1.16.0