[web] Make web integration tests shadow DOM aware. (#82926)
This commit is contained in:
@@ -904,6 +904,7 @@ Future<void> _runFlutterDriverWebTest({
|
||||
await runCommand(
|
||||
flutter,
|
||||
<String>[
|
||||
...?flutterTestArgs,
|
||||
'drive',
|
||||
'--target=$target',
|
||||
'--browser-name=chrome',
|
||||
@@ -1080,6 +1081,7 @@ Future<void> _runGalleryE2eWebTest(String buildMode, { bool canvasKit = false })
|
||||
await runCommand(
|
||||
flutter,
|
||||
<String>[
|
||||
...?flutterTestArgs,
|
||||
'drive',
|
||||
if (canvasKit)
|
||||
'--dart-define=FLUTTER_WEB_USE_SKIA=true',
|
||||
@@ -1163,6 +1165,7 @@ Future<void> _runWebReleaseTest(String target, {
|
||||
await runCommand(
|
||||
flutter,
|
||||
<String>[
|
||||
...?flutterTestArgs,
|
||||
'build',
|
||||
'web',
|
||||
'--release',
|
||||
|
||||
@@ -15,6 +15,15 @@ import 'package:web_e2e_tests/text_editing_main.dart' as app;
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
/// Locate elements in the correct root of the application, whether it is
|
||||
/// `document` or the new `shadowRoot` of `flt-class-pane`.
|
||||
List<Node> findElements(String selector) {
|
||||
final ShadowRoot? shadowRoot = document.querySelector('flt-glass-pane')?.shadowRoot;
|
||||
return (shadowRoot != null) ?
|
||||
shadowRoot.querySelectorAll(selector):
|
||||
document.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
testWidgets('Focused text field creates a native input element',
|
||||
(WidgetTester tester) async {
|
||||
app.main();
|
||||
@@ -29,10 +38,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('input')));
|
||||
|
||||
// A native input element will be appended to the DOM.
|
||||
final List<Node> nodeList = document.getElementsByTagName('input');
|
||||
final List<Node> nodeList = findElements('input');
|
||||
expect(nodeList.length, equals(1));
|
||||
final InputElement input =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input = nodeList[0] as InputElement;
|
||||
// The element's value will be the same as the textFormField's value.
|
||||
expect(input.value, 'Text1');
|
||||
|
||||
@@ -57,10 +65,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('empty-input')));
|
||||
|
||||
// A native input element will be appended to the DOM.
|
||||
final List<Node> nodeList = document.getElementsByTagName('input');
|
||||
final List<Node> nodeList = findElements('input');
|
||||
expect(nodeList.length, equals(1));
|
||||
final InputElement input =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input = nodeList[0] as InputElement;
|
||||
// The element's value will be empty.
|
||||
expect(input.value, '');
|
||||
|
||||
@@ -92,8 +99,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('input2')));
|
||||
|
||||
// // Press Tab. This should trigger `onFieldSubmitted` of TextField.
|
||||
final InputElement input =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input = findElements('input')[0] as InputElement;
|
||||
dispatchKeyboardEvent(input, 'keydown', <String, dynamic>{
|
||||
'keyCode': 13, // Enter.
|
||||
'cancelable': true,
|
||||
@@ -121,10 +127,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('input')));
|
||||
|
||||
// A native input element will be appended to the DOM.
|
||||
final List<Node> nodeList = document.getElementsByTagName('input');
|
||||
final List<Node> nodeList = findElements('input');
|
||||
expect(nodeList.length, equals(1));
|
||||
final InputElement input =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input = nodeList[0] as InputElement;
|
||||
|
||||
// Press Tab. The focus should move to the next TextFormField.
|
||||
dispatchKeyboardEvent(input, 'keydown', <String, dynamic>{
|
||||
@@ -132,14 +137,14 @@ void main() {
|
||||
'code': 'Tab',
|
||||
'bubbles': true,
|
||||
'cancelable': true,
|
||||
'composed': true,
|
||||
});
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A native input element for the next TextField should be attached to the
|
||||
// DOM.
|
||||
final InputElement input2 =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input2 = findElements('input')[0] as InputElement;
|
||||
expect(input2.value, 'Text2');
|
||||
}, semanticsEnabled: false);
|
||||
|
||||
@@ -156,10 +161,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('input')));
|
||||
|
||||
// A native input element will be appended to the DOM.
|
||||
final List<Node> nodeList = document.getElementsByTagName('input');
|
||||
final List<Node> nodeList = findElements('input');
|
||||
expect(nodeList.length, equals(1));
|
||||
final InputElement input =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input = nodeList[0] as InputElement;
|
||||
|
||||
// Press and release CapsLock.
|
||||
dispatchKeyboardEvent(input, 'keydown', <String, dynamic>{
|
||||
@@ -167,12 +171,14 @@ void main() {
|
||||
'code': 'CapsLock',
|
||||
'bubbles': true,
|
||||
'cancelable': true,
|
||||
'composed': true,
|
||||
});
|
||||
dispatchKeyboardEvent(input, 'keyup', <String, dynamic>{
|
||||
'key': 'CapsLock',
|
||||
'code': 'CapsLock',
|
||||
'bubbles': true,
|
||||
'cancelable': true,
|
||||
'composed': true,
|
||||
});
|
||||
|
||||
// Press Tab. The focus should move to the next TextFormField.
|
||||
@@ -181,14 +187,14 @@ void main() {
|
||||
'code': 'Tab',
|
||||
'bubbles': true,
|
||||
'cancelable': true,
|
||||
'composed': true,
|
||||
});
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A native input element for the next TextField should be attached to the
|
||||
// DOM.
|
||||
final InputElement input2 =
|
||||
document.getElementsByTagName('input')[0] as InputElement;
|
||||
final InputElement input2 = findElements('input')[0] as InputElement;
|
||||
expect(input2.value, 'Text2');
|
||||
}, semanticsEnabled: false);
|
||||
|
||||
@@ -216,7 +222,7 @@ void main() {
|
||||
await gesture.up();
|
||||
|
||||
// A native input element will be appended to the DOM.
|
||||
final List<Node> nodeList = document.getElementsByTagName('textarea');
|
||||
final List<Node> nodeList = findElements('textarea');
|
||||
expect(nodeList.length, equals(1));
|
||||
final TextAreaElement input = nodeList[0] as TextAreaElement;
|
||||
// The element's value should contain the selectable text.
|
||||
|
||||
Reference in New Issue
Block a user