@9l/playwright

中文文档
0.6.0发布于 2026/11/08Apache-2.0TypeScriptCommonJS零依赖构建来源已验证近 30 天下载 3270

Playwright fixtures and the versioned 9lives Go engine bridge

原始使用文档
文档目录4 节
  1. Install
  2. Use
  3. Android (experimental)
  4. License

@9l/playwright

Local Playwright fixtures for the 9lives runner. The n9l fixture provides step and bounded natural-language goal methods. Keep ordinary Playwright assertions to establish the expected behavior. A goal completing does not verify that behavior.

Install

Published on npm:

npm install --save-dev @9l/[email protected] @playwright/[email protected]
npm exec playwright install chromium

Use Node 24 for the qualified runtime (Node 22 minimum), Playwright 1.61.1 through 1.64.1, and Chromium. macOS, Linux and Windows on amd64/arm64 are the qualified runner targets (Windows from CLI 0.2.0). The peer range is @playwright/test >=1.61.1 <2; CI qualifies every published release from 1.61.1 through 1.64.1 (1.61.1, 1.62.0, 1.62.1, 1.63.0, 1.64.0 and 1.64.1). Later versions, and other browser engines, install but are unqualified.

The Go 9l executable is also required. Use the CLI installation guide for release availability or install from source with Go 1.27.3 or newer. This npm package does not install Go or bundle the runner, browsers or a hosted service. No platform account is needed.

Use

import {test, expect} from '@9l/playwright';

test('checkout confirms one order', async ({page, n9l}) => {
  await page.goto('http://localhost:3000/checkout');
  await n9l.step('place order', async () => {
    await page.getByRole('button', {name: 'Place order'}).click();
    await expect(page.getByRole('status')).toHaveText('Order confirmed');
  });
});

Start the example application, then run the selected spec through the Go engine:

9l run tests/checkout.spec.ts --sdk --format json

Use --pass-env NAME for explicitly approved application settings. Browser handles and goal parameter values stay in the worker; provider credentials stay in Go. The n9l fixture requires the engine identity supplied by --sdk. Existing Playwright specs and configuration remain usable independently.

Natural-language goals use finite observed controls and typed actions, with budgets and a conservative stop policy. See the goal contract and SDK bridge. Live provider accuracy, independent behavioral verification, verified replay, iOS and Android devices beyond those listed below are not qualified features.

Android (experimental)

The Android target drives an owned emulator or an attached phone through Appium 3.8.0 and UiAutomator2 8.7.0, with the same app fixture a web target uses. It is qualified on API 35 emulators and one Android 17 phone; see Android setup and qualification limits.

  1. Install the matching 0.6.0 CLI and @9l/playwright together (see installation), and the pinned automation tooling once, outside your project:

    npm install --prefix ~/.9l/android-tools --save-exact --ignore-scripts \
      [email protected] [email protected]
    

    For another location, set NINELIVES_ANDROID_TOOLS.

  2. Check the host. Doctor reports Java, the SDK, build-tools, AVDs, devices and the pinned tooling, each with a fix:

    9l doctor --android
    
  3. Construct the driver in the shared target fixture and name the Playwright project android:<alias>:

    import {createTargetTest} from '@9l/playwright';
    import {androidTargetDriver} from '@9l/playwright/android';
    
    export const test = createTargetTest({
      native: target => androidTargetDriver({
        appId: target.appId, avd: 'Pixel_API_35',
        apk: 'build/app.apk', apkSHA256: '<digest>',
        appPackage: 'com.example.app', activity: '.MainActivity',
      }),
    });
    
    // playwright.config.ts
    import {defineConfig} from '@playwright/test';
    
    export default defineConfig({
      // A cold emulator boot fits in open()'s 180-second bound, which needs
      // a test timeout above Playwright's 30-second default.
      timeout: 240_000,
      // 9l owns attempts: a Playwright retry is refused.
      retries: 0,
      projects: [{name: 'android:app'}],
    });
    
  4. Run through the engine, forwarding the variables the driver relies on. 9l run passes only a fixed environment to tests:

    9l run tests/login.spec.ts --sdk --target android:app \
      --pass-env ANDROID_HOME,JAVA_HOME,NINELIVES_ANDROID_TOOLS
    

    Forward ANDROID_SDK_ROOT, ANDROID_AVD_HOME or HOMEBREW_PREFIX too if your SDK or AVDs are found through them. 9l doctor --android says which.

The driver holds the device's only UI-automation connection while a session is open, so a spec-side adb shell uiautomator dump returns nothing. Use the fixture's operations instead, and app.deviceSerial() for other adb commands.

License

Apache-2.0. The package includes LICENSE and NOTICE.

版本与发布记录

@9l/playwright 共发布 27 个版本,首次发布于 2026/10/08;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.0latest2026/11/08今天
0.6.0-beta.4beta2026/11/053 天前
0.6.0-beta.32026/11/043 天前
0.6.0-beta.22026/11/035 天前
0.6.0-beta.12026/10/309 天前
0.6.0-beta2026/10/2910 天前

关于 @9l/playwright 的常见问题

@9l/playwright 是什么?

Playwright fixtures and the versioned 9lives Go engine bridge

如何安装 @9l/playwright?

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

@9l/playwright 支持 TypeScript 吗?

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

@9l/playwright 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@9l/playwright 需要什么版本的 Node.js?

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

@9l/playwright 可以商用吗?

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

@9l/playwright 的下载量有多少?

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

@9l/playwright 还在维护吗?

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