[web] Make web integration tests shadow DOM aware. (#82926)

This commit is contained in:
David Iglesias
2021-05-20 16:14:02 -07:00
committed by GitHub
parent fa1c6a2841
commit c94f0bea65
3 changed files with 42 additions and 20 deletions

View File

@@ -8,6 +8,8 @@ import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
import 'package:webdriver/async_io.dart';
// TODO(web): Migrate this test to a normal integration_test with a WidgetTester.
/// The following test is used as a simple smoke test for verifying Flutter
/// Framework and Flutter Web Engine integration.
void main() {
@@ -35,12 +37,23 @@ void main() {
await Future<void>.delayed(const Duration(seconds: 2));
// A flutter web app may be rendered directly on the body of the page, or
// inside the shadow root of the flt-glass-pane (after Flutter 2.4). To
// make this test backwards compatible, we first need to locate the correct
// root for the app.
//
// It's either the shadowRoot within flt-glass-pane, or [driver.webDriver].
final SearchContext appRoot = await driver.webDriver.execute(
'return document.querySelector("flt-glass-pane")?.shadowRoot;',
<dynamic>[],
) as SearchContext? ?? driver.webDriver;
// Elements with tag "flt-semantics" would show up after enabling
// accessibility.
//
// The tag used here is based on
// 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'));
final WebElement element = await appRoot.findElement(const By.cssSelector('flt-semantics'));
expect(element, isNotNull);
});