1. Give your widgets keys
If your widgets have keys for widget tests, you are done: in a debug build, getByTestId('email') finds Key('email').
Semantics(identifier:) also works as a test ID, and unlike a key it is still there in a release build. Use it for anything you want to test on a release build too.
TextField(
key: const Key('email'),
decoration: const InputDecoration(labelText: 'Email'),
),
TextField(
key: const Key('password'),
obscureText: true,
decoration: const InputDecoration(labelText: 'Password'),
),
Semantics(
identifier: 'sign-in-button',
child: ElevatedButton(
key: const Key('sign-in'),
onPressed: signIn,
child: const Text('Sign in'),
),
),lib/main.dart, the sign-in form