Actions & Interactions
Tap, double-tap, long-press, fill text fields, swipe the screen, and press hardware buttons — all with built-in auto-waiting.
Tapping
Tapping is the mobile equivalent of clicking. Mobilewright waits automatically until the element is visible, enabled, and has stopped moving before it taps — so taps land exactly where they should:
import { test, expect } from '@mobilewright/test';
test('tap variations', async ({ screen }) => {
// Simple tap
await screen.getByText('Sign In').tap();
// Double tap
await screen.getByRole('button', { name: 'Submit' }).doubleTap();
// Long press (opens context menus, drag handles, etc.)
await screen.getByText('Options').longPress();
});
const { test, expect } = require('@mobilewright/test');
test('tap variations', async ({ screen }) => {
// Simple tap
await screen.getByText('Sign In').tap();
// Double tap
await screen.getByRole('button', { name: 'Submit' }).doubleTap();
// Long press (opens context menus, drag handles, etc.)
await screen.getByText('Options').longPress();
});
Filling Text Fields
fill() taps the field to focus it, then types the text. Use it for logins, search boxes, and forms:
import { test, expect } from '@mobilewright/test';
test('fill in a form', async ({ screen }) => {
await screen.getByLabel('Email').fill('user@example.com');
await screen.getByLabel('Password').fill('secret');
await expect(screen.getByLabel('Email')).toHaveValue('user@example.com');
});
const { test, expect } = require('@mobilewright/test');
test('fill in a form', async ({ screen }) => {
await screen.getByLabel('Email').fill('user@example.com');
await screen.getByLabel('Password').fill('secret');
await expect(screen.getByLabel('Email')).toHaveValue('user@example.com');
});
Swiping
Swipe the screen in any direction — great for scrolling through lists, dismissing cards, or navigating carousels. You can optionally control the swipe distance in pixels:
import { test } from '@mobilewright/test';
test('scroll through the feed', async ({ screen }) => {
// Swipe up (scrolls the content down)
await screen.swipe('up');
// Swipe down with a custom distance in pixels
await screen.swipe('down', { distance: 300 });
});
const { test } = require('@mobilewright/test');
test('scroll through the feed', async ({ screen }) => {
// Swipe up (scrolls the content down)
await screen.swipe('up');
// Swipe down with a custom distance in pixels
await screen.swipe('down', { distance: 300 });
});
Hardware Buttons
Some flows need the device's physical buttons. pressButton() handles them:
import { test } from '@mobilewright/test';
test('hardware buttons', async ({ screen }) => {
// Go to the home screen
await screen.pressButton('HOME');
// Android only: the back button
await screen.pressButton('BACK');
});
const { test } = require('@mobilewright/test');
test('hardware buttons', async ({ screen }) => {
// Go to the home screen
await screen.pressButton('HOME');
// Android only: the back button
await screen.pressButton('BACK');
});
pressButton('BACK') is Android-only — iOS has no back button. Keep platform-specific steps behind a platform check or in separate projects (covered in chapter 11).Everything Auto-Waits
Every action in this chapter performs actionability checks before executing: the element must exist, be visible, be enabled, and have stable bounds (not animating). If a check fails, Mobilewright retries every 100ms until it passes or the timeout expires. This is why Mobilewright tests need no sleep() calls — the framework handles timing for you. We will dig deeper into this in the Auto-waiting chapter.
Written by PV
© 2026 All Rights Reserved