[webdriver] Tighten up types.
Using Future<void> if possible, avoiding dynamic calls.
PiperOrigin-RevId: 234037559
diff --git a/lib/src/async/alert.dart b/lib/src/async/alert.dart
index 1835166..18b9190 100644
--- a/lib/src/async/alert.dart
+++ b/lib/src/async/alert.dart
@@ -32,21 +32,21 @@
/// object was created).
///
/// Throws [NoSuchAlertException] if there isn't currently an alert.
- Future accept() => _client.send(
+ Future<void> accept() => _client.send(
_handler.alert.buildAcceptRequest(), _handler.alert.parseAcceptResponse);
/// Dismisses the currently displayed alert (may not be the alert for which
/// this object was created).
///
/// Throws [NoSuchAlertException] if there isn't currently an alert.
- Future dismiss() => _client.send(_handler.alert.buildDismissRequest(),
+ Future<void> dismiss() => _client.send(_handler.alert.buildDismissRequest(),
_handler.alert.parseDismissResponse);
/// Sends keys to the currently displayed alert (may not be the alert for
/// which this object was created).
///
/// Throws [NoSuchAlertException] if there isn't currently an alert
- Future sendKeys(String keysToSend) => _client.send(
+ Future<void> sendKeys(String keysToSend) => _client.send(
_handler.alert.buildSendTextRequest(keysToSend),
_handler.alert.parseSendTextResponse);
diff --git a/lib/src/async/cookies.dart b/lib/src/async/cookies.dart
index c355143..082e36b 100644
--- a/lib/src/async/cookies.dart
+++ b/lib/src/async/cookies.dart
@@ -25,17 +25,17 @@
Cookies(this._client, this._handler);
/// Sets a cookie.
- Future add(Cookie cookie) => _client.send(
+ Future<void> add(Cookie cookie) => _client.send(
_handler.cookies.buildAddCookieRequest(cookie),
_handler.cookies.parseAddCookieResponse);
/// Deletes the cookie with the given [name].
- Future delete(String name) => _client.send(
+ Future<void> delete(String name) => _client.send(
_handler.cookies.buildDeleteCookieRequest(name),
_handler.cookies.parseDeleteCookieResponse);
/// Deletes all cookies visible to the current page.
- Future deleteAll() => _client.send(
+ Future<void> deleteAll() => _client.send(
_handler.cookies.buildDeleteAllCookiesRequest(),
_handler.cookies.parseDeleteAllCookiesResponse);
diff --git a/lib/src/async/keyboard.dart b/lib/src/async/keyboard.dart
index 694bdaa..673fa05 100644
--- a/lib/src/async/keyboard.dart
+++ b/lib/src/async/keyboard.dart
@@ -81,12 +81,12 @@
Keyboard(this._client, this._handler);
/// Simulate pressing many keys at once as a 'chord'.
- Future sendChord(Iterable<String> chordToSend) => _client.send(
+ Future<void> sendChord(Iterable<String> chordToSend) => _client.send(
_handler.keyboard.buildSendChordRequest(chordToSend),
_handler.keyboard.parseSendChordResponse);
/// Send [keysToSend] to the active element.
- Future sendKeys(String keysToSend) => _client.send(
+ Future<void> sendKeys(String keysToSend) => _client.send(
_handler.keyboard.buildSendKeysRequest(keysToSend),
_handler.keyboard.parseSendKeysResponse);
diff --git a/lib/src/async/mouse.dart b/lib/src/async/mouse.dart
index 8286adc..4529e49 100644
--- a/lib/src/async/mouse.dart
+++ b/lib/src/async/mouse.dart
@@ -26,22 +26,23 @@
Mouse(this._client, this._handler);
/// Click any mouse button (at the coordinates set by the last moveTo).
- Future click([MouseButton button = MouseButton.primary]) => _client.send(
- _handler.mouse.buildClickRequest(button),
- _handler.mouse.parseClickResponse);
+ Future<void> click([MouseButton button = MouseButton.primary]) =>
+ _client.send(_handler.mouse.buildClickRequest(button),
+ _handler.mouse.parseClickResponse);
/// Click and hold any mouse button (at the coordinates set by the last
/// moveTo command).
- Future down([MouseButton button = MouseButton.primary]) => _client.send(
+ Future<void> down([MouseButton button = MouseButton.primary]) => _client.send(
_handler.mouse.buildDownRequest(button),
_handler.mouse.parseDownResponse);
/// Releases the mouse button previously held (where the mouse is currently at).
- Future up([MouseButton button = MouseButton.primary]) => _client.send(
+ Future<void> up([MouseButton button = MouseButton.primary]) => _client.send(
_handler.mouse.buildUpRequest(button), _handler.mouse.parseUpResponse);
/// Double-clicks at the current mouse coordinates (set by moveTo).
- Future doubleClick() => _client.send(_handler.mouse.buildDoubleClickRequest(),
+ Future<void> doubleClick() => _client.send(
+ _handler.mouse.buildDoubleClickRequest(),
_handler.mouse.parseDoubleClickResponse);
/// Move the mouse.
@@ -59,7 +60,7 @@
///
/// Special notes for W3C, if the destination is out of the current viewport,
/// an 'MoveTargetOutOfBounds' exception will be thrown.
- Future moveTo(
+ Future<void> moveTo(
{WebElement element,
int xOffset,
int yOffset,
diff --git a/lib/src/async/target_locator.dart b/lib/src/async/target_locator.dart
index 6798b06..ac87651 100644
--- a/lib/src/async/target_locator.dart
+++ b/lib/src/async/target_locator.dart
@@ -35,7 +35,7 @@
/// not provided: selects the first frame on the page or the main document.
///
/// Throws [NoSuchFrameException] if the specified frame can't be found.
- Future frame([/* int | WebElement | String */ frame]) async {
+ Future<void> frame([/* int | WebElement | String */ frame]) async {
if (frame == null || frame is int) {
await _client.send(_handler.frame.buildSwitchByIdRequest(frame),
_handler.frame.parseSwitchByIdResponse);
@@ -52,7 +52,7 @@
}
/// Changes focus to the parent frame of the current one.
- Future parentFrame() => _client.send(
+ Future<void> parentFrame() => _client.send(
_handler.frame.buildSwitchToParentRequest(),
_handler.frame.parseSwitchToParentResponse);
@@ -60,7 +60,7 @@
/// given name/handle.
///
/// Throws [NoSuchWindowException] if the specified window can't be found.
- Future window(Window window) => window.setAsActive();
+ Future<void> window(Window window) => window.setAsActive();
/// Switches to the currently active modal dialog for this particular driver
/// instance.
diff --git a/lib/src/async/timeouts.dart b/lib/src/async/timeouts.dart
index 08b2cd4..be1f416 100644
--- a/lib/src/async/timeouts.dart
+++ b/lib/src/async/timeouts.dart
@@ -24,17 +24,17 @@
Timeouts(this._client, this._handler);
/// Sets the script timeout.
- Future setScriptTimeout(Duration duration) => _client.send(
+ Future<void> setScriptTimeout(Duration duration) => _client.send(
_handler.timeouts.buildSetScriptTimeoutRequest(duration),
_handler.timeouts.parseSetScriptTimeoutResponse);
/// Sets the implicit timeout.
- Future setImplicitTimeout(Duration duration) => _client.send(
+ Future<void> setImplicitTimeout(Duration duration) => _client.send(
_handler.timeouts.buildSetImplicitTimeoutRequest(duration),
_handler.timeouts.parseSetImplicitTimeoutResponse);
/// Sets the page load timeout.
- Future setPageLoadTimeout(Duration duration) => _client.send(
+ Future<void> setPageLoadTimeout(Duration duration) => _client.send(
_handler.timeouts.buildSetPageLoadTimeoutRequest(duration),
_handler.timeouts.parseSetPageLoadTimeoutResponse);
diff --git a/lib/src/async/web_driver.dart b/lib/src/async/web_driver.dart
index ea31f01..45a5fb6 100644
--- a/lib/src/async/web_driver.dart
+++ b/lib/src/async/web_driver.dart
@@ -76,21 +76,23 @@
_handler.core.parseCurrentUrlResponse);
/// Navigates to the specified url
- Future get(/* Uri | String */ url) => _client.send(
+ Future<void> get(/* Uri | String */ url) => _client.send(
_handler.navigation
.buildNavigateToRequest((url is Uri) ? url.toString() : url),
_handler.navigation.parseNavigateToResponse);
/// Navigates forwards in the browser history, if possible.
- Future forward() => _client.send(_handler.navigation.buildForwardRequest(),
+ Future<void> forward() => _client.send(
+ _handler.navigation.buildForwardRequest(),
_handler.navigation.parseForwardResponse);
/// Navigates backwards in the browser history, if possible.
- Future back() => _client.send(_handler.navigation.buildBackRequest(),
+ Future<void> back() => _client.send(_handler.navigation.buildBackRequest(),
_handler.navigation.parseBackResponse);
/// Refreshes the current page.
- Future refresh() => _client.send(_handler.navigation.buildRefreshRequest(),
+ Future<void> refresh() => _client.send(
+ _handler.navigation.buildRefreshRequest(),
_handler.navigation.parseRefreshResponse);
/// The title of the current page.
@@ -125,7 +127,7 @@
_handler.core.parsePageSourceResponse);
/// Quits the browser.
- Future quit({bool closeSession = true}) => closeSession
+ Future<void> quit({bool closeSession = true}) => closeSession
? _client.send(_handler.core.buildDeleteSessionRequest(),
_handler.core.parseDeleteSessionResponse)
: Future.value();
@@ -226,7 +228,7 @@
/// Arguments may be any JSON-able object. WebElements will be converted to
/// the corresponding DOM element. Likewise, any DOM Elements in the script
/// result will be converted to WebElements.
- Future executeAsync(String script, List args) => _client.send(
+ Future<dynamic> executeAsync(String script, List args) => _client.send(
_handler.core.buildExecuteAsyncRequest(script, args),
(response) => _handler.core.parseExecuteAsyncResponse(
response, (elementId) => getElement(elementId, this, 'javascript')));
@@ -243,7 +245,7 @@
/// Arguments may be any JSON-able object. WebElements will be converted to
/// the corresponding DOM element. Likewise, any DOM Elements in the script
/// result will be converted to WebElements.
- Future execute(String script, List args) => _client.send(
+ Future<dynamic> execute(String script, List args) => _client.send(
_handler.core.buildExecuteRequest(script, args),
(response) => _handler.core.parseExecuteResponse(
response, (elementId) => getElement(elementId, this, 'javascript')));
diff --git a/lib/src/async/web_element.dart b/lib/src/async/web_element.dart
index c1cb9a5..198b3cc 100644
--- a/lib/src/async/web_element.dart
+++ b/lib/src/async/web_element.dart
@@ -47,16 +47,16 @@
[this.context, this.locator, this.index]);
/// Click on this element.
- Future click() => _client.send(_handler.element.buildClickRequest(id),
+ Future<void> click() => _client.send(_handler.element.buildClickRequest(id),
_handler.element.parseClickResponse);
/// Send [keysToSend] to this element.
- Future sendKeys(String keysToSend) => _client.send(
+ Future<void> sendKeys(String keysToSend) => _client.send(
_handler.element.buildSendKeysRequest(id, keysToSend),
_handler.element.parseSendKeysResponse);
/// Clear the content of a text element.
- Future clear() => _client.send(_handler.element.buildClearRequest(id),
+ Future<void> clear() => _client.send(_handler.element.buildClearRequest(id),
_handler.element.parseClearResponse);
/// Is this radio button/checkbox selected?
diff --git a/lib/src/async/window.dart b/lib/src/async/window.dart
index 31452aa..60cb0ac 100644
--- a/lib/src/async/window.dart
+++ b/lib/src/async/window.dart
@@ -26,7 +26,7 @@
Window(this._client, this._handler, this.id);
/// Sets the window as active.
- Future setAsActive() => _client.send(
+ Future<void> setAsActive() => _client.send(
_handler.window.buildSetActiveRequest(id),
_handler.window.parseSetActiveResponse);
@@ -59,17 +59,17 @@
}
/// Sets the window location.
- Future setLocation(Point<int> point) => _client.send(
+ Future<void> setLocation(Point<int> point) => _client.send(
_handler.window.buildSetLocationRequest(point),
_handler.window.parseSetLocationResponse);
/// Sets the window size.
- Future setSize(Rectangle<int> size) => _client.send(
+ Future<void> setSize(Rectangle<int> size) => _client.send(
_handler.window.buildSetSizeRequest(size),
_handler.window.parseSetSizeResponse);
/// The location and size of the window.
- Future setRect(Rectangle<int> rect) async {
+ Future<void> setRect(Rectangle<int> rect) async {
try {
await _client.send(_handler.window.buildSetRectRequest(rect),
_handler.window.parseSetRectResponse);
@@ -83,13 +83,15 @@
}
/// Maximizes the window.
- Future maximize() => _client.send(_handler.window.buildMaximizeRequest(),
+ Future<void> maximize() => _client.send(
+ _handler.window.buildMaximizeRequest(),
_handler.window.parseMaximizeResponse);
/// Minimizes the window.
///
/// Unsupported in JsonWire WebDriver.
- Future minimize() => _client.send(_handler.window.buildMinimizeRequest(),
+ Future<void> minimize() => _client.send(
+ _handler.window.buildMinimizeRequest(),
_handler.window.parseMinimizeResponse);
/// Closes the window.
diff --git a/lib/src/common/capabilities.dart b/lib/src/common/capabilities.dart
index 5abca67..88d31b6 100644
--- a/lib/src/common/capabilities.dart
+++ b/lib/src/common/capabilities.dart
@@ -55,16 +55,13 @@
@Deprecated('This is not supported in the W3C spec.')
static const String enableProfiling = 'webdriver.logging.profiler.enabled';
- static Map<String, dynamic> get chrome =>
- Map.from(empty)..[browserName] = Browser.chrome;
+ static Map<String, dynamic> get chrome => {browserName: Browser.chrome};
- static Map<String, dynamic> get firefox =>
- Map.from(empty)..[browserName] = Browser.firefox;
+ static Map<String, dynamic> get firefox => {browserName: Browser.firefox};
- static Map<String, dynamic> get android =>
- Map.from(empty)..[browserName] = Browser.android;
+ static Map<String, dynamic> get android => {browserName: Browser.android};
- static Map<String, dynamic> get empty => <String, dynamic>{};
+ static Map<String, dynamic> get empty => {};
}
/// Browser name constants.
diff --git a/lib/src/common/command_event.dart b/lib/src/common/command_event.dart
index 1fde2e1..fcea0a7 100644
--- a/lib/src/common/command_event.dart
+++ b/lib/src/common/command_event.dart
@@ -15,12 +15,12 @@
class WebDriverCommandEvent {
final String method;
final String endPoint;
- final params;
+ final dynamic params;
final StackTrace stackTrace;
final DateTime startTime;
final DateTime endTime;
- final exception;
- final result;
+ final dynamic exception;
+ final dynamic result;
WebDriverCommandEvent(
{this.method,
diff --git a/lib/src/common/exception.dart b/lib/src/common/exception.dart
index 28c3fec..8e94956 100644
--- a/lib/src/common/exception.dart
+++ b/lib/src/common/exception.dart
@@ -16,6 +16,7 @@
@override
bool operator ==(other) =>
+ other is WebDriverException &&
other.runtimeType == runtimeType &&
other.statusCode == statusCode &&
other.message == message;
@@ -25,183 +26,192 @@
}
class InvalidArgumentException extends WebDriverException {
- const InvalidArgumentException(statusCode, message)
+ const InvalidArgumentException(int statusCode, String message)
: super(statusCode, message);
}
class InvalidRequestException extends WebDriverException {
- const InvalidRequestException(statusCode, message)
+ const InvalidRequestException(int statusCode, String message)
: super(statusCode, message);
}
class InvalidResponseException extends WebDriverException {
- const InvalidResponseException(statusCode, message)
+ const InvalidResponseException(int statusCode, String message)
: super(statusCode, message);
}
class UnknownException extends WebDriverException {
- const UnknownException(statusCode, message) : super(statusCode, message);
+ const UnknownException(int statusCode, String message)
+ : super(statusCode, message);
}
class NoSuchDriverException extends WebDriverException {
- const NoSuchDriverException(statusCode, message) : super(statusCode, message);
+ const NoSuchDriverException(int statusCode, String message)
+ : super(statusCode, message);
}
class NoSuchElementException extends WebDriverException {
- const NoSuchElementException(statusCode, message)
+ const NoSuchElementException(int statusCode, String message)
: super(statusCode, message);
}
class NoSuchFrameException extends WebDriverException {
- const NoSuchFrameException(statusCode, message) : super(statusCode, message);
+ const NoSuchFrameException(int statusCode, String message)
+ : super(statusCode, message);
}
class UnknownCommandException extends WebDriverException {
- const UnknownCommandException(statusCode, message)
+ const UnknownCommandException(int statusCode, String message)
: super(statusCode, message);
}
class StaleElementReferenceException extends WebDriverException {
- const StaleElementReferenceException(statusCode, message)
+ const StaleElementReferenceException(int statusCode, String message)
: super(statusCode, message);
}
class ElementNotVisibleException extends WebDriverException {
- const ElementNotVisibleException(statusCode, message)
+ const ElementNotVisibleException(int statusCode, String message)
: super(statusCode, message);
}
class InvalidElementStateException extends WebDriverException {
- const InvalidElementStateException(statusCode, message)
+ const InvalidElementStateException(int statusCode, String message)
: super(statusCode, message);
}
class ElementIsNotSelectableException extends WebDriverException {
- const ElementIsNotSelectableException(statusCode, message)
+ const ElementIsNotSelectableException(int statusCode, String message)
: super(statusCode, message);
}
class JavaScriptException extends WebDriverException {
- const JavaScriptException(statusCode, message) : super(statusCode, message);
+ const JavaScriptException(int statusCode, String message)
+ : super(statusCode, message);
}
class XPathLookupException extends WebDriverException {
- const XPathLookupException(statusCode, message) : super(statusCode, message);
+ const XPathLookupException(int statusCode, String message)
+ : super(statusCode, message);
}
class TimeoutException extends WebDriverException {
- const TimeoutException(statusCode, message) : super(statusCode, message);
+ const TimeoutException(int statusCode, String message)
+ : super(statusCode, message);
}
class NoSuchWindowException extends WebDriverException {
- const NoSuchWindowException(statusCode, message) : super(statusCode, message);
+ const NoSuchWindowException(int statusCode, String message)
+ : super(statusCode, message);
}
class InvalidCookieDomainException extends WebDriverException {
- const InvalidCookieDomainException(statusCode, message)
+ const InvalidCookieDomainException(int statusCode, String message)
: super(statusCode, message);
}
class UnableToSetCookieException extends WebDriverException {
- const UnableToSetCookieException(statusCode, message)
+ const UnableToSetCookieException(int statusCode, String message)
: super(statusCode, message);
}
class UnexpectedAlertOpenException extends WebDriverException {
- const UnexpectedAlertOpenException(statusCode, message)
+ const UnexpectedAlertOpenException(int statusCode, String message)
: super(statusCode, message);
}
class NoSuchAlertException extends WebDriverException {
- const NoSuchAlertException(statusCode, message) : super(statusCode, message);
+ const NoSuchAlertException(int statusCode, String message)
+ : super(statusCode, message);
}
class ScriptTimeoutException extends WebDriverException {
- const ScriptTimeoutException(statusCode, message)
+ const ScriptTimeoutException(int statusCode, String message)
: super(statusCode, message);
}
class InvalidElementCoordinatesException extends WebDriverException {
- const InvalidElementCoordinatesException(statusCode, message)
+ const InvalidElementCoordinatesException(int statusCode, String message)
: super(statusCode, message);
}
class IMENotAvailableException extends WebDriverException {
- const IMENotAvailableException(statusCode, message)
+ const IMENotAvailableException(int statusCode, String message)
: super(statusCode, message);
}
class IMEEngineActivationFailedException extends WebDriverException {
- const IMEEngineActivationFailedException(statusCode, message)
+ const IMEEngineActivationFailedException(int statusCode, String message)
: super(statusCode, message);
}
class InvalidSelectorException extends WebDriverException {
- const InvalidSelectorException(statusCode, message)
+ const InvalidSelectorException(int statusCode, String message)
: super(statusCode, message);
}
class SessionNotCreatedException extends WebDriverException {
- const SessionNotCreatedException(statusCode, message)
+ const SessionNotCreatedException(int statusCode, String message)
: super(statusCode, message);
}
class MoveTargetOutOfBoundsException extends WebDriverException {
- const MoveTargetOutOfBoundsException(statusCode, message)
+ const MoveTargetOutOfBoundsException(int statusCode, String message)
: super(statusCode, 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(statusCode, message)
+ const ElementClickInterceptedException(int statusCode, String message)
: super(statusCode, message);
}
/// A command could not be completed because the element is not pointer- or
/// keyboard interactable.
class ElementNotInteractableException extends WebDriverException {
- const ElementNotInteractableException(statusCode, message)
+ const ElementNotInteractableException(int statusCode, String message)
: super(statusCode, 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(statusCode, message)
+ const InsecureCertificateException(int statusCode, String message)
: super(statusCode, 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(statusCode, message)
+ const InvalidSessionIdException(int statusCode, String message)
: super(statusCode, 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(statusCode, message) : super(statusCode, message);
+ const NoSuchCookieException(int statusCode, String message)
+ : super(statusCode, message);
}
/// A screen capture was made impossible.
class UnableToCaptureScreenException extends WebDriverException {
- const UnableToCaptureScreenException(statusCode, message)
+ const UnableToCaptureScreenException(int statusCode, String message)
: super(statusCode, message);
}
/// The requested command matched a known URL but did not match an method for
/// that URL.
class UnknownMethodException extends WebDriverException {
- const UnknownMethodException(statusCode, message)
+ const UnknownMethodException(int statusCode, String message)
: super(statusCode, message);
}
/// Indicates that a command that should have executed properly cannot be
/// supported for some reason.
class UnsupportedOperationException extends WebDriverException {
- const UnsupportedOperationException(statusCode, message)
+ const UnsupportedOperationException(int statusCode, String message)
: super(statusCode, message);
}
@@ -209,8 +219,8 @@
WebDriverException getExceptionFromJsonWireResponse(
{int httpStatusCode, String httpReasonPhrase, dynamic jsonResp}) {
if (jsonResp is Map) {
- final status = jsonResp['status'];
- final message = jsonResp['value']['message'];
+ var status = jsonResp['status'] as int;
+ var message = jsonResp['value']['message'] as String;
switch (status) {
case 0:
@@ -267,7 +277,7 @@
}
}
if (jsonResp != null) {
- return InvalidRequestException(httpStatusCode, jsonResp);
+ return InvalidRequestException(httpStatusCode, jsonResp as String);
}
return InvalidRequestException(httpStatusCode, httpReasonPhrase);
}
diff --git a/lib/src/handler/json_wire/mouse.dart b/lib/src/handler/json_wire/mouse.dart
index bf55f9d..5c09902 100644
--- a/lib/src/handler/json_wire/mouse.dart
+++ b/lib/src/handler/json_wire/mouse.dart
@@ -47,7 +47,7 @@
WebDriverRequest buildMoveToRequest(
{String elementId, int xOffset, int yOffset, bool absolute = false}) {
if (absolute) {
- throw InvalidArgumentException(
+ throw const InvalidArgumentException(
0, 'Move to an absolute location is only supported in W3C spec.');
}
diff --git a/lib/src/handler/json_wire/utils.dart b/lib/src/handler/json_wire/utils.dart
index afa3bf3..01a1f20 100644
--- a/lib/src/handler/json_wire/utils.dart
+++ b/lib/src/handler/json_wire/utils.dart
@@ -27,8 +27,8 @@
(responseBody is Map &&
responseBody['status'] != null &&
responseBody['status'] != 0)) {
- final status = responseBody['status'];
- final message = responseBody['value']['message'];
+ final status = responseBody['status'] as int;
+ final message = responseBody['value']['message'] as String;
switch (status) {
case 0:
@@ -135,7 +135,7 @@
}
if (obj is List) {
- return obj.map((item) => serialize(item)).toList();
+ return obj.map(serialize).toList();
}
return obj;
diff --git a/lib/src/handler/w3c/element_finder.dart b/lib/src/handler/w3c/element_finder.dart
index e30c9ad..eebaaf8 100644
--- a/lib/src/handler/w3c/element_finder.dart
+++ b/lib/src/handler/w3c/element_finder.dart
@@ -9,8 +9,8 @@
/// In principle, W3C spec implementations should be nearly the same as
/// the existing JSON wire spec. In practice compliance is uneven.
Map<String, String> _byToJson(By by) {
- var using;
- var value;
+ String using;
+ String value;
switch (by.using) {
case 'id': // This doesn't exist in the W3C spec.
@@ -42,10 +42,9 @@
@override
List<String> parseFindElementsResponse(WebDriverResponse response) {
- return parseW3cResponse(response)
- .map((e) => e[w3cElementStr])
- .toList()
- .cast<String>();
+ return (parseW3cResponse(response) as List)
+ .map<String>((e) => e[w3cElementStr])
+ .toList();
}
@override
diff --git a/lib/src/handler/w3c/utils.dart b/lib/src/handler/w3c/utils.dart
index 2bd0845..84f7901 100644
--- a/lib/src/handler/w3c/utils.dart
+++ b/lib/src/handler/w3c/utils.dart
@@ -9,6 +9,7 @@
const String w3cElementStr = 'element-6066-11e4-a52e-4f735466cecf';
dynamic parseW3cResponse(WebDriverResponse response) {
+ final int statusCode = response.statusCode;
Map responseBody;
try {
responseBody = json.decode(response.body);
@@ -17,110 +18,99 @@
? '<empty response>'
: response.body;
throw WebDriverException(
- response.statusCode, 'Error parsing response body: $rawBody');
+ statusCode, 'Error parsing response body: $rawBody');
}
- if (response.statusCode < 200 || response.statusCode > 299) {
- final value = responseBody['value'];
+ if (statusCode < 200 || statusCode > 299) {
+ final Map value = responseBody['value'];
+ final String message = value['message'];
+
// See https://www.w3.org/TR/webdriver/#handling-errors
switch (value['error']) {
case 'element click intercepted':
- throw ElementClickInterceptedException(
- response.statusCode, value['message']);
+ throw ElementClickInterceptedException(statusCode, message);
case 'element not interactable':
- throw ElementNotInteractableException(
- response.statusCode, value['message']);
+ throw ElementNotInteractableException(statusCode, message);
case 'insecure certificate':
- throw InsecureCertificateException(
- response.statusCode, value['message']);
+ throw InsecureCertificateException(statusCode, message);
case 'invalid argument':
- throw InvalidArgumentException(response.statusCode, value['message']);
+ throw InvalidArgumentException(statusCode, message);
case 'invalid cookie domain':
- throw InvalidCookieDomainException(
- response.statusCode, value['message']);
+ throw InvalidCookieDomainException(statusCode, message);
case 'invalid element state':
- throw InvalidElementStateException(
- response.statusCode, value['message']);
+ throw InvalidElementStateException(statusCode, message);
case 'invalid selector':
- throw InvalidSelectorException(response.statusCode, value['message']);
+ throw InvalidSelectorException(statusCode, message);
case 'invalid session id':
- throw InvalidSessionIdException(response.statusCode, value['message']);
+ throw InvalidSessionIdException(statusCode, message);
case 'javascript error':
- throw JavaScriptException(response.statusCode, value['message']);
+ throw JavaScriptException(statusCode, message);
case 'move target out of bounds':
- throw MoveTargetOutOfBoundsException(
- response.statusCode, value['message']);
+ throw MoveTargetOutOfBoundsException(statusCode, message);
case 'no such alert':
- throw NoSuchAlertException(response.statusCode, value['message']);
+ throw NoSuchAlertException(statusCode, message);
case 'no such cookie':
- throw NoSuchCookieException(response.statusCode, value['message']);
+ throw NoSuchCookieException(statusCode, message);
case 'no such element':
- throw NoSuchElementException(response.statusCode, value['message']);
+ throw NoSuchElementException(statusCode, message);
case 'no such frame':
- throw NoSuchFrameException(response.statusCode, value['message']);
+ throw NoSuchFrameException(statusCode, message);
case 'no such window':
- throw NoSuchWindowException(response.statusCode, value['message']);
+ throw NoSuchWindowException(statusCode, message);
case 'script timeout':
- throw ScriptTimeoutException(response.statusCode, value['message']);
+ throw ScriptTimeoutException(statusCode, message);
case 'session not created':
- throw SessionNotCreatedException(response.statusCode, value['message']);
+ throw SessionNotCreatedException(statusCode, message);
case 'stale element reference':
- throw StaleElementReferenceException(
- response.statusCode, value['message']);
+ throw StaleElementReferenceException(statusCode, message);
case 'timeout':
- throw TimeoutException(response.statusCode, value['message']);
+ throw TimeoutException(statusCode, message);
case 'unable to set cookie':
- throw UnableToSetCookieException(response.statusCode, value['message']);
+ throw UnableToSetCookieException(statusCode, message);
case 'unable to capture screen':
- throw UnableToCaptureScreenException(
- response.statusCode, value['message']);
+ throw UnableToCaptureScreenException(statusCode, message);
case 'unexpected alert open':
- throw UnexpectedAlertOpenException(
- response.statusCode, value['message']);
+ throw UnexpectedAlertOpenException(statusCode, message);
case 'unknown command':
- throw UnknownCommandException(response.statusCode, value['message']);
+ throw UnknownCommandException(statusCode, message);
case 'unknown error':
- throw UnknownException(response.statusCode, value['message']);
+ throw UnknownException(statusCode, message);
case 'unknown method':
- throw UnknownMethodException(response.statusCode, value['message']);
+ throw UnknownMethodException(statusCode, message);
case 'unsupported operation':
- throw UnsupportedOperationException(
- response.statusCode, value['message']);
+ throw UnsupportedOperationException(statusCode, message);
+
default:
- throw WebDriverException(response.statusCode, value['message']);
+ throw WebDriverException(statusCode, message);
}
}
- if (responseBody is Map) {
- return responseBody['value'];
- }
-
- return responseBody;
+ return responseBody == null ? null : responseBody['value'];
}
/// Prefix to represent element in webdriver uri.
@@ -162,7 +152,7 @@
}
if (obj is List) {
- return obj.map((item) => serialize(item)).toList();
+ return obj.map(serialize).toList();
}
return obj;
diff --git a/lib/src/handler/w3c_handler.dart b/lib/src/handler/w3c_handler.dart
index 222cc7d..932a2b0 100644
--- a/lib/src/handler/w3c_handler.dart
+++ b/lib/src/handler/w3c_handler.dart
@@ -69,5 +69,5 @@
deserialize(parseW3cResponse(response), createElement);
@override
- String toString() => "W3C";
+ String toString() => 'W3C';
}
diff --git a/lib/src/request/async_io_request_client.dart b/lib/src/request/async_io_request_client.dart
index 2b13e27..9d0c380 100644
--- a/lib/src/request/async_io_request_client.dart
+++ b/lib/src/request/async_io_request_client.dart
@@ -56,5 +56,5 @@
}
@override
- String toString() => "AsyncIo";
+ String toString() => 'AsyncIo';
}
diff --git a/lib/src/request/async_xhr_request_client.dart b/lib/src/request/async_xhr_request_client.dart
index 9781a2a..e898546 100644
--- a/lib/src/request/async_xhr_request_client.dart
+++ b/lib/src/request/async_xhr_request_client.dart
@@ -41,5 +41,5 @@
}
@override
- String toString() => "AsyncXhr";
+ String toString() => 'AsyncXhr';
}
diff --git a/lib/src/request/sync_http_request_client.dart b/lib/src/request/sync_http_request_client.dart
index 52d7dba..8676eb9 100644
--- a/lib/src/request/sync_http_request_client.dart
+++ b/lib/src/request/sync_http_request_client.dart
@@ -37,5 +37,5 @@
}
@override
- String toString() => "SyncHttp";
+ String toString() => 'SyncHttp';
}
diff --git a/lib/support/async.dart b/lib/support/async.dart
index 6b7fd55..d754005 100644
--- a/lib/support/async.dart
+++ b/lib/support/async.dart
@@ -35,7 +35,7 @@
const Clock();
/// Sleep for the specified time.
- Future sleep([Duration interval = defaultInterval]) =>
+ Future<void> sleep([Duration interval = defaultInterval]) =>
Future.delayed(interval);
/// The current time.
@@ -53,16 +53,13 @@
{matcher,
Duration timeout = defaultTimeout,
Duration interval = defaultInterval}) async {
- if (matcher != null) {
- matcher = m.wrapMatcher(matcher);
- }
-
+ m.Matcher mMatcher = matcher == null ? null : m.wrapMatcher(matcher);
var endTime = now.add(timeout);
while (true) {
try {
var value = await condition();
- if (matcher is m.Matcher) {
- _matcherExpect(value, matcher);
+ if (mMatcher != null) {
+ _matcherExpect(value, mMatcher);
}
return value;
} catch (e) {
@@ -98,14 +95,14 @@
}
class Lock {
- Completer _lock;
+ Completer<void> _lock;
Chain _stack;
final bool awaitChecking;
Lock({this.awaitChecking = false});
- Future acquire() {
+ Future<void> acquire() {
if (awaitChecking) {
if (isHeld) {
return Future.error(StateError(
diff --git a/lib/support/firefox_profile.dart b/lib/support/firefox_profile.dart
index cf2dede..f10e626 100644
--- a/lib/support/firefox_profile.dart
+++ b/lib/support/firefox_profile.dart
@@ -222,7 +222,7 @@
/// `prefs` and `userPrefs`.
/// It can be uses like
/// `var desired = Capabilities.firefox..addAll(firefoxProfile.toJson()}`
- Map toJson() {
+ Map<String, dynamic> toJson() {
Archive archive = Archive();
if (profileDirectory != null) {
profileDirectory.listSync(recursive: true).forEach((f) {
@@ -270,11 +270,9 @@
RegExp(r'user_pref\("([^"]+)", ("?.+?"?)\);');
final String name;
- T _value;
+ final T value;
- dynamic get value => _value;
-
- factory PrefsOption(String name, value) {
+ factory PrefsOption(String name, T value) {
assert(value is bool || value is int || value is String);
if (value is bool) {
return BooleanOption(name, value) as PrefsOption<T>;
@@ -314,7 +312,7 @@
as PrefsOption<T>;
}
- PrefsOption._(this.name, [this._value]) : assert(name.isNotEmpty);
+ PrefsOption._(this.name, [this.value]) : assert(name.isNotEmpty);
@override
bool operator ==(Object other) {
@@ -362,7 +360,7 @@
class StringOption extends PrefsOption<String> {
StringOption(String name, String value) : super._(name, value);
- String _escape(String value) =>
+ static String _escape(String value) =>
value.replaceAll(r'\', r'\\').replaceAll('"', r'\"');
@override
diff --git a/lib/support/forwarder.dart b/lib/support/forwarder.dart
index 5c9fcf8..58c23ef 100644
--- a/lib/support/forwarder.dart
+++ b/lib/support/forwarder.dart
@@ -75,13 +75,13 @@
/// Forward [request] to [driver] and respond to the request with the returned
/// value or any thrown exceptions.
- Future<Null> forward(HttpRequest request) async {
+ Future<void> forward(HttpRequest request) async {
try {
if (!request.uri.path.startsWith(prefix)) {
- request.response.statusCode = HttpStatus.NOT_FOUND;
+ request.response.statusCode = HttpStatus.notFound;
return;
}
- request.response.statusCode = HttpStatus.OK;
+ request.response.statusCode = HttpStatus.ok;
request.response.headers.contentType = _contentTypeJson;
var endpoint = request.uri.path.replaceFirst(prefix, '');
diff --git a/lib/support/stdio_stepper.dart b/lib/support/stdio_stepper.dart
index bbf9af8..e688c2b 100644
--- a/lib/support/stdio_stepper.dart
+++ b/lib/support/stdio_stepper.dart
@@ -16,7 +16,7 @@
import 'dart:async' show Future, Stream, StreamController;
import 'dart:convert' show Encoding, json;
-import 'dart:io' show exit, Stdin, stdin, SYSTEM_ENCODING;
+import 'dart:io' show exit, Stdin, stdin, systemEncoding;
import 'package:webdriver/src/async/stepper.dart';
@@ -35,8 +35,7 @@
final LineReader _reader;
- StdioStepper({LineReader reader})
- : _reader = reader == null ? stdinLineReader : reader;
+ StdioStepper({LineReader reader}) : _reader = reader ?? stdinLineReader;
@override
Future<bool> step(String method, String command, params) async {
@@ -97,7 +96,7 @@
/// Only encodings that are a superset of ASCII are supported
/// TODO(DrMarcII): Support arbitrary encodings
LineReader(Stream /* <List<int> | int> */ stream,
- {this.encoding = SYSTEM_ENCODING}) {
+ {this.encoding = systemEncoding}) {
if (stream is Stdin) {
stdin.lineMode = false;
}