Skip to content

Allow Developers to enable Accessibility testing on WebFlutterDriver and get the underlying webDriver#65051

Merged
fluttergithubbot merged 6 commits intoflutter:masterfrom
angjieli:a11y
Sep 8, 2020
Merged

Allow Developers to enable Accessibility testing on WebFlutterDriver and get the underlying webDriver#65051
fluttergithubbot merged 6 commits intoflutter:masterfrom
angjieli:a11y

Conversation

@angjieli
Copy link
Contributor

@angjieli angjieli commented Sep 1, 2020

Description

Allow Developers to enable Accessibility testing on WebFlutterDriver and get the underlying webDriver.

Tests

I added the following tests:

  • Test to verify that VMServiceFlutterDriver would throw UnsupportedError when invoking enableAccessibility() and webDriver.

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@angjieli angjieli requested a review from nturgut September 1, 2020 21:20
@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Sep 1, 2020
/// Enables accessibility feature.
Future<void> enableAccessibility() async {
throw UnimplementedError();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we add a message to the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline. Will follow existing pattern and do not add message to UnimplementedError.

VMServiceClient get serviceClient => throw UnimplementedError();

/// Getter of webDriver.
async_io.WebDriver get webDriver => throw UnimplementedError();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we add a message to the error here as well? Also a comment on why we add this method. (Sorry the serviceClient also doesn't have it, but I thought it might be useful in the future to the readers of this code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the comment below.

'document.querySelector(\'flt-semantics-placeholder\').click();',
<String>[]);
_accessibilityEnabled = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few things we need to do here.
(1) This only works for desktop web (mobile web has another method which is very similar to this)
(2) If flt-semantics-placeholder which lives on the engine changes, this will break. It would be very hard to understand for the engine-developers. It is best to add a documentation and also a link to that code.

Btw, a question we can also click on this button by calling the following right?

webDriver.execute(
          'document.querySelector(\'flt-semantics-placeholder\').click();',
          <String>[]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated accordingly. Well create an issue for Mobile Web (in fact, it works on Android-Chrome).

String url,
Map<String, dynamic> settings,
{Duration timeout}) async {
// Use sync WebDriver because async version will create a 15 seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Looks like we are also switching the way we are accessing the driver object (fromExistingSession vs constructor)? Is there a specific reason for it (anything failing with a11y or screendriver)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The async version of fromExistingSession returns a WebDriver instance which will NOT have the same capabilities (in fact, it would be empty) as the original one where the capabilities plays an important role for screendriver.

@nturgut
Copy link
Contributor

nturgut commented Sep 2, 2020

Can we add a test to this functionality?

I think the easiest way would be editing this code: https://github.com/flutter/flutter/blob/master/examples/hello_world/test_driver/smoke_web_engine_test.dart we can add one more test method, which call enabling a11y. Later the webdriver can be called a second time to show, placeholder no longer exists and flt-semantics is added to the DOM.

// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/src/engine/semantics/semantics.dart#L534
final WebElement element = await driver.webDriver.findElement(const By.tagName('flt-semantics'));

expect(element, isNotNull);
Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks for adding this test!

@fluttergithubbot fluttergithubbot merged commit d2fa384 into flutter:master Sep 8, 2020
@angjieli angjieli deleted the a11y branch October 23, 2020 18:21
test('enable accessibility', () async {
await driver.enableAccessibility();

await Future<void>.delayed(const Duration(seconds: 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way we can remove this timeout? In general this kind of thing is a source of flakes, and thus violates our style guide (https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#never-check-if-a-port-is-available-before-using-it-never-add-timeouts-and-other-race-conditions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants