@allwright.dev/core

中文文档
0.2.0发布于 2026/10/17MITTypeScriptES Module构建来源已验证近 30 天下载 1945

High-level TypeScript client for the allwright automation engine.

原始使用文档

@allwright.dev/core

High-level TypeScript client for the allwright automation engine.

Install:

bun add @allwright.dev/core
import { firefox } from "@allwright.dev/core";

const browser = await firefox.launch();
const page = browser.page();
await page.goto("https://themoderninternet.vercel.app");
await page.click(
  "xpath=//div[contains(@class,'card')][.//h2[normalize-space()='Form Inputs']]//button[normalize-space()='Visit page']",
);
await browser.close();

Web clicks accept { button: "left" | "middle" | "right", clickCount: 1 | 2 | 3 }. Use page.dblclick(selector) or locator.dblclick() for the common double-click case.

Register a typed hook before an action that opens a tab, then wait for its typed result afterward:

import { firefox, hooks } from "@allwright.dev/core";

const browser = await firefox.launch();
const page = browser.page();
const hook = await page.registerHook(hooks.newPage);
await page.click("a[target=_blank]");
const newPage = await hook.wait();
const hook = await page.registerHook(hooks.fileChooser);
await page.click("button.open-upload");
const chooser = await hook.wait();
await chooser.setFiles("fixtures/document.pdf");
const hook = await page.registerHook(hooks.download);
await page.click("a.download-report");
const download = await hook.wait();
await download.saveAs(`artifacts/${download.suggestedFilename}`);

Paths passed to setFiles and saveAs belong to the test process, even when the Allwright server is remote. Android apps support the same fileChooser and download hook shape; Android newPage hooks are not applicable.

Runnable examples cover every implemented surface: Web, Android, iOS, macOS, and Windows. The desktop examples default to Calculator on macOS and Notepad on Windows and accept ALLWRIGHT_MAC_APP_ID or ALLWRIGHT_WINDOWS_APP_ID.

Android, iOS, macOS, and Windows applications implement the shared NativeApp and NativeAppLocator interfaces. Platform-specific type names such as MobileAndroidApp, MobileIosLocator, DesktopMacLocator, and DesktopWindowsLocator remain exported as aliases for compatibility and platform-oriented annotations.

Shared config files are stack-agnostic and can live in allwright.config.yaml or allwright.config.json. The shared schema lives at the repo root in allwright.schema.json.

schemaVersion: 1

server:
  addr: 127.0.0.1:50051

browser:
  name: firefox
  binary: /Applications/Firefox.app/Contents/MacOS/firefox
  launchOptions:
    timeoutMs: 30000

expect:
  timeoutMs: 5000
  intervalMs: 100

suites:
  smoke:
    browser:
      name: chromium

The TypeScript package exports findConfigFile(), loadConfigFile(), resolveConfig(), and launchConfiguredBrowser() so runner packages can consume the same config model without inventing language-specific config files.

Iframes

An iframe resolves to a normal Page, including nested and cross-origin frames:

const frame = await page.locator("#checkout-frame").Frame({ timeoutMs: 10_000 });
await frame.locator("input[name=email]").fill("[email protected]");
const nested = await frame.locator("iframe").frame({ timeoutMs: 5_000 });

Frame() and frame() are aliases. The timeout covers finding exactly one iframe, resolving its browsing context, and waiting for a fully loaded document with 200 ms without DOM mutations. The default is 10 seconds. Closing the frame page releases its session; it does not remove the iframe or close the parent tab. Resolve a new frame page after the iframe is replaced.

Read page and element state

const url = await page.url();
const value = await page.locator('input, textarea').inputValue();
const options = await page.locator('select').selectedOptions(); // [{ value, label, index }]
const selectedText = await page.locator('textarea').selectedText();
const checked = await page.locator('input[type=checkbox]').isChecked();
const text = await page.locator('h1').innerText(); // string
const attribute = await page.locator('a').getAttribute('href');
const box = await page.locator('button').boundingBox(); // { x, y, width, height }

Element reads also have page methods such as page.inputValue(selector, options) and accept timeoutMs. Reads use the first locator match and work in frame pages. inputValue reads the live property of an input, textarea, or select. selectedOptions supports native selects (including multiple selections) and ARIA combobox/listbox options marked aria-selected="true". selectedText returns the textbox's selected substring, an empty string for a caret, or null for input types without selection support. isChecked supports native checkbox/radio and ARIA checked controls; ARIA mixed state returns false.

Missing attributes return null (an empty attribute remains ""). Bounding boxes use CSS pixels relative to the page/frame viewport and return null for hidden or zero-area elements. Missing elements and incompatible control types raise errors. Use textContent() for raw text or innerText() for rendered text.

NativeApp and NativeAppLocator expose inputValue, isChecked, getAttribute, and boundingBox on Android, iOS, macOS, and Windows. Native attributes are platform accessibility/UI Automation properties, and native boxes use platform screen coordinates. Selected-option and selected-text reads remain web-only.

版本与发布记录

@allwright.dev/core 共发布 76 个版本,首次发布于 2026/08/26;过去 12 个月发布了 76 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/10/1722 天前
0.1.352026/10/1722 天前
0.1.342026/10/1722 天前
0.1.332026/10/1722 天前
0.1.322026/10/1622 天前
0.1.312026/10/1622 天前

关于 @allwright.dev/core 的常见问题

@allwright.dev/core 是什么?

High-level TypeScript client for the allwright automation engine.

如何安装 @allwright.dev/core?

在项目目录运行 npm install @allwright.dev/core,或使用 pnpm add / yarn add / bun add。

@allwright.dev/core 支持 TypeScript 吗?

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

@allwright.dev/core 支持 ESM 还是 CommonJS?

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

@allwright.dev/core 可以商用吗?

@allwright.dev/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@allwright.dev/core 的下载量有多少?

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

@allwright.dev/core 还在维护吗?

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