diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1170aa4..ced8a8b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,7 +40,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [dev] + sdk: [2.18.0, dev] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d @@ -66,7 +66,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [2.14.0, dev] + sdk: [2.18.0, dev] steps: - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d diff --git a/CHANGELOG.md b/CHANGELOG.md index 037fbf2..2be0b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.2-dev + +* Require Dart 2.18 +* "Officially" deprecate `core.dart` and `io.dart` libraries. + ## 3.0.1 * Return Future with non-nullable generic from `waitFor`. The generic `T` may diff --git a/README.md b/README.md index eb01489..cf02b21 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![CI](https://github.com/google/webdriver.dart/actions/workflows/ci.yaml/badge.svg)](https://github.com/google/webdriver.dart/actions/workflows/ci.yaml) [![pub package](https://img.shields.io/pub/v/webdriver.svg)](https://pub.dartlang.org/packages/webdriver) +[![package publisher](https://img.shields.io/pub/publisher/webdriver.svg)](https://pub.dev/packages/webdriver/publisher) Provides WebDriver bindings for Dart. These use the WebDriver JSON interface, and as such, require the use of the WebDriver remote server. @@ -12,8 +13,8 @@ import 'package:webdriver/io.dart'; WebDriver driver = createDriver(...); ``` -This will use by default the asynchronous, JSON wire spec implementation. -You now can also use a synchronous version of WebDriver: +This will use by default the asynchronous, JSON wire spec implementation. You +now can also use a synchronous version of WebDriver: ```dart import 'package:webdriver/sync_io.dart'; @@ -22,9 +23,9 @@ final driver = createDriver(...); ``` This version of WebDriver supports both the JSON wire spec and W3C spec, -allowing use with modern versions of Firefox. This defaults to the JSON -wire spec, but can also be configured to use the W3C spec or even to try -and automatically infer the spec during session creation: +allowing use with modern versions of Firefox. This defaults to the JSON wire +spec, but can also be configured to use the W3C spec or even to try and +automatically infer the spec during session creation: ```dart final w3cDriver = createDriver(spec: WebDriverSpec.W3c); // Use W3C spec. @@ -35,11 +36,11 @@ final anyDriver = createDriver(spec: WebDriverSpec.Auto); // Infer spec. ## Testing Unfortunately using bazel with Dart libraries and Dart WebDriver is not yet -supported. We hope to add this at some point, but for now pub still works. +supported. We hope to add this at some point, but for now pub still works. As a consequence, running tests is a bit more complicated than we'd like: -1) Launch a WebDriver binar(ies). +1. Launch a WebDriver binar(ies). First, bring up chromedriver / geckodriver. Other conforming WebDriver binaries should work as well, but we test against these: @@ -53,19 +54,19 @@ As a consequence, running tests is a bit more complicated than we'd like: geckodriver is used to test our W3C spec implementation. Synchronous tests are labeled as Chrome/Firefox. All async tests run - exclusively against Chrome (as async, like ChromeDriver supports only the - old JSON wire spec). + exclusively against Chrome (as async, like ChromeDriver supports only the old + JSON wire spec). -2) Run a test. All files suffixed with '_test.dart' are tests. +2. Run a test. All files suffixed with `_test.dart` are tests. ``` - pub run test/path/to/test.dart -r expanded -p vm + dart test test/path/to/the_test.dart -r expanded -p vm ``` - Or to run *all* tests: + Or to run _all_ tests: ``` - pub run test -r expanded -p vm + dart test -r expanded -p vm ``` You should probably go get a coffee or something, this is gonna take a while. diff --git a/analysis_options.yaml b/analysis_options.yaml index 6488b3c..0831710 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,47 +1,44 @@ +# https://dart.dev/guides/language/analysis-options include: package:lints/recommended.yaml analyzer: - strong-mode: - implicit-casts: false + language: + strict-casts: true linter: rules: - - avoid_empty_else - - avoid_init_to_null - - avoid_null_checks_in_equality_operators + - always_declare_return_types + - avoid_bool_literals_in_conditional_expressions + - avoid_classes_with_only_static_members + - avoid_private_typedef_functions + - avoid_redundant_argument_values + - avoid_returning_null_for_future + - avoid_returning_this - avoid_unused_constructor_parameters - - await_only_futures - - camel_case_types + - avoid_void_async - cancel_subscriptions - - constant_identifier_names - - control_flow_in_finally - directives_ordering - - empty_catches - - empty_constructor_bodies - - empty_statements - - hash_and_equals - - implementation_imports - - iterable_contains_unrelated_type - - library_names - - library_prefixes - - list_remove_unrelated_type - - non_constant_identifier_names - - overridden_fields + - literal_only_boolean_expressions + - missing_whitespace_between_adjacent_strings + - no_adjacent_strings_in_list + - omit_local_variable_types - package_api_docs - - package_names - - package_prefixed_library_names - - prefer_equal_for_default_values + - prefer_asserts_in_initializer_lists + - prefer_const_constructors + - prefer_const_declarations - prefer_expression_function_bodies - - prefer_final_fields - - prefer_generic_function_type_aliases - - prefer_is_not_empty + - prefer_final_locals - prefer_relative_imports - - slash_for_doc_comments + - prefer_single_quotes + - sort_pub_dependencies - test_types_in_equals - throw_in_finally - - type_init_formals - - unnecessary_brace_in_string_interps - - unnecessary_const - - unnecessary_new - - unrelated_type_equality_checks - - valid_regexps + - type_annotate_public_apis + - unawaited_futures + - unnecessary_lambdas + - unnecessary_parenthesis + - unnecessary_statements + - use_if_null_to_convert_nulls_to_bools + - use_raw_strings + - use_string_buffers + - use_super_parameters diff --git a/lib/async_core.dart b/lib/async_core.dart index b33067d..d87fff6 100644 --- a/lib/async_core.dart +++ b/lib/async_core.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.core; - import 'dart:async' show Future; import 'dart:collection' show UnmodifiableMapView; diff --git a/lib/async_html.dart b/lib/async_html.dart index 21f86b0..eb2f13a 100644 --- a/lib/async_html.dart +++ b/lib/async_html.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.html; - import 'dart:async' show Future; import 'async_core.dart' as core @@ -53,8 +51,7 @@ Future createDriver( /// last path component will be dropped. Future fromExistingSession(String sessionId, {Uri? uri, WebDriverSpec spec = WebDriverSpec.Auto}) => - core.fromExistingSession( - (prefix) => AsyncXhrRequestClient(prefix), sessionId, + core.fromExistingSession(AsyncXhrRequestClient.new, sessionId, uri: uri, spec: spec); /// Creates an async WebDriver from existing session with a sync function using @@ -70,6 +67,5 @@ Future fromExistingSession(String sessionId, /// last path component will be dropped. core.WebDriver fromExistingSessionSync(String sessionId, WebDriverSpec spec, {Uri? uri, Map? capabilities}) => - core.fromExistingSessionSync( - (prefix) => AsyncXhrRequestClient(prefix), sessionId, spec, + core.fromExistingSessionSync(AsyncXhrRequestClient.new, sessionId, spec, uri: uri, capabilities: capabilities); diff --git a/lib/async_io.dart b/lib/async_io.dart index 0001692..f3b0993 100644 --- a/lib/async_io.dart +++ b/lib/async_io.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.io; - import 'dart:async' show Future; import 'async_core.dart' as core @@ -55,8 +53,7 @@ Future createDriver( /// last path component will be dropped. Future fromExistingSession(String sessionId, {Uri? uri, core.WebDriverSpec spec = core.WebDriverSpec.Auto}) => - core.fromExistingSession( - (prefix) => AsyncIoRequestClient(prefix), sessionId, + core.fromExistingSession(AsyncIoRequestClient.new, sessionId, uri: uri, spec: spec); /// Creates an async WebDriver from existing session with a sync function using @@ -73,6 +70,5 @@ Future fromExistingSession(String sessionId, core.WebDriver fromExistingSessionSync( String sessionId, core.WebDriverSpec spec, {Uri? uri, Map? capabilities}) => - core.fromExistingSessionSync( - (prefix) => AsyncIoRequestClient(prefix), sessionId, spec, + core.fromExistingSessionSync(AsyncIoRequestClient.new, sessionId, spec, uri: uri, capabilities: capabilities); diff --git a/lib/core.dart b/lib/core.dart index 7369275..4c7ce75 100644 --- a/lib/core.dart +++ b/lib/core.dart @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.core; +@Deprecated("Use 'package:webdriver/async_core.dart' instead.") +library core; /// Consider this file as deprecated. This exists as an alias to async_core.dart /// for backward compatibility. diff --git a/lib/io.dart b/lib/io.dart index 35e615e..79805d7 100644 --- a/lib/io.dart +++ b/lib/io.dart @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.io; +@Deprecated("Use 'package:webdriver/async_io.dart' instead.") +library io; /// Consider this file as deprecated. This exists as an alias to async_io.dart /// for backward compatibility. -export 'package:webdriver/async_io.dart'; +export 'async_io.dart'; diff --git a/lib/src/async/alert.dart b/lib/src/async/alert.dart index 2f6c526..ba65efa 100644 --- a/lib/src/async/alert.dart +++ b/lib/src/async/alert.dart @@ -57,6 +57,6 @@ class Alert { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Alert && _handler == other._handler && _client == other._client; } diff --git a/lib/src/async/cookies.dart b/lib/src/async/cookies.dart index 1b34be3..eb13a5b 100644 --- a/lib/src/async/cookies.dart +++ b/lib/src/async/cookies.dart @@ -61,7 +61,7 @@ class Cookies { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Cookies && _handler == other._handler && _client == other._client; diff --git a/lib/src/async/keyboard.dart b/lib/src/async/keyboard.dart index 673fa05..35e756a 100644 --- a/lib/src/async/keyboard.dart +++ b/lib/src/async/keyboard.dart @@ -97,7 +97,7 @@ class Keyboard { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Keyboard && _handler == other._handler && _client == other._client; diff --git a/lib/src/async/logs.dart b/lib/src/async/logs.dart index e7a26fc..b83154d 100644 --- a/lib/src/async/logs.dart +++ b/lib/src/async/logs.dart @@ -45,6 +45,6 @@ class Logs { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Logs && _handler == other._handler && _client == other._client; } diff --git a/lib/src/async/mouse.dart b/lib/src/async/mouse.dart index d72647b..52f7b21 100644 --- a/lib/src/async/mouse.dart +++ b/lib/src/async/mouse.dart @@ -127,6 +127,6 @@ class Mouse { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Mouse && _handler == other._handler && _client == other._client; } diff --git a/lib/src/async/stepper.dart b/lib/src/async/stepper.dart index ba5b425..0db19ab 100644 --- a/lib/src/async/stepper.dart +++ b/lib/src/async/stepper.dart @@ -20,6 +20,6 @@ class Stepper { const Stepper(); /// returns true if command should be executed, false if should not be executed. - Future step(String method, String command, params) => + Future step(String method, String command, Object? params) => Future.value(true); } diff --git a/lib/src/async/target_locator.dart b/lib/src/async/target_locator.dart index cfe07ca..3da24b2 100644 --- a/lib/src/async/target_locator.dart +++ b/lib/src/async/target_locator.dart @@ -35,7 +35,7 @@ class TargetLocator { /// 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 frame([Object? /* int | WebElement | String */ frame]) async { if (frame is int?) { await _client.send(_handler.frame.buildSwitchByIdRequest(frame), _handler.frame.parseSwitchByIdResponse); @@ -75,5 +75,6 @@ class TargetLocator { int get hashCode => _driver.hashCode; @override - bool operator ==(other) => other is TargetLocator && other._driver == _driver; + bool operator ==(Object other) => + other is TargetLocator && other._driver == _driver; } diff --git a/lib/src/async/timeouts.dart b/lib/src/async/timeouts.dart index 7f48fe4..f769d52 100644 --- a/lib/src/async/timeouts.dart +++ b/lib/src/async/timeouts.dart @@ -45,7 +45,7 @@ class Timeouts { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Timeouts && _handler == other._handler && _client == other._client; diff --git a/lib/src/async/web_driver.dart b/lib/src/async/web_driver.dart index ebbcc91..06fb245 100644 --- a/lib/src/async/web_driver.dart +++ b/lib/src/async/web_driver.dart @@ -74,7 +74,7 @@ class WebDriver implements SearchContext { _handler.core.parseCurrentUrlResponse); /// Navigates to the specified url - Future get(/* Uri | String */ url) => _client.send( + Future get(Object /* Uri | String */ url) => _client.send( _handler.navigation.buildNavigateToRequest( (url is Uri) ? url.toString() : url as String, ), @@ -200,13 +200,13 @@ class WebDriver implements SearchContext { /// Take a screenshot of the current page as PNG as list of uint8. Future> captureScreenshotAsList() async { - var base64Encoded = captureScreenshotAsBase64(); + final base64Encoded = captureScreenshotAsBase64(); return base64.decode(await base64Encoded); } /// Take a screenshot of the specified element as PNG as list of uint8. Future> captureElementScreenshotAsList(WebElement element) async { - var base64Encoded = captureElementScreenshotAsBase64(element); + final base64Encoded = captureElementScreenshotAsBase64(element); return base64.decode(await base64Encoded); } @@ -263,7 +263,7 @@ class WebDriver implements SearchContext { ), ); - Future postRequest(String command, [params]) => _client.send( + Future postRequest(String command, [Object? params]) => _client.send( _handler.buildGeneralRequest(HttpMethod.httpPost, command, params), (response) => _handler.parseGeneralResponse( response, @@ -290,7 +290,7 @@ class WebDriver implements SearchContext { WebElement getElement( String elementId, [ SearchContext? context, - locator, + Object? locator, int? index, ]) => WebElement(this, _client, _handler, elementId, context, locator, index); diff --git a/lib/src/async/web_element.dart b/lib/src/async/web_element.dart index 8b60be8..9ff9798 100644 --- a/lib/src/async/web_element.dart +++ b/lib/src/async/web_element.dart @@ -33,7 +33,7 @@ class WebElement extends common.WebElement implements SearchContext { final SearchContext? context; /// How the element was located from the context. - final dynamic /* String | Finder */ locator; + final Object? /* String | Finder */ locator; /// The index of this element in the set of element founds. If the method /// used to find this element always returns one element, then this is null. @@ -157,12 +157,12 @@ class WebElement extends common.WebElement implements SearchContext { int get hashCode => driver.hashCode * 3 + id.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is WebElement && other.driver == driver && other.id == id; @override String toString() { - var out = StringBuffer()..write(context); + final out = StringBuffer()..write(context); if (locator is By) { if (index == null) { out.write('.findElement('); diff --git a/lib/src/async/window.dart b/lib/src/async/window.dart index 436e7a8..8e2ee43 100644 --- a/lib/src/async/window.dart +++ b/lib/src/async/window.dart @@ -102,7 +102,7 @@ class Window { int get hashCode => id.hashCode + _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Window && other._client == _client && other._handler == _handler && diff --git a/lib/src/common/by.dart b/lib/src/common/by.dart index 87e05ab..84a9eee 100644 --- a/lib/src/common/by.dart +++ b/lib/src/common/by.dart @@ -60,6 +60,6 @@ class By { int get hashCode => using.hashCode * 3 + value.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is By && other.using == using && other.value == value; } diff --git a/lib/src/common/capabilities.dart b/lib/src/common/capabilities.dart index 88d31b6..89504e8 100644 --- a/lib/src/common/capabilities.dart +++ b/lib/src/common/capabilities.dart @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// ignore: avoid_classes_with_only_static_members /// Capabilities constants. class Capabilities { static const String browserName = 'browserName'; diff --git a/lib/src/common/exception.dart b/lib/src/common/exception.dart index 961f967..83063f3 100644 --- a/lib/src/common/exception.dart +++ b/lib/src/common/exception.dart @@ -11,11 +11,10 @@ class WebDriverException implements Exception { @override String toString() => - '$runtimeType ($statusCode): ' + - (message?.isEmpty != false ? '' : message!); + '$runtimeType ($statusCode): ${message?.isEmpty ?? true ? '' : message!}'; @override - bool operator ==(other) => + bool operator ==(Object other) => other is WebDriverException && other.runtimeType == runtimeType && other.statusCode == statusCode && @@ -26,201 +25,166 @@ 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(int 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(int 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(int 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(int 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(int 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(int 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(int 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(int super.statusCode, super.message); } /// Temporary method to emulate the original json wire exception parsing logic. WebDriverException getExceptionFromJsonWireResponse( {int? httpStatusCode, String? httpReasonPhrase, dynamic jsonResp}) { if (jsonResp is Map) { - var status = jsonResp['status'] as int?; - var message = jsonResp['value']['message'] as String?; + final status = jsonResp['status'] as int?; + final message = jsonResp['value']['message'] as String?; switch (status) { case 0: diff --git a/lib/src/common/request.dart b/lib/src/common/request.dart index d310520..f10931c 100644 --- a/lib/src/common/request.dart +++ b/lib/src/common/request.dart @@ -28,7 +28,7 @@ class WebDriverRequest { WebDriverRequest(this.method, this.uri, this.body); - WebDriverRequest.postRequest(this.uri, [params]) + WebDriverRequest.postRequest(this.uri, [Object? params]) : method = HttpMethod.httpPost, body = params == null ? '{}' : json.encode(params); diff --git a/lib/src/common/request_client.dart b/lib/src/common/request_client.dart index 31ff9d9..bffbd24 100644 --- a/lib/src/common/request_client.dart +++ b/lib/src/common/request_client.dart @@ -12,7 +12,7 @@ abstract class RequestClient { RequestClient(this._prefix); Uri resolve(String command) => _prefix.resolve( - command.isEmpty ? _prefix.path.replaceFirst(RegExp('/\$'), '') : command); + command.isEmpty ? _prefix.path.replaceFirst(RegExp(r'/$'), '') : command); @override String toString() => _prefix.toString(); @@ -24,7 +24,7 @@ typedef SyncWebDriverListener = void Function(WebDriverCommandEvent event); abstract class SyncRequestClient extends RequestClient { final _commandListeners = []; - SyncRequestClient(Uri prefix) : super(prefix); + SyncRequestClient(super.prefix); void addEventListener(SyncWebDriverListener listener) { _commandListeners.add(listener); @@ -73,7 +73,7 @@ typedef AsyncWebDriverListener = Future Function( abstract class AsyncRequestClient extends RequestClient { final _commandListeners = []; - AsyncRequestClient(Uri prefix) : super(prefix); + AsyncRequestClient(super.prefix); void addEventListener(AsyncWebDriverListener listener) { _commandListeners.add(listener); diff --git a/lib/src/common/webdriver_handler.dart b/lib/src/common/webdriver_handler.dart index 175fe0f..ce1a25f 100644 --- a/lib/src/common/webdriver_handler.dart +++ b/lib/src/common/webdriver_handler.dart @@ -44,7 +44,8 @@ abstract class WebDriverHandler { LogsHandler get logs; /// Builds general request to send to web driver server. - WebDriverRequest buildGeneralRequest(HttpMethod method, String uri, [params]); + WebDriverRequest buildGeneralRequest(HttpMethod method, String uri, + [Object? params]); /// Parses general response got from web driver server. dynamic parseGeneralResponse( diff --git a/lib/src/handler/infer_handler.dart b/lib/src/handler/infer_handler.dart index 3ccdb2a..50533db 100644 --- a/lib/src/handler/infer_handler.dart +++ b/lib/src/handler/infer_handler.dart @@ -64,8 +64,11 @@ class InferWebDriverHandler extends WebDriverHandler { throw UnsupportedError('Unsupported for InferHandler'); @override - WebDriverRequest buildGeneralRequest(HttpMethod method, String uri, - [params]) => + WebDriverRequest buildGeneralRequest( + HttpMethod method, + String uri, [ + Object? params, + ]) => throw UnsupportedError('Unsupported for InferHandler'); @override @@ -122,9 +125,8 @@ class InferSessionHandler extends SessionHandler { try { body = json.decode(response.body!)['value'] as Map?; } catch (e) { - final rawBody = response.body?.isEmpty != false - ? '' - : response.body; + final rawBody = + response.body?.isEmpty ?? true ? '' : response.body; throw WebDriverException( response.statusCode, 'Error parsing response body: $rawBody', diff --git a/lib/src/handler/json_wire/element.dart b/lib/src/handler/json_wire/element.dart index a33b9e9..b8defa5 100644 --- a/lib/src/handler/json_wire/element.dart +++ b/lib/src/handler/json_wire/element.dart @@ -64,7 +64,7 @@ class JsonWireElementHandler extends ElementHandler { @override Point parseLocationResponse(WebDriverResponse response) { - final point = parseJsonWireResponse(response); + final point = parseJsonWireResponse(response) as Map; return Point((point['x'] as num).toInt(), (point['y'] as num).toInt()); } @@ -74,7 +74,7 @@ class JsonWireElementHandler extends ElementHandler { @override Rectangle parseSizeResponse(WebDriverResponse response) { - final size = parseJsonWireResponse(response); + final size = parseJsonWireResponse(response) as Map; return Rectangle( 0, 0, diff --git a/lib/src/handler/json_wire/element_finder.dart b/lib/src/handler/json_wire/element_finder.dart index 71ba1a3..a1bf9e7 100644 --- a/lib/src/handler/json_wire/element_finder.dart +++ b/lib/src/handler/json_wire/element_finder.dart @@ -10,7 +10,7 @@ class JsonWireElementFinder extends ElementFinder { @override WebDriverRequest buildFindElementsRequest(By by, [String? contextId]) { - var uri = contextId == null ? 'elements' : 'element/$contextId/elements'; + final uri = contextId == null ? 'elements' : 'element/$contextId/elements'; return WebDriverRequest.postRequest(uri, _byToJson(by)); } @@ -23,7 +23,7 @@ class JsonWireElementFinder extends ElementFinder { @override WebDriverRequest buildFindElementRequest(By by, [String? contextId]) { - var uri = contextId == null ? 'element' : 'element/$contextId/element'; + final uri = contextId == null ? 'element' : 'element/$contextId/element'; return WebDriverRequest.postRequest(uri, _byToJson(by)); } @@ -37,5 +37,5 @@ class JsonWireElementFinder extends ElementFinder { @override String? parseFindElementResponseCore(WebDriverResponse response) => - (parseJsonWireResponse(response) ?? {})[jsonWireElementStr] as String?; + (parseJsonWireResponse(response) as Map?)?[jsonWireElementStr] as String?; } diff --git a/lib/src/handler/json_wire/keyboard.dart b/lib/src/handler/json_wire/keyboard.dart index 95ff6eb..d7c68fb 100644 --- a/lib/src/handler/json_wire/keyboard.dart +++ b/lib/src/handler/json_wire/keyboard.dart @@ -21,7 +21,7 @@ class JsonWireKeyboardHandler extends KeyboardHandler { } String _createChord(Iterable chord) { - var chordString = StringBuffer(); + final chordString = StringBuffer(); for (var s in chord) { chordString.write(s); } diff --git a/lib/src/handler/json_wire/session.dart b/lib/src/handler/json_wire/session.dart index 5954ec5..2b07a17 100644 --- a/lib/src/handler/json_wire/session.dart +++ b/lib/src/handler/json_wire/session.dart @@ -24,7 +24,7 @@ class JsonWireSessionHandler extends SessionHandler { @override SessionInfo parseInfoResponse(WebDriverResponse response, [String? sessionId]) { - final session = parseJsonWireResponse(response, valueOnly: false); + final session = parseJsonWireResponse(response, valueOnly: false) as Map; return SessionInfo( session['sessionId'] as String, WebDriverSpec.JsonWire, diff --git a/lib/src/handler/json_wire/utils.dart b/lib/src/handler/json_wire/utils.dart index 6a52fa9..4537f52 100644 --- a/lib/src/handler/json_wire/utils.dart +++ b/lib/src/handler/json_wire/utils.dart @@ -8,7 +8,7 @@ import '../../common/web_element.dart'; /// Source: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol const String jsonWireElementStr = 'ELEMENT'; -dynamic parseJsonWireResponse(WebDriverResponse response, +Object? parseJsonWireResponse(WebDriverResponse response, {bool valueOnly = true}) { final statusCode = response.statusCode!; Map responseBody; @@ -103,7 +103,7 @@ String elementPrefix(String? elementId) => /// Deserializes json object returned by WebDriver server. /// /// Mainly it handles the element object rebuild. -dynamic deserialize(result, dynamic Function(String) createElement) { +Object? deserialize(Object? result, dynamic Function(String) createElement) { if (result is Map) { if (result.containsKey(jsonWireElementStr)) { return createElement(result[jsonWireElementStr] as String); @@ -121,22 +121,19 @@ dynamic deserialize(result, dynamic Function(String) createElement) { } } -dynamic serialize(dynamic obj) { +Object? serialize(dynamic obj) { if (obj is WebElement) { return {jsonWireElementStr: obj.id}; } if (obj is Map) { - final newResult = {}; - for (final item in obj.entries) { - newResult[item.key as String] = serialize(item.value); - } - - return newResult; + return { + for (var item in obj.entries) item.key as String: serialize(item.value), + }; } if (obj is List) { - return obj.map(serialize).toList(); + return [for (var item in obj) serialize(item)]; } return obj; diff --git a/lib/src/handler/json_wire/window.dart b/lib/src/handler/json_wire/window.dart index cb307a2..05ef108 100644 --- a/lib/src/handler/json_wire/window.dart +++ b/lib/src/handler/json_wire/window.dart @@ -50,7 +50,7 @@ class JsonWireWindowHandler extends WindowHandler { @override Point parseLocationResponse(WebDriverResponse response) { - final point = parseJsonWireResponse(response); + final point = parseJsonWireResponse(response) as Map; return Point( (point['x'] as num).toInt(), (point['y'] as num).toInt(), @@ -63,7 +63,7 @@ class JsonWireWindowHandler extends WindowHandler { @override Rectangle parseSizeResponse(WebDriverResponse response) { - final size = parseJsonWireResponse(response); + final size = parseJsonWireResponse(response) as Map; return Rectangle( 0, 0, @@ -147,7 +147,7 @@ class JsonWireWindowHandler extends WindowHandler { @override Rectangle parseInnerSizeResponse(WebDriverResponse response) { - final size = parseJsonWireResponse(response); + final size = parseJsonWireResponse(response) as Map; return Rectangle(0, 0, size['width'] as int, size['height'] as int); } } diff --git a/lib/src/handler/json_wire_handler.dart b/lib/src/handler/json_wire_handler.dart index c29f337..ec0372d 100644 --- a/lib/src/handler/json_wire_handler.dart +++ b/lib/src/handler/json_wire_handler.dart @@ -58,8 +58,11 @@ class JsonWireWebDriverHandler extends WebDriverHandler { final LogsHandler logs = JsonWireLogsHandler(); @override - WebDriverRequest buildGeneralRequest(HttpMethod method, String uri, - [params]) => + WebDriverRequest buildGeneralRequest( + HttpMethod method, + String uri, [ + Object? params, + ]) => WebDriverRequest( method, uri, params == null ? null : json.encode(serialize(params))); diff --git a/lib/src/handler/w3c/element_finder.dart b/lib/src/handler/w3c/element_finder.dart index 2269ee2..e1d10c9 100644 --- a/lib/src/handler/w3c/element_finder.dart +++ b/lib/src/handler/w3c/element_finder.dart @@ -40,7 +40,7 @@ class W3cElementFinder extends ElementFinder { @override WebDriverRequest buildFindElementsRequest(By by, [String? contextId]) { - var uri = '${elementPrefix(contextId)}elements'; + final uri = '${elementPrefix(contextId)}elements'; return WebDriverRequest.postRequest(uri, _byToJson(by)); } @@ -52,7 +52,7 @@ class W3cElementFinder extends ElementFinder { @override WebDriverRequest buildFindElementRequest(By by, [String? contextId]) { - var uri = '${elementPrefix(contextId)}element'; + final uri = '${elementPrefix(contextId)}element'; return WebDriverRequest.postRequest(uri, _byToJson(by)); } diff --git a/lib/src/handler/w3c/utils.dart b/lib/src/handler/w3c/utils.dart index 07dc148..beac292 100644 --- a/lib/src/handler/w3c/utils.dart +++ b/lib/src/handler/w3c/utils.dart @@ -121,7 +121,7 @@ dynamic parseW3cResponse(WebDriverResponse response) { String elementPrefix(String? elementId) => elementId == null ? '' : 'element/$elementId/'; -dynamic deserialize(result, dynamic Function(String) createElement) { +Object? deserialize(Object? result, dynamic Function(String) createElement) { if (result is Map) { if (result.containsKey(w3cElementStr)) { return createElement(result[w3cElementStr] as String); diff --git a/lib/src/handler/w3c_handler.dart b/lib/src/handler/w3c_handler.dart index 82c94c8..9db0bde 100644 --- a/lib/src/handler/w3c_handler.dart +++ b/lib/src/handler/w3c_handler.dart @@ -58,8 +58,11 @@ class W3cWebDriverHandler extends WebDriverHandler { LogsHandler get logs => W3cLogsHandler(); @override - WebDriverRequest buildGeneralRequest(HttpMethod method, String uri, - [params]) => + WebDriverRequest buildGeneralRequest( + HttpMethod method, + String uri, [ + Object? params, + ]) => WebDriverRequest( method, uri, params == null ? null : json.encode(serialize(params))); diff --git a/lib/src/request/async_io_request_client.dart b/lib/src/request/async_io_request_client.dart index 02bd2c2..dc8ebb8 100644 --- a/lib/src/request/async_io_request_client.dart +++ b/lib/src/request/async_io_request_client.dart @@ -14,9 +14,8 @@ class AsyncIoRequestClient extends AsyncRequestClient { final Lock _lock = Lock(); - AsyncIoRequestClient(Uri prefix, {Map headers = const {}}) - : _headers = headers, - super(prefix); + AsyncIoRequestClient(super.prefix, {Map headers = const {}}) + : _headers = headers; @override Future sendRaw(WebDriverRequest request) async { diff --git a/lib/src/request/async_xhr_request_client.dart b/lib/src/request/async_xhr_request_client.dart index f3464b2..b369700 100644 --- a/lib/src/request/async_xhr_request_client.dart +++ b/lib/src/request/async_xhr_request_client.dart @@ -13,9 +13,8 @@ class AsyncXhrRequestClient extends AsyncRequestClient { final Lock _lock = Lock(); final Map _headers; - AsyncXhrRequestClient(Uri prefix, {Map headers = const {}}) - : _headers = headers, - super(prefix); + AsyncXhrRequestClient(super.prefix, {Map headers = const {}}) + : _headers = headers; @override Future sendRaw(WebDriverRequest request) async { diff --git a/lib/src/request/sync_http_request_client.dart b/lib/src/request/sync_http_request_client.dart index 0e3f615..2ab596b 100644 --- a/lib/src/request/sync_http_request_client.dart +++ b/lib/src/request/sync_http_request_client.dart @@ -8,9 +8,8 @@ import '../common/request_client.dart'; /// Sync request client using sync_http package. class SyncHttpRequestClient extends SyncRequestClient { final Map _headers; - SyncHttpRequestClient(Uri prefix, {Map headers = const {}}) - : _headers = headers, - super(prefix); + SyncHttpRequestClient(super.prefix, {Map headers = const {}}) + : _headers = headers; @override WebDriverResponse sendRaw(WebDriverRequest request) { diff --git a/lib/src/sync/alert.dart b/lib/src/sync/alert.dart index 6d7d7c4..7650848 100644 --- a/lib/src/sync/alert.dart +++ b/lib/src/sync/alert.dart @@ -60,6 +60,6 @@ class Alert { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Alert && _handler == other._handler && _client == other._client; } diff --git a/lib/src/sync/cookies.dart b/lib/src/sync/cookies.dart index 0653070..0885e11 100644 --- a/lib/src/sync/cookies.dart +++ b/lib/src/sync/cookies.dart @@ -58,7 +58,7 @@ class Cookies { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Cookies && _handler == other._handler && _client == other._client; diff --git a/lib/src/sync/keyboard.dart b/lib/src/sync/keyboard.dart index 62a7cbf..4995096 100644 --- a/lib/src/sync/keyboard.dart +++ b/lib/src/sync/keyboard.dart @@ -93,7 +93,7 @@ class Keyboard { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Keyboard && _handler == other._handler && _client == other._client; diff --git a/lib/src/sync/logs.dart b/lib/src/sync/logs.dart index c00ad2d..f951431 100644 --- a/lib/src/sync/logs.dart +++ b/lib/src/sync/logs.dart @@ -40,6 +40,6 @@ class Logs { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Logs && _handler == other._handler && _client == other._client; } diff --git a/lib/src/sync/mouse.dart b/lib/src/sync/mouse.dart index 77b9a2f..471660a 100644 --- a/lib/src/sync/mouse.dart +++ b/lib/src/sync/mouse.dart @@ -134,6 +134,6 @@ class Mouse { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Mouse && _handler == other._handler && _client == other._client; } diff --git a/lib/src/sync/target_locator.dart b/lib/src/sync/target_locator.dart index 1ecb7bf..5b79fcf 100644 --- a/lib/src/sync/target_locator.dart +++ b/lib/src/sync/target_locator.dart @@ -15,7 +15,6 @@ import '../common/by.dart'; import '../common/request_client.dart'; import '../common/webdriver_handler.dart'; - import 'alert.dart'; import 'web_driver.dart'; import 'web_element.dart'; @@ -38,7 +37,7 @@ class TargetLocator { /// not provided: selects the first frame on the page or the main document. /// /// Throws [NoSuchFrameException] if the specified frame can't be found. - void frame([/* int | WebElement | String */ frame]) { + void frame([Object? /* int | WebElement | String */ frame]) { if (frame is int?) { _client.send(_handler.frame.buildSwitchByIdRequest(frame), _handler.frame.parseSwitchByIdResponse); @@ -82,5 +81,6 @@ class TargetLocator { int get hashCode => _driver.hashCode; @override - bool operator ==(other) => other is TargetLocator && other._driver == _driver; + bool operator ==(Object other) => + other is TargetLocator && other._driver == _driver; } diff --git a/lib/src/sync/timeouts.dart b/lib/src/sync/timeouts.dart index bd35e1f..945c941 100644 --- a/lib/src/sync/timeouts.dart +++ b/lib/src/sync/timeouts.dart @@ -47,7 +47,7 @@ class Timeouts { int get hashCode => _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Timeouts && _handler == other._handler && _client == other._client; diff --git a/lib/src/sync/web_driver.dart b/lib/src/sync/web_driver.dart index f913a61..cffd807 100644 --- a/lib/src/sync/web_driver.dart +++ b/lib/src/sync/web_driver.dart @@ -70,7 +70,7 @@ class WebDriver implements SearchContext { _handler.core.parseCurrentUrlResponse); /// Navigates to the specified url - void get(/* Uri | String */ url) { + void get(Object /* Uri | String */ url) { _client.send( _handler.navigation.buildNavigateToRequest( (url is Uri) ? url.toString() : url as String, @@ -271,7 +271,7 @@ class WebDriver implements SearchContext { /// Performs post request on command to the WebDriver server. /// /// For use by supporting WebDriver packages. - dynamic postRequest(String command, [params]) => _client.send( + dynamic postRequest(String command, [Object? params]) => _client.send( _handler.buildGeneralRequest(HttpMethod.httpPost, command, params), (response) => _handler.parseGeneralResponse( response, (elementId) => getElement(elementId, this))); @@ -298,7 +298,7 @@ class WebDriver implements SearchContext { WebElement getElement( String elementId, [ SearchContext? context, - locator, + Object? locator, int? index, ]) => WebElement( diff --git a/lib/src/sync/web_element.dart b/lib/src/sync/web_element.dart index 198b3bc..d28f57f 100644 --- a/lib/src/sync/web_element.dart +++ b/lib/src/sync/web_element.dart @@ -90,7 +90,7 @@ class WebElement extends common.WebElement implements SearchContext { WebElement? p = this; final result = []; while (p != null) { - var id = p.id; + final id = p.id; if (_parentCache.containsKey(id)) { break; } @@ -218,7 +218,7 @@ class WebElement extends common.WebElement implements SearchContext { int get hashCode => driver.hashCode * 3 + id.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is WebElement && other.driver == driver && other.id == id; @override diff --git a/lib/src/sync/window.dart b/lib/src/sync/window.dart index 1002f7e..5b4067d 100644 --- a/lib/src/sync/window.dart +++ b/lib/src/sync/window.dart @@ -125,7 +125,7 @@ class Window { int get hashCode => id.hashCode + _client.hashCode; @override - bool operator ==(other) => + bool operator ==(Object other) => other is Window && other._client == _client && other._handler == _handler && diff --git a/lib/support/async.dart b/lib/support/async.dart index a4a3137..ab4a02d 100644 --- a/lib/support/async.dart +++ b/lib/support/async.dart @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.support.async; - import 'dart:async' show Completer, FutureOr; import 'package:matcher/matcher.dart' as m; +import 'package:matcher/matcher.dart'; import 'package:stack_trace/stack_trace.dart' show Chain; const defaultInterval = Duration(milliseconds: 500); @@ -25,7 +24,7 @@ const defaultTimeout = Duration(seconds: 5); const clock = Clock(); Future waitFor(FutureOr Function() condition, - {matcher, + {Matcher? matcher, Duration timeout = defaultTimeout, Duration interval = defaultInterval}) => clock.waitFor(condition, @@ -50,14 +49,14 @@ class Clock { /// rethrown. If [condition] doesn't throw then an [expect] exception is /// thrown. Future waitFor(FutureOr Function() condition, - {matcher, + {Object? matcher, Duration timeout = defaultTimeout, Duration interval = defaultInterval}) async { - var mMatcher = matcher == null ? null : m.wrapMatcher(matcher); - var endTime = now.add(timeout); + final mMatcher = matcher == null ? null : m.wrapMatcher(matcher); + final endTime = now.add(timeout); while (true) { try { - var value = await condition(); + final value = await condition(); if (mMatcher != null) { _matcherExpect(value, mMatcher); } @@ -73,12 +72,12 @@ class Clock { } } -void _matcherExpect(value, m.Matcher matcher) { - var matchState = {}; +void _matcherExpect(Object? value, m.Matcher matcher) { + final matchState = {}; if (matcher.matches(value, matchState)) { return; } - var desc = m.StringDescription() + final desc = m.StringDescription() ..add('Expected: ') ..addDescriptionOf(matcher) ..add('\n') @@ -86,7 +85,7 @@ void _matcherExpect(value, m.Matcher matcher) { ..addDescriptionOf(value) ..add('\n'); - var mismatchDescription = m.StringDescription(); + final mismatchDescription = m.StringDescription(); matcher.describeMismatch(value, mismatchDescription, matchState, true); if (mismatchDescription.length > 0) { desc.add(' Which: $mismatchDescription\n'); diff --git a/lib/support/firefox_profile.dart b/lib/support/firefox_profile.dart index 370c7a0..8f3aa74 100644 --- a/lib/support/firefox_profile.dart +++ b/lib/support/firefox_profile.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.support.firefox_profile; - import 'dart:collection'; import 'dart:convert' show LineSplitter, base64; import 'dart:io' as io; @@ -222,7 +220,7 @@ class FirefoxProfile { /// It can be uses like /// `var desired = Capabilities.firefox..addAll(firefoxProfile.toJson()}` Map toJson() { - var archive = Archive(); + final archive = Archive(); if (profileDirectory != null) { profileDirectory!.listSync(recursive: true).forEach((f) { ArchiveFile archiveFile; @@ -234,7 +232,7 @@ class FirefoxProfile { return; } archiveFile = - ArchiveFile(name, f.statSync().size, (f).readAsBytesSync()); + ArchiveFile(name, f.statSync().size, f.readAsBytesSync()); } else { throw 'Invalid file type for file "${f.path}" ' '(${io.FileSystemEntity.typeSync(f.path)}).'; @@ -294,7 +292,7 @@ abstract class PrefsOption { if (valueString.startsWith('"') && valueString.endsWith('"')) { final value = valueString .substring(1, valueString.length - 1) - .replaceAll(r'\"', r'"') + .replaceAll(r'\"', '"') .replaceAll(r'\\', r'\'); return StringOption(name, value) as PrefsOption; } @@ -304,7 +302,7 @@ abstract class PrefsOption { return BooleanOption(name, false) as PrefsOption; } try { - var value = int.parse(valueString); + final value = int.parse(valueString); return IntegerOption(name, value) as PrefsOption; } catch (_) {} return InvalidOption('Not a valid prefs option: "$prefs".') @@ -340,7 +338,7 @@ class InvalidOption extends PrefsOption { /// A boolean preferences option with name and value. class BooleanOption extends PrefsOption { - BooleanOption(String name, bool value) : super._(name, value); + BooleanOption(super.name, bool super.value) : super._(); @override String get _valueAsPrefString => value.toString(); @@ -348,7 +346,7 @@ class BooleanOption extends PrefsOption { /// An integer preferences option with name and value. class IntegerOption extends PrefsOption { - IntegerOption(String name, int value) : super._(name, value); + IntegerOption(super.name, int super.value) : super._(); @override String get _valueAsPrefString => value.toString(); @@ -357,7 +355,7 @@ class IntegerOption extends PrefsOption { /// A String preferences option with name and value. /// [_valueAsPrefString] escapes `"` as `\"` and `\` as `\\`. class StringOption extends PrefsOption { - StringOption(String name, String value) : super._(name, value); + StringOption(super.name, String super.value) : super._(); static String _escape(String value) => value.replaceAll(r'\', r'\\').replaceAll('"', r'\"'); diff --git a/lib/support/stdio_stepper.dart b/lib/support/stdio_stepper.dart index 0d262b9..3758fe2 100644 --- a/lib/support/stdio_stepper.dart +++ b/lib/support/stdio_stepper.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.support.stdio_stepper; - import 'dart:async' show StreamController; import 'dart:convert' show Encoding, json; import 'dart:io' show exit, Stdin, stdin, systemEncoding; @@ -35,7 +33,7 @@ class StdioStepper implements Stepper { StdioStepper({LineReader? reader}) : _reader = reader ?? stdinLineReader; @override - Future step(String method, String command, params) async { + Future step(String method, String command, Object? params) async { if (!enabled) return true; print('$method $command(${json.encode(params)}):'); await for (String command in _reader.onLine) { diff --git a/lib/sync_core.dart b/lib/sync_core.dart index 5de6f1c..3c9d7f6 100644 --- a/lib/sync_core.dart +++ b/lib/sync_core.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.sync_core; - import 'dart:collection' show UnmodifiableMapView; import 'src/common/request_client.dart'; diff --git a/lib/sync_io.dart b/lib/sync_io.dart index a2bb6fb..797dc2a 100644 --- a/lib/sync_io.dart +++ b/lib/sync_io.dart @@ -12,10 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.sync_io; - import 'src/request/sync_http_request_client.dart'; - import 'sync_core.dart' as core show createDriver, fromExistingSession, WebDriver, WebDriverSpec; @@ -54,6 +51,5 @@ core.WebDriver fromExistingSession(String sessionId, {Uri? uri, core.WebDriverSpec spec = core.WebDriverSpec.Auto, Map? capabilities}) => - core.fromExistingSession( - sessionId, (prefix) => SyncHttpRequestClient(prefix), + core.fromExistingSession(sessionId, SyncHttpRequestClient.new, uri: uri, spec: spec, capabilities: capabilities); diff --git a/pubspec.yaml b/pubspec.yaml index 2ae95ce..7f8a883 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ name: webdriver -version: 3.0.1 +version: 3.0.2-dev description: >- Provides WebDriver bindings for Dart. Supports WebDriver JSON interface and W3C spec. Requires the use of WebDriver remote server. repository: https://github.com/google/webdriver.dart environment: - sdk: '>=2.14.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: archive: ^3.0.0 @@ -16,5 +16,5 @@ dependencies: sync_http: ^0.3.0 dev_dependencies: - lints: ^1.0.0 + lints: ^2.0.0 test: ^1.16.0 diff --git a/test/async_alert_test.dart b/test/async_alert_test.dart index e877821..cd26540 100644 --- a/test/async_alert_test.dart +++ b/test/async_alert_test.dart @@ -45,28 +45,28 @@ void main() { test('text', () async { await button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; expect(await alert.text, 'button clicked'); await alert.dismiss(); }); test('accept', () async { await button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; await alert.accept(); expect(await output.text, startsWith('accepted')); }); test('dismiss', () async { await button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; await alert.dismiss(); expect(await output.text, startsWith('dismissed')); }); test('sendKeys', () async { await button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; await alert.sendKeys('some keys'); await alert.accept(); expect(await output.text, endsWith('some keys')); diff --git a/test/async_command_event_test.dart b/test/async_command_event_test.dart index f27cac6..f518ca6 100644 --- a/test/async_command_event_test.dart +++ b/test/async_command_event_test.dart @@ -25,7 +25,7 @@ void main() { group('CommandEvent', () { late WebDriver driver; - var events = []; + final events = []; setUp(() async { driver = await config.createTestDriver(); diff --git a/test/async_logs_test.dart b/test/async_logs_test.dart index 3caa7bc..3cce53d 100644 --- a/test/async_logs_test.dart +++ b/test/async_logs_test.dart @@ -25,7 +25,7 @@ void main() { late WebDriver driver; setUp(() async { - var capabilities = { + final capabilities = { // ignore: deprecated_member_use_from_same_package Capabilities.loggingPrefs: {LogType.performance: LogLevel.info} }; @@ -36,7 +36,7 @@ void main() { }); test('get logs', () async { - var logs = await driver.logs.get(LogType.performance).toList(); + final logs = await driver.logs.get(LogType.performance).toList(); if (driver.capabilities['browserName'] == 'firefox') { expect(logs, isEmpty); return; diff --git a/test/async_mouse_test.dart b/test/async_mouse_test.dart index 08c05c9..05f006d 100644 --- a/test/async_mouse_test.dart +++ b/test/async_mouse_test.dart @@ -54,7 +54,7 @@ void main() { }); test('moveTo coordinates/click', () async { - var pos = await button.location; + final pos = await button.location; await driver.mouse.moveTo(xOffset: pos.x + 5, yOffset: pos.y + 5); expect(await mouseOnButton(), true); }); @@ -94,7 +94,7 @@ void main() { test('hide moves to given location in w3c.', () async { if (driver.spec == WebDriverSpec.W3c) { - var pos = await button.location; + final pos = await button.location; await driver.mouse.moveTo(element: button); expect(await mouseOnButton(), true); await driver.mouse.moveTo(xOffset: 0, yOffset: 0, absolute: true); diff --git a/test/async_navigation_test.dart b/test/async_navigation_test.dart index a684080..31e8a38 100644 --- a/test/async_navigation_test.dart +++ b/test/async_navigation_test.dart @@ -31,7 +31,7 @@ void main() { }); test('refresh', () async { - var element = await driver.findElement(const By.tagName('button')); + final element = await driver.findElement(const By.tagName('button')); await driver.refresh(); await waitFor(() async { try { diff --git a/test/async_web_driver_test.dart b/test/async_web_driver_test.dart index 6303f05..59dfb99 100644 --- a/test/async_web_driver_test.dart +++ b/test/async_web_driver_test.dart @@ -18,7 +18,7 @@ library webdriver.web_driver_test; import 'dart:async'; import 'package:test/test.dart'; -import 'package:webdriver/core.dart'; +import 'package:webdriver/async_core.dart'; import 'configs/async_io_config.dart' as config; @@ -26,9 +26,9 @@ void main() { group('WebDriver', () { group('create', () { test('default', () async { - var driver = await config.createTestDriver(); + final driver = await config.createTestDriver(); await config.createTestServerAndGoToTestPage(driver); - var element = await driver.findElement(const By.tagName('button')); + final element = await driver.findElement(const By.tagName('button')); expect(await element.name, 'button'); }); }); @@ -46,13 +46,13 @@ void main() { }); test('currentUrl', () async { - var url = await driver.currentUrl; + final url = await driver.currentUrl; expect(url, anyOf(startsWith('file:'), startsWith('http:'))); expect(url, endsWith('test_page.html')); }); test('findElement -- success', () async { - var element = await driver.findElement(const By.tagName('tr')); + final element = await driver.findElement(const By.tagName('tr')); expect(element, config.isWebElement); }); @@ -66,7 +66,7 @@ void main() { }); test('findElements -- 1 found', () async { - var elements = await driver + final elements = await driver .findElements(const By.cssSelector('input[type=text]')) .toList(); expect(elements, hasLength(1)); @@ -74,14 +74,14 @@ void main() { }); test('findElements -- 4 found', () async { - var elements = + final elements = await driver.findElements(const By.tagName('td')).toList(); expect(elements, hasLength(4)); expect(elements, everyElement(config.isWebElement)); }); test('findElements -- 0 found', () async { - var elements = + final elements = await driver.findElements(const By.id('non-existent-id')).toList(); expect(elements, isEmpty); }); @@ -91,7 +91,7 @@ void main() { }); test('close/windows', () async { - var numHandles = (await driver.windows.toList()).length; + final numHandles = (await driver.windows.toList()).length; await (await driver.findElement(const By.partialLinkText('Open copy'))) .click(); expect(await driver.windows.toList(), hasLength(numHandles + 1)); @@ -100,7 +100,7 @@ void main() { }); test('window', () async { - var orig = await driver.window; + final orig = await driver.window; Window? next; await (await driver.findElement(const By.partialLinkText('Open copy'))) @@ -127,65 +127,66 @@ void main() { }); test('windows', () async { - var windows = await driver.windows.toList(); + final windows = await driver.windows.toList(); expect(windows, hasLength(isPositive)); expect(windows, everyElement(isA())); }); test('execute', () async { - var button = await driver.findElement(const By.tagName('button')); - var script = ''' + final button = await driver.findElement(const By.tagName('button')); + const script = ''' arguments[1].textContent = arguments[0]; return arguments[1];'''; - var e = await driver.execute(script, ['new text', button]); + final e = await driver.execute(script, ['new text', button]); expect(await e.text, 'new text'); }); test('executeAsync', () async { - var button = await driver.findElement(const By.tagName('button')); - var script = ''' + final button = await driver.findElement(const By.tagName('button')); + const script = ''' arguments[1].textContent = arguments[0]; arguments[2](arguments[1]);'''; - var e = await driver.executeAsync(script, ['new text', button]); + final e = await driver.executeAsync(script, ['new text', button]); expect(await e.text, 'new text'); }); test('captureScreenshot', () async { // ignore: deprecated_member_use_from_same_package - var screenshot = await driver.captureScreenshot().toList(); + final screenshot = await driver.captureScreenshot().toList(); expect(screenshot, hasLength(isPositive)); expect(screenshot, everyElement(isA())); }); test('captureScreenshotAsList', () async { - var screenshot = await driver.captureScreenshotAsList(); + final screenshot = await driver.captureScreenshotAsList(); expect(screenshot, hasLength(isPositive)); expect(screenshot, everyElement(const TypeMatcher())); }); test('captureElementScreenshotAsList', () async { - var element = await driver.findElement(const By.tagName('tr')); - var screenshot = await driver.captureElementScreenshotAsList(element); + final element = await driver.findElement(const By.tagName('tr')); + final screenshot = await driver.captureElementScreenshotAsList(element); expect(screenshot, hasLength(isPositive)); expect(screenshot, everyElement(const TypeMatcher())); }); test('captureScreenshotAsBase64', () async { - var screenshot = await driver.captureScreenshotAsBase64(); + final screenshot = await driver.captureScreenshotAsBase64(); expect(screenshot, hasLength(isPositive)); expect(screenshot, const TypeMatcher()); }); test('captureElementScreenshotAsBase64', () async { - var element = await driver.findElement(const By.tagName('tr')); - var screenshot = await driver.captureElementScreenshotAsBase64(element); + final element = await driver.findElement(const By.tagName('tr')); + final screenshot = + await driver.captureElementScreenshotAsBase64(element); expect(screenshot, hasLength(isPositive)); expect(screenshot, const TypeMatcher()); }); test('future based event listeners work with script timeouts', () async { driver.addEventListener((WebDriverCommandEvent e) async => - await Future.delayed(const Duration(milliseconds: 1000), (() {}))); + await Future.delayed(const Duration(milliseconds: 1000), () {})); try { await driver.timeouts.setScriptTimeout(const Duration(seconds: 1)); @@ -197,14 +198,14 @@ void main() { }); test('future based event listeners ordered appropriately', () async { - var eventList = []; + final eventList = []; var millisDelay = 2000; var current = 0; driver.addEventListener((WebDriverCommandEvent e) async => - await Future.delayed(Duration(milliseconds: millisDelay), (() { + await Future.delayed(Duration(milliseconds: millisDelay), () { eventList.add(current++); millisDelay = (millisDelay / 2).round(); - }))); + })); for (var i = 0; i < 10; i++) { await driver.title; // GET request. diff --git a/test/async_web_element_test.dart b/test/async_web_element_test.dart index 1247278..c0a2b39 100644 --- a/test/async_web_element_test.dart +++ b/test/async_web_element_test.dart @@ -53,13 +53,13 @@ void main() { test('click', () async { await button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; await alert.accept(); }); test('submit', () async { await formSubmit.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; expect(await alert.text, 'form submitted'); await alert.accept(); }); @@ -96,28 +96,28 @@ void main() { }); test('location -- table', () async { - var location = await table.location; + final location = await table.location; expect(location, config.isPoint); expect(location.x, isNonNegative); expect(location.y, isNonNegative); }); test('location -- invisible', () async { - var location = await invisible.location; + final location = await invisible.location; expect(location, config.isPoint); expect(location.x, 0); expect(location.y, 0); }); test('size -- table', () async { - var size = await table.size; + final size = await table.size; expect(size, config.isRectangle); expect(size.width, isNonNegative); expect(size.height, isNonNegative); }); test('size -- invisible', () async { - var size = await invisible.size; + final size = await invisible.size; expect(size, config.isRectangle); expect(size.width, isNonNegative); expect(size.height, isNonNegative); @@ -137,7 +137,7 @@ void main() { }); test('findElement -- success', () async { - var element = await table.findElement(const By.tagName('tr')); + final element = await table.findElement(const By.tagName('tr')); expect(element, config.isWebElement); }); @@ -151,7 +151,7 @@ void main() { }); test('findElements -- 1 found', () async { - var elements = await form + final elements = await form .findElements(const By.cssSelector('input[type=text]')) .toList(); expect(elements, hasLength(1)); @@ -159,13 +159,14 @@ void main() { }); test('findElements -- 4 found', () async { - var elements = await table.findElements(const By.tagName('td')).toList(); + final elements = + await table.findElements(const By.tagName('td')).toList(); expect(elements, hasLength(4)); expect(elements, everyElement(config.isWebElement)); }); test('findElements -- 0 found', () async { - var elements = await form.findElements(const By.tagName('td')).toList(); + final elements = await form.findElements(const By.tagName('td')).toList(); expect(elements, isEmpty); }); @@ -186,7 +187,7 @@ void main() { test('equals', () async { expect(await invisible.equals(disabled), isFalse); - var element = await driver.findElement(const By.cssSelector('table')); + final element = await driver.findElement(const By.cssSelector('table')); expect(await element.equals(table), isTrue); }); }, timeout: const Timeout(Duration(minutes: 2))); diff --git a/test/async_window_test.dart b/test/async_window_test.dart index d124590..6ea476e 100644 --- a/test/async_window_test.dart +++ b/test/async_window_test.dart @@ -33,8 +33,8 @@ void main() { }); test('size', () async { - var window = await driver.window; - var size = const Rectangle(0, 0, 600, 400); + final window = await driver.window; + const size = Rectangle(0, 0, 600, 400); // Firefox may take a bit longer to do the resize. await Future.delayed(const Duration(seconds: 1)); @@ -43,15 +43,15 @@ void main() { }); test('location', () async { - var window = await driver.window; - var position = const Point(100, 200); + final window = await driver.window; + const position = Point(100, 200); await window.setLocation(position); expect(await window.location, position); }); // May not work on some OS/browser combinations (notably Mac OS X). test('maximize', () async { - var window = await driver.window; + final window = await driver.window; await window.setSize(const Rectangle(0, 0, 300, 200)); await window.setLocation(const Point(100, 200)); await window.maximize(); @@ -60,8 +60,8 @@ void main() { await waitFor(() async => (await window.size).height, matcher: greaterThan(200)); - var location = await window.location; - var size = await window.size; + final location = await window.location; + final size = await window.size; // Changed from `lessThan(100)` to pass the test on Mac. expect(location.x, lessThanOrEqualTo(100)); expect(location.y, lessThan(200)); diff --git a/test/configs/async_io_config.dart b/test/configs/async_io_config.dart index fd45010..e42175f 100644 --- a/test/configs/async_io_config.dart +++ b/test/configs/async_io_config.dart @@ -24,7 +24,7 @@ import 'common_config.dart'; export 'common_config.dart'; -final Matcher isWebElement = const TypeMatcher(); +const Matcher isWebElement = TypeMatcher(); Future createTestDriver({ Map? additionalCapabilities, @@ -52,8 +52,8 @@ Future createTestServerAndGoToTestPage(WebDriver driver) async { final server = await createLocalServer(); server.listen((request) { if (request.method == 'GET' && request.uri.path.endsWith('.html')) { - var testPagePath = '$testHomePath${request.uri.path}'; - var file = File(testPagePath); + final testPagePath = '$testHomePath${request.uri.path}'; + final file = File(testPagePath); if (file.existsSync()) { request.response ..statusCode = HttpStatus.ok diff --git a/test/configs/common_config.dart b/test/configs/common_config.dart index c292065..dd1778d 100644 --- a/test/configs/common_config.dart +++ b/test/configs/common_config.dart @@ -25,8 +25,8 @@ final Uri _defaultFirefoxUri = Uri.parse('http://127.0.0.1:4445/'); const WebDriverSpec defaultSpec = WebDriverSpec.JsonWire; -final Matcher isRectangle = const TypeMatcher>(); -final Matcher isPoint = const TypeMatcher>(); +const Matcher isRectangle = TypeMatcher>(); +const Matcher isPoint = TypeMatcher>(); Future createLocalServer() => HttpServer.bind(InternetAddress.anyIPv4, 0); @@ -51,17 +51,17 @@ Map getCapabilities(WebDriverSpec spec) { case WebDriverSpec.W3c: return Capabilities.firefox; case WebDriverSpec.JsonWire: - var capabilities = Capabilities.chrome; - Map env = Platform.environment; + final capabilities = Capabilities.chrome; + final env = Platform.environment; - var chromeOptions = {}; + final chromeOptions = {}; if (env['CHROMEDRIVER_BINARY'] != null) { chromeOptions['binary'] = env['CHROMEDRIVER_BINARY']; } if (env['CHROMEDRIVER_ARGS'] != null) { - chromeOptions['args'] = env['CHROMEDRIVER_ARGS'].split(' '); + chromeOptions['args'] = env['CHROMEDRIVER_ARGS']!.split(' '); } if (chromeOptions.isNotEmpty) { diff --git a/test/configs/sync_io_config.dart b/test/configs/sync_io_config.dart index 3fdef80..729aa95 100644 --- a/test/configs/sync_io_config.dart +++ b/test/configs/sync_io_config.dart @@ -25,7 +25,7 @@ import 'common_config.dart'; export 'common_config.dart'; -final Matcher isWebElement = const TypeMatcher(); +const Matcher isWebElement = TypeMatcher(); WebDriver createTestDriver({ Map? additionalCapabilities, @@ -51,8 +51,8 @@ Future createTestServerAndGoToTestPage(WebDriver driver) async { final server = await createLocalServer(); server.listen((request) { if (request.method == 'GET' && request.uri.path.endsWith('.html')) { - var testPagePath = '$testHomePath${request.uri.path}'; - var file = File(testPagePath); + final testPagePath = '$testHomePath${request.uri.path}'; + final file = File(testPagePath); if (file.existsSync()) { request.response ..statusCode = HttpStatus.ok diff --git a/test/support/async_test.dart b/test/support/async_test.dart index 7f63323..a9e245a 100644 --- a/test/support/async_test.dart +++ b/test/support/async_test.dart @@ -22,7 +22,7 @@ import 'package:webdriver/support/async.dart'; void main() { group('Lock', () { test('basic acquire/release', () async { - var lock = Lock(); + final lock = Lock(); expect(lock.isHeld, isFalse); await lock.acquire(); expect(lock.isHeld, isTrue); @@ -34,12 +34,12 @@ void main() { }); test('release without acquiring fails', () { - var lock = Lock(); - expect(() => lock.release(), throwsA(isA())); + final lock = Lock(); + expect(lock.release, throwsA(isA())); }); test('locking prevents acquisition of lock', () async { - var lock = Lock(); + final lock = Lock(); var secondLockAcquired = false; await lock.acquire(); unawaited(lock.acquire().then((_) => secondLockAcquired = true)); @@ -53,7 +53,7 @@ void main() { }); test('awaitChecking throws exception on acquire of held lock', () async { - var lock = Lock(awaitChecking: true); + final lock = Lock(awaitChecking: true); await lock.acquire(); expect(lock.acquire(), throwsA(anything)); lock.release(); @@ -63,11 +63,11 @@ void main() { }); group('Clock.waitFor', () { - var clock = FakeClock(); + final clock = FakeClock(); test('that returns a string', () async { var count = 0; - var result = await clock.waitFor(() { + final result = await clock.waitFor(() { if (count == 2) return 'webdriver - Google Search'; count++; return count; @@ -78,7 +78,7 @@ void main() { test('that returns null', () async { var count = 0; - var result = await clock.waitFor(() { + final result = await clock.waitFor(() { if (count == 2) return null; count++; return count; @@ -88,7 +88,7 @@ void main() { test('that returns false', () async { var count = 0; - var result = await clock.waitFor(() { + final result = await clock.waitFor(() { if (count == 2) return false; count++; return count; @@ -98,7 +98,7 @@ void main() { test('that returns a string, default matcher', () async { var count = 0; - var result = await clock.waitFor(() { + final result = await clock.waitFor(() { if (count == 2) return 'Google'; count++; throw ''; @@ -128,7 +128,7 @@ void main() { }); test('uses Future value', () async { - var result = await clock.waitFor(() => Future.value('a value'), + final result = await clock.waitFor(() => Future.value('a value'), matcher: 'a value'); expect(result, 'a value'); }); @@ -145,9 +145,9 @@ void main() { }); test('sanity test with real Clock -- successful', () async { - var clock = const Clock(); + const clock = Clock(); var count = 0; - var result = await clock.waitFor(() { + final result = await clock.waitFor(() { if (count < 2) { count++; return null; @@ -159,7 +159,7 @@ void main() { }); test('sanity test with real Clock -- throws', () async { - var clock = const Clock(); + const clock = Clock(); Object? exception; try { await clock.waitFor(() => throw 'an exception'); @@ -170,7 +170,7 @@ void main() { }); test('sanity test with real Clock -- never matches', () async { - var clock = const Clock(); + const clock = Clock(); Object? exception; try { await clock.waitFor(() => null, matcher: isNotNull); diff --git a/test/support/firefox_profile_test.dart b/test/support/firefox_profile_test.dart index ece45ef..4fdc5bf 100644 --- a/test/support/firefox_profile_test.dart +++ b/test/support/firefox_profile_test.dart @@ -27,65 +27,65 @@ import 'package:webdriver/support/firefox_profile.dart'; void main() { group('Firefox profile', () { test('parse and serialize string value with quotes', () { - const value = - r'user_pref("extensions.xpiState", "{\"app-global\":{\"{972ce4c6-' + const value = r'user_pref("extensions.xpiState", ' + r'"{\"app-global\":{\"{972ce4c6-' r'7e08-4474-a285-3208198ce6fd}\":{\"d\":\"/opt/firefox/browser/' r'extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}\",\"e\":true,\' r'"v\":\"40.0\",\"st\":1439535413000,\"mt\":1438968709000}}}");'; - var option = PrefsOption.parse(value); + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.asPrefString, value); }); test('parse and serialize string value with backslash', () { - const value = r'user_pref("browser.cache.disk.parent_directory", ' + const value = 'user_pref("browser.cache.disk.parent_directory", ' r'"\\\\volume\\web\\cache\\mz");'; - var option = PrefsOption.parse(value); + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.asPrefString, value); }); test('parse and serialize integer value', () { - const value = r'user_pref("browser.cache.frecency_experiment", 3);'; - var option = PrefsOption.parse(value); + const value = 'user_pref("browser.cache.frecency_experiment", 3);'; + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.asPrefString, value); }); test('parse and serialize negative integer value', () { - const value = r'user_pref("browser.cache.frecency_experiment", -3);'; - var option = PrefsOption.parse(value); + const value = 'user_pref("browser.cache.frecency_experiment", -3);'; + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.asPrefString, value); }); test('parse and serialize boolean true', () { const value = - r'user_pref("browser.cache.disk.smart_size.first_run", true);'; - var option = PrefsOption.parse(value); + 'user_pref("browser.cache.disk.smart_size.first_run", true);'; + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.asPrefString, value); }); test('parse and serialize boolean false', () { const value = - r'user_pref("browser.cache.disk.smart_size.first_run", false);'; - var option = PrefsOption.parse(value); + 'user_pref("browser.cache.disk.smart_size.first_run", false);'; + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.asPrefString, value); }); test('parse boolean uppercase True', () { const value = - r'user_pref("browser.cache.disk.smart_size.first_run", True);'; - var option = PrefsOption.parse(value); + 'user_pref("browser.cache.disk.smart_size.first_run", True);'; + final option = PrefsOption.parse(value); expect(option, isA()); expect(option.value, true); }); test('added value should be in prefs', () { - var profile = FirefoxProfile(); - var option = + final profile = FirefoxProfile(); + final option = PrefsOption('browser.bookmarks.restore_default_bookmarks', false); expect(profile.setOption(option), true); @@ -97,9 +97,9 @@ void main() { }); test('overriding locked value should be ignored', () { - var profile = FirefoxProfile(); - var lockedOption = PrefsOption('javascript.enabled', false); - var lockedOptionOrig = + final profile = FirefoxProfile(); + final lockedOption = PrefsOption('javascript.enabled', false); + final lockedOptionOrig = profile.prefs.firstWhere((e) => e.name == lockedOption.name); expect(lockedOption.value, isNot(lockedOptionOrig.value)); @@ -111,9 +111,9 @@ void main() { }); test('removing locked value should be ignored', () { - var profile = FirefoxProfile(); - var lockedOption = PrefsOption('javascript.enabled', false); - var lockedOptionOrig = + final profile = FirefoxProfile(); + final lockedOption = PrefsOption('javascript.enabled', false); + final lockedOptionOrig = profile.prefs.firstWhere((e) => e.name == lockedOption.name); expect(lockedOption.value, isNot(lockedOptionOrig.value)); @@ -125,20 +125,20 @@ void main() { }); test('encode/decode "user.js" in-memory', () { - var profile = FirefoxProfile(); + final profile = FirefoxProfile(); // ignore: deprecated_member_use_from_same_package profile.setOption(PrefsOption(Capabilities.hasNativeEvents, true)); - var archive = unpackArchiveData(profile.toJson()); + final archive = unpackArchiveData(profile.toJson()); - var expectedFiles = ['prefs.js', 'user.js']; + final expectedFiles = ['prefs.js', 'user.js']; expect(archive.files.length, greaterThanOrEqualTo(expectedFiles.length)); expect( archive.files, anyElement((ArchiveFile f) => f.name == 'prefs.js'), ); - var prefs = FirefoxProfile.loadPrefsFile(MockFile( + final prefs = FirefoxProfile.loadPrefsFile(MockFile( String.fromCharCodes( archive.files.firstWhere((f) => f.name == 'user.js').content as List, @@ -155,14 +155,14 @@ void main() { }); test('encode/decode profile directory from disk', () { - var profile = FirefoxProfile( + final profile = FirefoxProfile( profileDirectory: io.Directory('test/support/firefox_profile')); // ignore: deprecated_member_use_from_same_package profile.setOption(PrefsOption(Capabilities.hasNativeEvents, true)); - var archive = unpackArchiveData(profile.toJson()); + final archive = unpackArchiveData(profile.toJson()); - var expectedFiles = [ + final expectedFiles = [ 'prefs.js', 'user.js', 'addons.js', @@ -175,7 +175,7 @@ void main() { anyElement((ArchiveFile f) => f.name == 'prefs.js'), ); - var prefs = FirefoxProfile.loadPrefsFile( + final prefs = FirefoxProfile.loadPrefsFile( MockFile( String.fromCharCodes( archive.files.firstWhere((f) => f.name == 'user.js').content @@ -196,7 +196,7 @@ void main() { } Archive unpackArchiveData(Map profileData) { - var zipArchive = base64.decode(profileData['firefox_profile'] as String); + final zipArchive = base64.decode(profileData['firefox_profile'] as String); return ZipDecoder().decodeBytes(zipArchive, verify: true); } diff --git a/test/sync/alert.dart b/test/sync/alert.dart index e2a6ace..ce584f6 100644 --- a/test/sync/alert.dart +++ b/test/sync/alert.dart @@ -45,28 +45,28 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { test('text', () { button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; expect(alert.text, 'button clicked'); alert.dismiss(); }); test('accept', () { button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; alert.accept(); expect(output.text, startsWith('accepted')); }); test('dismiss', () { button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; alert.dismiss(); expect(output.text, startsWith('dismissed')); }); test('sendKeys', () { button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; alert.sendKeys('some keys'); alert.accept(); expect(output.text, endsWith('some keys')); diff --git a/test/sync/command_event.dart b/test/sync/command_event.dart index 8bad594..7056785 100644 --- a/test/sync/command_event.dart +++ b/test/sync/command_event.dart @@ -25,7 +25,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { group('CommandEvent', () { late WebDriver driver; - var events = []; + final events = []; setUp(() async { driver = config.createTestDriver(spec: spec); diff --git a/test/sync/logs.dart b/test/sync/logs.dart index 4ccbd22..339f405 100644 --- a/test/sync/logs.dart +++ b/test/sync/logs.dart @@ -25,7 +25,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { late WebDriver driver; setUp(() async { - var capabilities = { + final capabilities = { // ignore: deprecated_member_use_from_same_package Capabilities.loggingPrefs: {LogType.performance: LogLevel.info} }; @@ -38,7 +38,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('get logs', () { - var logs = driver.logs.get(LogType.performance).toList(); + final logs = driver.logs.get(LogType.performance).toList(); if (driver.capabilities['browserName'] == 'firefox') { expect(logs, isEmpty); return; diff --git a/test/sync/mouse.dart b/test/sync/mouse.dart index d60a411..ada7453 100644 --- a/test/sync/mouse.dart +++ b/test/sync/mouse.dart @@ -51,14 +51,14 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('moveTo coordinates/click', () { - var pos = button.location; + final pos = button.location; driver.mouse.moveTo(xOffset: pos.x + 5, yOffset: pos.y + 5); expect(mouseOnButton(), true); }); test('moveTo absolute coordinates/click', () { if (driver.spec == WebDriverSpec.W3c) { - var pos = button.location; + final pos = button.location; driver.mouse.moveTo(xOffset: pos.x + 200, yOffset: pos.y + 200); expect(mouseOnButton(), false); driver.mouse @@ -113,7 +113,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { test('hide moves to given location in w3c.', () { if (driver.spec == WebDriverSpec.W3c) { - var pos = button.location; + final pos = button.location; driver.mouse.moveTo(element: button); expect(mouseOnButton(), true); driver.mouse.moveTo(xOffset: 0, yOffset: 0, absolute: true); @@ -128,7 +128,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { driver.mouse.moveTo(element: button); driver.mouse.down(); driver.mouse.up(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; alert.dismiss(); }); @@ -136,7 +136,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { test('doubleClick', () { driver.mouse.moveTo(element: button); driver.mouse.doubleClick(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; alert.dismiss(); }); }, timeout: const Timeout(Duration(minutes: 2))); diff --git a/test/sync/navigation.dart b/test/sync/navigation.dart index 857be04..a2794f4 100644 --- a/test/sync/navigation.dart +++ b/test/sync/navigation.dart @@ -30,7 +30,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('refresh', () async { - var element = driver.findElement(const By.tagName('button')); + final element = driver.findElement(const By.tagName('button')); // TODO(b/140553567): Use sync driver when we have a separate server. await driver.asyncDriver.refresh(); try { diff --git a/test/sync/spec_inference_test.dart b/test/sync/spec_inference_test.dart index 156edf4..0a841d4 100644 --- a/test/sync/spec_inference_test.dart +++ b/test/sync/spec_inference_test.dart @@ -38,7 +38,7 @@ void main() { }, tags: ['ff']); test('firefox work', () async { - driver = config.createTestDriver(spec: WebDriverSpec.JsonWire); + driver = config.createTestDriver(); await config.createTestServerAndGoToTestPage(driver); final button = driver.findElement(const By.tagName('button')); try { diff --git a/test/sync/web_driver.dart b/test/sync/web_driver.dart index 10c3b37..79e9be9 100644 --- a/test/sync/web_driver.dart +++ b/test/sync/web_driver.dart @@ -26,9 +26,9 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { group('WebDriver', () { group('create', () { test('default', () async { - var driver = config.createTestDriver(spec: spec); + final driver = config.createTestDriver(spec: spec); await config.createTestServerAndGoToTestPage(driver); - var element = driver.findElement(const By.tagName('button')); + final element = driver.findElement(const By.tagName('button')); expect(element.name, 'button'); }); }); @@ -46,14 +46,14 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('currentUrl', () { - var url = driver.currentUrl; + final url = driver.currentUrl; expect(url, startsWith('http:')); expect(url, endsWith('test_page.html')); }); test('findElement -- success', () { - var element = driver.findElement(const By.tagName('tr')); + final element = driver.findElement(const By.tagName('tr')); expect(element, config.isWebElement); }); @@ -67,7 +67,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('findElements -- 1 found', () { - var elements = driver + final elements = driver .findElements(const By.cssSelector('input[type=text]')) .toList(); expect(elements, hasLength(1)); @@ -75,13 +75,13 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('findElements -- 4 found', () { - var elements = driver.findElements(const By.tagName('td')).toList(); + final elements = driver.findElements(const By.tagName('td')).toList(); expect(elements, hasLength(4)); expect(elements, everyElement(config.isWebElement)); }); test('findElements -- 0 found', () { - var elements = + final elements = driver.findElements(const By.id('non-existent-id')).toList(); expect(elements, isEmpty); }); @@ -95,7 +95,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('close/windows', () { - var numHandles = (driver.windows.toList()).length; + final numHandles = (driver.windows.toList()).length; (driver.findElement(const By.partialLinkText('Open copy'))).click(); sleep(const Duration(milliseconds: 500)); // Bit slow on Firefox. expect(driver.windows.toList(), hasLength(numHandles + 1)); @@ -104,7 +104,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('window', () { - var orig = driver.window; + final orig = driver.window; Window? next; (driver.findElement(const By.partialLinkText('Open copy'))).click(); @@ -129,57 +129,57 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('windows', () { - var windows = driver.windows.toList(); + final windows = driver.windows.toList(); expect(windows, hasLength(isPositive)); expect(windows, everyElement(isA())); }); test('execute', () { - var button = driver.findElement(const By.tagName('button')); - var script = ''' + final button = driver.findElement(const By.tagName('button')); + const script = ''' arguments[1].textContent = arguments[0]; return arguments[1];'''; - var e = driver.execute(script, ['new text', button]); + final e = driver.execute(script, ['new text', button]); expect(e.text, 'new text'); }); test('executeAsync', () { - var button = driver.findElement(const By.tagName('button')); - var script = ''' + final button = driver.findElement(const By.tagName('button')); + const script = ''' arguments[1].textContent = arguments[0]; arguments[2](arguments[1]);'''; - var e = driver.executeAsync(script, ['new text', button]); + final e = driver.executeAsync(script, ['new text', button]); expect(e.text, 'new text'); }); test('captureScreenshot', () { - var screenshot = driver.captureScreenshotAsList().toList(); + final screenshot = driver.captureScreenshotAsList().toList(); expect(screenshot, hasLength(isPositive)); expect(screenshot, everyElement(isA())); }); test('captureScreenshotAsList', () { - var screenshot = driver.captureScreenshotAsList(); + final screenshot = driver.captureScreenshotAsList(); expect(screenshot, hasLength(isPositive)); expect(screenshot, everyElement(isA())); }); test('captureElementScreenshotAsList', () { - var element = driver.findElement(const By.tagName('tr')); - var screenshot = driver.captureElementScreenshotAsList(element); + final element = driver.findElement(const By.tagName('tr')); + final screenshot = driver.captureElementScreenshotAsList(element); expect(screenshot, hasLength(isPositive)); expect(screenshot, everyElement(isA())); }); test('captureScreenshotAsBase64', () { - var screenshot = driver.captureScreenshotAsBase64(); + final screenshot = driver.captureScreenshotAsBase64(); expect(screenshot, hasLength(isPositive)); expect(screenshot, isA()); }); test('captureElementScreenshotAsBase64', () { - var element = driver.findElement(const By.tagName('tr')); - var screenshot = driver.captureElementScreenshotAsBase64(element); + final element = driver.findElement(const By.tagName('tr')); + final screenshot = driver.captureElementScreenshotAsBase64(element); expect(screenshot, hasLength(isPositive)); expect(screenshot, isA()); }); @@ -195,7 +195,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('event listeners ordered appropriately', () { - var eventList = []; + final eventList = []; var current = 0; driver.addEventListener((e) { eventList.add(current++); diff --git a/test/sync/web_element.dart b/test/sync/web_element.dart index ed035c8..d1ff061 100644 --- a/test/sync/web_element.dart +++ b/test/sync/web_element.dart @@ -52,13 +52,13 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { test('click', () { button.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; alert.accept(); }); test('submit', () { formSubmit.click(); - var alert = driver.switchTo.alert; + final alert = driver.switchTo.alert; expect(alert.text, 'form submitted'); alert.accept(); }); @@ -95,7 +95,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('rect -- table', () { - var rect = table.rect; + final rect = table.rect; expect(rect, config.isRectangle); expect(rect.left, isNonNegative); expect(rect.top, isNonNegative); @@ -104,7 +104,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('rect -- invisible', () { - var rect = invisible.rect; + final rect = invisible.rect; expect(rect, config.isRectangle); expect(rect.left, 0); expect(rect.top, 0); @@ -113,28 +113,28 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('location -- table', () { - var location = table.location; + final location = table.location; expect(location, config.isPoint); expect(location.x, isNonNegative); expect(location.y, isNonNegative); }); test('location -- invisible', () { - var location = invisible.location; + final location = invisible.location; expect(location, config.isPoint); expect(location.x, 0); expect(location.y, 0); }); test('size -- table', () { - var size = table.size; + final size = table.size; expect(size, config.isRectangle); expect(size.width, isNonNegative); expect(size.height, isNonNegative); }); test('size -- invisible', () { - var size = invisible.size; + final size = invisible.size; expect(size, config.isRectangle); expect(size.width, isNonNegative); expect(size.height, isNonNegative); @@ -154,7 +154,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('findElement -- success', () { - var element = table.findElement(const By.tagName('tr')); + final element = table.findElement(const By.tagName('tr')); expect(element, config.isWebElement); }); @@ -168,20 +168,20 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('findElements -- 1 found', () { - var elements = + final elements = form.findElements(const By.cssSelector('input[type=text]')).toList(); expect(elements, hasLength(1)); expect(elements, everyElement(config.isWebElement)); }); test('findElements -- 4 found', () { - var elements = table.findElements(const By.tagName('td')).toList(); + final elements = table.findElements(const By.tagName('td')).toList(); expect(elements, hasLength(4)); expect(elements, everyElement(config.isWebElement)); }); test('findElements -- 0 found', () { - var elements = form.findElements(const By.tagName('td')).toList(); + final elements = form.findElements(const By.tagName('td')).toList(); expect(elements, isEmpty); }); @@ -202,7 +202,7 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { test('equals', () { expect(invisible.equals(disabled), isFalse); - var element = driver.findElement(const By.cssSelector('table')); + final element = driver.findElement(const By.cssSelector('table')); expect(element.equals(table), isTrue); }); diff --git a/test/sync/window.dart b/test/sync/window.dart index bee3b07..830613e 100644 --- a/test/sync/window.dart +++ b/test/sync/window.dart @@ -32,8 +32,8 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { }); test('size', () { - var window = driver.window; - var windowRect = const Rectangle(0, 0, 600, 400); + final window = driver.window; + const windowRect = Rectangle(0, 0, 600, 400); window.rect = windowRect; // Firefox may take a bit longer to do the resize. @@ -50,12 +50,12 @@ void runTests({WebDriverSpec spec = WebDriverSpec.Auto}) { // May not work on some OS/browser combinations (notably Mac OS X). test('maximize', () { - var window = driver.window; - final windowRect = const Rectangle(100, 200, 300, 300); + final window = driver.window; + const windowRect = Rectangle(100, 200, 300, 300); window.rect = windowRect; window.maximize(); - var finalRect = window.rect; + final finalRect = window.rect; expect(finalRect.width, greaterThan(300)); expect(finalRect.height, greaterThan(300)); }, skip: 'Unreliable on Travis');