-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Testing Color Contrast in AlertDialog #148657
Comments
Reproducible using the code sample provided above. flutter doctor -v
|
It works with |
Once @anasqadrei Any reason for not relying on a longer duration? It would make sense to wait for the dialog to be fully visible before checking color contrast. |
In my original test, I am testing for semantics too. After some investigation, I found out that Consider the below lines after tapping show dialog button. I ran these tests individually (running one section and commenting the rest) // Passes
await tester.pump();
expect(find.text('OK'), findsOneWidget);
// Passes
await tester.pump(Durations.short1);
expect(find.text('OK'), findsOneWidget);
// Fails
await tester.pump();
expect(find.bySemanticsLabel('OK'), findsOneWidget);
// Fails
await tester.pump(Durations.short1);
expect(find.bySemanticsLabel('OK'), findsOneWidget);
// Passes
await tester.pump();
await tester.pump(Durations.short1);
expect(find.bySemanticsLabel('OK'), findsOneWidget);
// Passes
await tester.pump();
await expectLater(tester, meetsGuideline(textContrastGuideline));
// Passes
await tester.pump(Durations.short1);
await expectLater(tester, meetsGuideline(textContrastGuideline));
// Passes
await tester.pump(Durations.short3);
await expectLater(tester, meetsGuideline(textContrastGuideline));
// Fails
await tester.pump();
await tester.pump(Durations.short1);
await expectLater(tester, meetsGuideline(textContrastGuideline));
// Passes
await tester.pump();
await tester.pump(Durations.short3);
await expectLater(tester, meetsGuideline(textContrastGuideline)); I'm a bit puzzled here Question 1: Why did |
To debug this you can print the semantics tree with |
To narrow down the problem, I'm wondering why finding a text takes one pump while finding its corresponding semantics label takes two. If text is pumped then its semantics label should go with it, shouldn't it? Why is there an inconsistency?
await tester.pump();
debugDumpApp();
debugDumpSemanticsTree();
expect(find.text('Alert dialog description'), findsOneWidget); // Passes. Shouldn't it fail because it NEEDS-PAINT
expect(find.bySemanticsLabel('Alert dialog description'), findsOneWidget); // Fails I get this snippet from
and I get this from
await tester.pump();
await tester.pump(Durations.short1);
debugDumpApp();
debugDumpSemanticsTree();
expect(find.text('Alert dialog description'), findsOneWidget); // Passes
expect(find.bySemanticsLabel('Alert dialog description'), findsOneWidget); // Passes I get this snippet from
and I get this from
From the debugs I did above, it seems showing an AlertDialog takes few steps which is okay but there are inconsistencies with text, their semantics labels and colour contrast. |
Steps to reproduce
I'm building a complex app with asynchronous code, providers, external libraries, and so on. It works well and passes tests in most cases, except for this one. I created a minimal code example to demonstrate the issue. In my complex app, for some reason, I need to run two pumps for the AlertDialog test to pass. However, only the color contrast test fails. I'm unsure why it fails, as it shouldn't fail regardless of the number of pumps I run.
Expected results
Test should pass
Actual results
Test fails
Code sample
lib/main.dart
test/widget_test.dart
Screenshots or Video
No response
Logs
Logs
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: