@browserstack/mobilewright

中文文档
0.1.1发布于 2026/08/19Apache-2.0TypeScriptES Module近 30 天下载 2186

BrowserStack App Automate driver for Mobilewright

原始使用文档
文档目录5 节
  1. Switching between a local device and BrowserStack
  2. What's inside
  3. Dev setup
  4. Contributing & security
  5. License

@browserstack/mobilewright

BrowserStack App Automate driver for Mobilewright. Every test session is a first-class App Automate session — dashboard, server-side video, device/network logs, BrowserStack Local, geolocation/network simulation, camera & biometric injection — with no BrowserStack-specific code in your tests.

Requires mobilewright ≥ 0.0.53; Node requirements are exactly your existing Mobilewright project's — this package adds none of its own. Install into an existing Mobilewright project (@mobilewright/test comes with your Mobilewright setup):

npm i -D @browserstack/mobilewright

Heads-up (upstream, not BrowserStack-specific): despite mobilewright declaring node >=18, its config loading needs Node ≥ 20.19 in CommonJS projects (require() of an ESM package) — Node 18.x fails at config load with ERR_REQUIRE_ESM even with no driver configured. See upstream/README.md §3.

Point an existing Mobilewright suite at BrowserStack by setting the driver:

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

export default defineConfig({
  testDir: './tests',
  bundleId: 'org.wikipedia.alpha',
  driver: browserStackDriver({
    app: 'bs://<app-id>',          // or a local .apk/.ipa path, or an https:// url — uploaded for you
    project: 'My project',
  }),
  projects: [
    { name: 'android', use: { platform: 'android', deviceName: /Google Pixel 8\b/ } },
    { name: 'ios', use: { platform: 'ios', deviceType: 'real', osVersion: '>=17 <19' } },
  ],
});

browserStackDriver(options) is new BrowserStackDriver(options) spelled like configuration — mobilewright ≥0.0.53 takes the driver as an instance. Device selection uses the standard config fields: deviceName (regex), osVersion (range expressions like ">=17 <19"), deviceType (App Automate is real devices). Credentials come from BROWSERSTACK_USERNAME / BROWSERSTACK_ACCESS_KEY env vars (or the username/accessKey options); the app falls back to the BROWSERSTACK_APP env var. Tests are stock Mobilewright.

Session names and statuses are automatic. The driver ships a TestObserver, which mobilewright invokes without any reporter configuration: at run end every App Automate session is named after the tests it ran, marked passed/failed, and its dashboard link printed.

Switching between a local device and BrowserStack

Keep one config and pick the driver by environment — local (mobilecli) by default, BrowserStack when credentials are present:

const config: MobilewrightConfig = { /* ...your existing config... */ };

if (process.env.BROWSERSTACK_USERNAME) {
  config.driver = browserStackDriver({ app: './apps/checkout.apk' });
}

export default defineConfig(config);
npx mobilewright test                                     # local device, as always
BROWSERSTACK_USERNAME=… BROWSERSTACK_ACCESS_KEY=… \
  npx mobilewright test                                   # the same suite on App Automate

Local .apk/.ipa paths are uploaded automatically (once per run), and the fixtures' mid-session reinstall of the session app is skipped.

What's inside

  • src/driver.ts — the full Mobilewright driver contract: DeviceAllocator (one App Automate session per worker slot; workers attach by session id) + MobilewrightSession (26 verbs + webViewBridge with multi-webview page expansion) over BrowserStack's standard W3C WebDriver session API.
  • src/observer.ts — the TestObserver: automatic session naming/status + dashboard links.
  • src/executor.ts — browserStackExecutor() escape hatch for BrowserStack-specific actions (camera image injection, biometrics, Apple Pay, …).
  • src/reporter.ts — standalone Playwright reporter; superseded by the observer, kept for suites that want reporter-style wiring explicitly.
  • e2e/ — conformance suites (Android/iOS native, webview, phase-2 features, BrowserStack Local, the Milliways cross-platform suite), the release compat gate (e2e/compat-check.sh), and the local-vs-cloud performance benchmark (e2e/perf/).
  • upstream/ — pending one-line upstream fixes found by these suites.

Dev setup

Plain npm — the package builds against the published mobilewright packages:

npm install && npm run build && npm run lint && npm run test:unit

# conformance against real App Automate devices
export BROWSERSTACK_USERNAME=… BROWSERSTACK_ACCESS_KEY=…
cd e2e && ./compat-check.sh

e2e/compat-check.sh pins the @mobilewright/protocol version and fails loudly when upstream's driver interface moves; bump the pin deliberately after reviewing changes.

Contributing & security

See CONTRIBUTING.md for setup, style, the compat-gate policy, and the release process. Report vulnerabilities privately per SECURITY.md — never via public issues. Code review is owned by the App Automate team (.github/CODEOWNERS); dependencies are watched by Dependabot.

License

Apache-2.0 (see LICENSE).

版本与发布记录

@browserstack/mobilewright 共发布 2 个版本,首次发布于 2026/08/19;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.1latest2026/08/192 个月前
0.1.0next2026/08/192 个月前

关于 @browserstack/mobilewright 的常见问题

@browserstack/mobilewright 是什么?

BrowserStack App Automate driver for Mobilewright

如何安装 @browserstack/mobilewright?

在项目目录运行 npm install @browserstack/mobilewright,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@mobilewright/core(>=0.0.53 <0.1.0)、@mobilewright/protocol(>=0.0.53 <0.1.0)、mobilewright(>=0.0.53 <0.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@browserstack/mobilewright 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@browserstack/mobilewright 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@browserstack/mobilewright 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@browserstack/mobilewright 可以商用吗?

@browserstack/mobilewright 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@browserstack/mobilewright 的下载量有多少?

根据 npm 官方下载统计,@browserstack/mobilewright 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,186 次,日均约 73 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@browserstack/mobilewright 还在维护吗?

最新版本 0.1.1 发布于 2026/08/19(2 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/08/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。