@allwright.dev/vitest 0.0.44 → 0.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @allwright.dev/vitest
2
2
 
3
- Vitest fixtures for allwright with Playwright-style `browser` and `page` injection.
3
+ Vitest fixtures for allwright with Playwright-style `browser` and `page` injection, plus Android mobile fixtures for hybrid tests.
4
4
 
5
5
  Install:
6
6
 
@@ -16,6 +16,10 @@ test("opens a page", async ({ page }) => {
16
16
  const title = await page.textContent("h1");
17
17
  expect(title.text).toContain("Example");
18
18
  });
19
+
20
+ test("opens an Android app", async ({ androidPage }) => {
21
+ await androidPage.click('Id=com.example.airticket:id/bottom_nav_account');
22
+ });
19
23
  ```
20
24
 
21
25
  A checked-in example spec also lives in [examples/basic.spec.ts](./examples/basic.spec.ts).
@@ -29,9 +33,10 @@ schemaVersion: 1
29
33
  server:
30
34
  addr: 127.0.0.1:50051
31
35
 
32
- browser:
33
- name: firefox
34
- binary: /Applications/Firefox.app/Contents/MacOS/firefox
36
+ web:
37
+ browser:
38
+ name: firefox
39
+ binary: /Applications/Firefox.app/Contents/MacOS/firefox
35
40
 
36
41
  expect:
37
42
  timeoutMs: 7000
@@ -39,8 +44,9 @@ expect:
39
44
 
40
45
  suites:
41
46
  smoke:
42
- browser:
43
- name: chromium
47
+ web:
48
+ browser:
49
+ name: chromium
44
50
  ```
45
51
 
46
52
  Vitest can override or select from that shared config without switching to a Vitest-specific file:
@@ -54,3 +60,38 @@ test.use({
54
60
  }
55
61
  });
56
62
  ```
63
+
64
+ Android fixtures are available alongside the web fixtures:
65
+
66
+ ```ts
67
+ import { test } from "@allwright.dev/vitest";
68
+
69
+ test.use({
70
+ allwright: {
71
+ android: {
72
+ launchOptions: {
73
+ apkPath: "/absolute/path/to/app.apk",
74
+ appId: "com.example.airticket",
75
+ },
76
+ },
77
+ },
78
+ });
79
+
80
+ test("android only", async ({ androidPage }) => {
81
+ await androidPage.fill('xpath=//*[@text="Email"]', "user@example.com");
82
+ });
83
+
84
+ test("hybrid web and android", async ({ page, androidPage }) => {
85
+ await page.goto("https://example.com");
86
+ await androidPage.click('Id=com.example.airticket:id/bottom_nav_account');
87
+ });
88
+ ```
89
+
90
+ Available fixtures:
91
+
92
+ - `browser`: launched web browser
93
+ - `page`: initial web page
94
+ - `android`: connected Android device session
95
+ - `androidPage`: launched Android app page
96
+
97
+ `androidPage` launches using `allwright.android.launchOptions` first, then falls back to `config.mobile.android`.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,22 @@
1
- import { type Browser, type BrowserKind, type LaunchOptions, type Locator, type Page, type WaitForSelectorOptions } from "@allwright.dev/core";
1
+ import { type MobileAndroidConnectOptions, type MobileAndroidDevice, type MobileAndroidLaunchOptions, type MobileAndroidPage, type Browser, type BrowserKind, type LaunchOptions, type Locator, type Page, type WaitForSelectorOptions } from "@allwright.dev/core";
2
2
  import { expect as vitestExpect } from "vitest";
3
3
  export interface AllwrightVitestOptions {
4
4
  launchOptions?: LaunchOptions;
5
5
  serverAddr?: string;
6
6
  browser?: BrowserKind;
7
7
  browserBinary?: string;
8
+ android?: {
9
+ connectOptions?: MobileAndroidConnectOptions;
10
+ launchOptions?: MobileAndroidLaunchOptions;
11
+ };
8
12
  configFile?: string;
9
13
  suite?: string;
10
14
  }
11
15
  export interface AllwrightVitestFixtures {
12
16
  browser: Browser;
13
17
  page: Page;
18
+ android: MobileAndroidDevice;
19
+ androidPage: MobileAndroidPage;
14
20
  }
15
21
  export interface RetryExpectationOptions {
16
22
  timeoutMs?: number;
@@ -39,6 +45,8 @@ export interface LocatorExpectMatchers {
39
45
  export declare const test: import("vitest").TestAPI<{
40
46
  browser: Browser;
41
47
  page: Page;
48
+ android: MobileAndroidDevice;
49
+ androidPage: MobileAndroidPage;
42
50
  allwright: AllwrightVitestOptions;
43
51
  }>;
44
52
  type VitestExpect = typeof vitestExpect;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { launchConfiguredBrowser, resolveConfig, setServerAddr, shutdown, } from "@allwright.dev/core";
1
+ import { launchConfiguredBrowser, mobile, resolveConfig, setServerAddr, shutdown, } from "@allwright.dev/core";
2
2
  import { expect as vitestExpect, test as base } from "vitest";
3
3
  export const test = base.extend({
4
4
  allwright: async ({}, use) => {
@@ -23,6 +23,17 @@ export const test = base.extend({
23
23
  page: async ({ browser }, use) => {
24
24
  await use(browser.page());
25
25
  },
26
+ android: async ({ allwright }, use) => {
27
+ const config = resolveVitestConfig(allwright);
28
+ const android = await mobile.android.connect(resolveAndroidConnectOptions(config, allwright));
29
+ await use(android);
30
+ },
31
+ androidPage: async ({ android, allwright }, use) => {
32
+ const config = resolveVitestConfig(allwright);
33
+ const launchOptions = resolveAndroidLaunchOptions(config, allwright);
34
+ const page = await android.launch(launchOptions);
35
+ await use(page);
36
+ },
26
37
  });
27
38
  const DEFAULT_EXPECT_TIMEOUT_MS = 5_000;
28
39
  const DEFAULT_EXPECT_INTERVAL_MS = 100;
@@ -56,6 +67,27 @@ function resolveVitestConfig(options) {
56
67
  expect: config.expect,
57
68
  };
58
69
  }
70
+ function resolveAndroidConnectOptions(config, options) {
71
+ return {
72
+ device: options.android?.connectOptions?.device ?? config.mobile.android?.device,
73
+ adbEndpoint: options.android?.connectOptions?.adbEndpoint,
74
+ preserveAppState: options.android?.connectOptions?.preserveAppState ?? false,
75
+ timeoutMs: options.android?.connectOptions?.timeoutMs,
76
+ };
77
+ }
78
+ function resolveAndroidLaunchOptions(config, options) {
79
+ const launchOptions = {
80
+ apkPath: options.android?.launchOptions?.apkPath ?? config.mobile.android?.appBinary,
81
+ appId: options.android?.launchOptions?.appId ?? config.mobile.android?.appId,
82
+ launchActivity: options.android?.launchOptions?.launchActivity ?? config.mobile.android?.appActivity,
83
+ stopBeforeLaunch: options.android?.launchOptions?.stopBeforeLaunch ?? false,
84
+ timeoutMs: options.android?.launchOptions?.timeoutMs,
85
+ };
86
+ if (!launchOptions.apkPath && !launchOptions.appId) {
87
+ throw new Error("androidPage fixture requires android launch options with `apkPath` or `appId`, or config.mobile.android.app configured");
88
+ }
89
+ return launchOptions;
90
+ }
59
91
  async function retryExpectation(callback, options = {}, defaults = {}) {
60
92
  const timeoutMs = options.timeoutMs ?? defaults.timeoutMs ?? DEFAULT_EXPECT_TIMEOUT_MS;
61
93
  const intervalMs = options.intervalMs ?? defaults.intervalMs ?? DEFAULT_EXPECT_INTERVAL_MS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allwright.dev/vitest",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "description": "Vitest fixtures for the allwright TypeScript client.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,7 +39,7 @@
39
39
  "prepublishOnly": "bun run build"
40
40
  },
41
41
  "dependencies": {
42
- "@allwright.dev/core": "0.0.44"
42
+ "@allwright.dev/core": "0.0.46"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.9.2",