New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When Testing Accessibility, Text Contrast Tests Do Not Always Give Right Results #50376
Comments
Hi @pennzht
flutter doctor -v[✓] Flutter (Channel master, 1.22.0-10.0.pre.251, on Mac OS X 10.15.6 19G2021
x86_64, locale en-GB)
• Flutter version 1.22.0-10.0.pre.251 at
/Users/tahatesser/Code/flutter_master
• Framework revision d26268bb9e (13 hours ago), 2020-09-18 09:06:26 +0900
• Engine revision 2abe69c608
• Dart version 2.10.0 (build 2.10.0-136.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/tahatesser/Code/sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /Users/tahatesser/Code/sdk
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0, Build version 12A7209
• CocoaPods version 1.9.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.49.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.14.1
[✓] Connected device (3 available)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G2021
x86_64
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome
85.0.4183.102
• No issues found! |
@TahaTesser Thank you for your message! You need to checkout the file Alternatively, you can add the following tests to Additional tests testWidgets('white text on white background with merge semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: MergeSemantics(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Text(
'I am text one',
style: TextStyle(color: Colors.white),
),
Text(
'And I am text two',
style: TextStyle(color: Colors.white),
),
],
),
),
),
),
));
await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('black text on white background with merge semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: MergeSemantics(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Text(
'I am text one',
style: TextStyle(color: Colors.black),
),
Text(
'And I am text two',
style: TextStyle(color: Colors.black),
),
],
),
),
),
),
));
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('white text on white', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: MergeSemantics(
child: Column(
children: const <Widget>[
Text('White', style: TextStyle(color: Colors.white)),
]
),
),
),
),
));
await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('white and black text on white', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: MergeSemantics(
child: Column(
children: const <Widget>[
Text('White', style: TextStyle(color: Colors.white)),
SizedBox(height: 30),
Text('Black', style: TextStyle(color: Colors.black)),
]
),
),
),
),
));
await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('black and white text on white', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: MergeSemantics(
child: Column(
children: const <Widget>[
Text('Black', style: TextStyle(color: Colors.black)),
SizedBox(height: 30),
Text('White', style: TextStyle(color: Colors.white)),
]
),
),
),
),
));
await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('irrelevant text', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: const <Widget>[
ExcludeSemantics(
child: Text('One', style: TextStyle(color: Colors.white)),
),
SizedBox(height: 30),
MergeSemantics(
child: Text('One', style: TextStyle(color: Colors.black)),
)
],
),
),
),
));
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('irrelevant text - passing', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: const <Widget>[
ExcludeSemantics(
child: Text('Two', style: TextStyle(color: Colors.white)),
),
SizedBox(height: 30),
MergeSemantics(
child: Text('One', style: TextStyle(color: Colors.black)),
)
],
),
),
),
));
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('irrelevant button', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: const <Widget>[
ExcludeSemantics(
child: FlatButton(child: Text('One'), onPressed: null),
),
SizedBox(height: 30),
MergeSemantics(
child: Text('One', style: TextStyle(color: Colors.black)),
)
],
),
),
),
));
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('irrelevant button - passing', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: const <Widget>[
ExcludeSemantics(
child: FlatButton(child: Text('Two'), onPressed: null),
),
SizedBox(height: 30),
MergeSemantics(
child: Text('One', style: TextStyle(color: Colors.black)),
)
],
),
),
),
));
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();
});
testWidgets('black and white text, without MergeSemantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light(),
home: Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: const <Widget>[
ExcludeSemantics(
child: Text('One', style: TextStyle(color: Colors.black)),
),
SizedBox(height: 30),
Text('One', style: TextStyle(color: Colors.white)),
],
),
),
),
));
await expectLater(tester, doesNotMeetGuideline(textContrastGuideline));
handle.dispose();
}); |
@TahaTesser I updated the description. |
Steps to Reproduce
packages/flutter_test/test/accessibility_test.dart
from the following branch.packages/flutter_test/test/accessibility_test.dart
.packages/flutter_test/lib/src/accessibility.dart
.packages/flutter_test
and runflutter test test/accessibility_test.dart
Expected results:
MergeSemantics
widgets. Text widgets that do not contribute to semantics should be skipped.Actual results:
Related Solutions
May be fixed by #48868
Logs
flutter test --verbose test/accessibility_test.dart
.Additional Tests
Additional tests
The text was updated successfully, but these errors were encountered: