All posts

Dismiss Android Keyboards and Handle IME Focus in Phoma Flows

Dismiss Android Keyboards and Handle IME Focus in Phoma Flows

Why IME State Matters

Android keyboards are complex input surfaces. They hold focus, prediction history, autocorrect state, and sometimes typed text. When a Phoma flow starts, the keyboard may already be open, partially open, or focused on the wrong field. That can make a tap land on the wrong control or make typed text appear in the wrong place.

For QA testers and developers, this means the flow must manage input context. A reliable flow does not just send tap and type steps. It waits, focuses, types, and dismisses in the right order. This is especially important for smoke tests, regression checks, and repetitive data entry. A missing dismiss step can cause the next assertion to run while the keyboard is still visible.

Map The Keyboard And Focus Lifecycle

A strong automation flow usually has four phases.

Wait For The Screen

Before any input action, wait for the screen or element. This avoids tap-before-ready races.

Wait For The Target Field

Use stable selectors such as resource IDs or test tags. Avoid fragile selectors based only on visible text. Text can change between app versions.

Focus The Field

Tap the field. If the keyboard is already open, confirm focus. If not, the tap should open it. Then type. The order matters because Android delivers focus and keyboard events differently across apps. If the app keeps focus on the previous field, the typed value may be lost or placed incorrectly. Always verify field state before typing.

Dismiss Or Reset

After typing, dismiss the keyboard before assertions, navigation, or screenshot checkpoints. Press back or tap outside. This resets focus for the next step.

Build A Login Flow Without Flaky Keys

A typical email and password flow in Phoma:

  • Launch the app.
  • Wait for the sign-in screen.
  • Tap the email field.
  • Type the test email.
  • Tap the password field.
  • Type the test password.
  • Press back or send key.
  • Tap the sign-in button.
  • Wait for the post-login screen.
  • Capture a screenshot.

The important design choices are deliberate focus movement and keyboard dismissal. Moving from email to password should not rely on manual timing. Use flow steps that wait for each field. After submit, dismiss or close the keyboard before checking the next screen.

Real-World QA Example: Two-Step Form

For a two-step form:

  • Launch the app.
  • Wait for the email field.
  • Type the email.
  • Press next.
  • Wait for the password field.
  • Type the password.
  • Dismiss the keyboard.
  • Tap submit.

This shows how a key press can move focus without a full reload.

Handle Stuck Keyboards And Bad Focus

When a keyboard will not dismiss, use a controlled troubleshooting path.

  1. Press the Android back key.
  2. Wait for the transition.
  3. Tap outside the field.
  4. Retry the focus step once.
  5. Capture a screenshot and log the state.

Do not keep typing into a stuck keyboard. Break the flow into smaller steps and inspect the screen tree. A stuck keyboard can also block screenshots and OCR steps, so dismiss before checkpoints.

Recovery Pattern

  • Stop typing.
  • Dismiss the keyboard.
  • Wait.
  • Re-focus.
  • Resume.

Practical Example: Search And Results Flow

For a search flow:

  • Open the app.
  • Tap the search field.
  • Type the query.
  • Press enter or submit.
  • Wait for the results container.
  • Dismiss the keyboard if needed.
  • Capture a screenshot.

This pattern helps QA teams test search without keyboard overlay hiding results.

Step-By-Step: Add IME Handling To A Phoma Flow

  1. Open the flow in Phoma.
  2. Add a wait for the target element.
  3. Add a tap action.
  4. Add a type action.
  5. Add a key press action.
  6. Add a wait for the next element.
  7. Add a screenshot checkpoint.

If the app uses a custom keyboard, verify dismissal through the custom back action if available. This sequence keeps the flow readable and avoids hidden timing assumptions.

Why Focus Order Matters

Android focus order can differ from visual order. In QA, test tab order and back behavior. Use conditions to branch when fields are optional. This helps multi-step forms avoid skipped inputs.

How To Choose A Dismiss Method

  • Press the back key for normal screens.
  • Tap outside for text fields.
  • Use the submit key for single input forms.

Choose based on the app under test. A banking app may require special handling, so do not force unsafe behavior.

IME State And Assertions

Before an assertion reads text or captures a screenshot, ensure the keyboard is handled. An assertion that reads the wrong field because focus was stale will fail even when the UI is correct. Treat keyboard state as part of the test condition.

Troubleshooting Flow

If a flow fails after typing, check these points.

  • Did the keyboard dismiss?
  • Was the next field focused?
  • Did the wait step run?
  • Did the selector match?

This short checklist prevents most IME related failures.

Common Mistakes

  • Tapping before the keyboard closes.
  • Using a global back action without screen context.
  • Not waiting after typing.
  • Assuming the keyboard state.
  • Forgetting focus order in multi-step forms.

QA And Team Considerations

  • Name flows by outcome, such as login or search.
  • Keep selectors stable across app updates.
  • Add conditions for optional keyboards.
  • Use bounded retries for slow screens.
  • Document whether keyboard dismissal is part of the flow.

Without this, teams may see flaky failures that are actually input context issues.

Checklist Before Running IME Flows

  • Verify the field selector.
  • Confirm the keyboard state.
  • Add wait steps.
  • Add dismiss step.
  • Add screenshot.

When Not To Automate IME Handling

Some flows should not force keyboard dismissal. Secure token entry, biometric fallback, and high-risk banking flows may require special handling. Respect app security and user experience.