Skip to content

deviceName regex works with android.launch() but silently hangs with @mobilewright/test fixture due to inconsistent device resolution #237

Description

@avdhutssh

Mobilewright version

0.0.50

Operating system

macOS 15 (darwin arm64)

Target platform

Android

Device or simulator

Android emulator (ID: PixelPro_AVD, Name: PixelPro AVD)

Minimal reproduction

// mobilewright.config.ts
import { defineConfig } from 'mobilewright';

export default defineConfig({
testDir: './tests',
testMatch: '**/*.ts',
platform: 'android',
deviceName: /PixelPro_AVD/, // matches device ID, not display name
bundleId: 'com.android.chrome',
autoAppLaunch: false,
timeout: 300_000,
workers: 1,
});

// tests/example.ts — STANDALONE (works fine)
import { android } from 'mobilewright';
const device = await android.launch({ deviceName: /PixelPro_AVD/ }); // ✅ connects
await device.close();

// tests/example.ts — FIXTURE (hangs)
import { test } from '@mobilewright/test';
test('basic', async ({ screen }) => {
// ❌ never reaches here — times out on device setup
});

Run: npx mobilewright test

Actual behavior

The same deviceName: /PixelPro_AVD/ regex works with standalone android.launch() but silently hangs when using the @mobilewright/test fixture.

npx mobilewright devices reports:

ID Name Platform Type State
PixelPro_AVD PixelPro AVD android emulator online
he standalone android.launch() resolves the device successfully — it appears to match against both device.id and device.name.

The fixture's MobilecliAllocator.allocate() only matches against device.name (display name: "PixelPro AVD"). Since the regex /PixelPro_AVD/ has an underscore and the display name has a space, the match fails. The device pool then waits indefinitely for a matching device to appear, eventually timing out with:

Test timeout of 300000ms exceeded while setting up "device"
Debug output (DEBUG=mw:*) shows:

mw:test:fixtures allocating device (platform=android)
mw:driver-mobilecli listing devices
mw:driver-mobilecli found 1 device(s)

Then hangs — no error about the device name not matching.

Expected behavior

Consistent device resolution: if deviceName: /PixelPro_AVD/ works with android.launch(), it should also work with @mobilewright/test fixture. The allocator should match against both device.id and device.name.
If no device matches the pattern, throw a clear error immediately (e.g., "No online device matches pattern /PixelPro_AVD/. Available devices: PixelPro AVD (ID: PixelPro_AVD)") instead of hanging until test timeout.
Additional context:

The issue is in node_modules/mobilewright/dist/device-pool/adapters/mobilecli-allocator.js:

// allocate() filters with:
.filter((d) => !namePattern || namePattern.test(d.name))
// Only checks d.name, not d.id
Workaround: use a regex that matches the display name instead of the ID:

deviceName: /PixelPro/, // matches "PixelPro AVD"

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions