spana-test 0.1.0 → 0.3.0

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.
Files changed (131) hide show
  1. package/.agents/skills/spana-testing/SKILL.md +4 -1
  2. package/README.md +312 -86
  3. package/dist/accessibility-audit-RS3VIWRT.js +140 -0
  4. package/dist/accessibility-audit-RS3VIWRT.js.map +1 -0
  5. package/dist/agent/index.d.ts +14 -3
  6. package/dist/agent/index.js +10 -9
  7. package/dist/{allure-PTTVORQ6.js → allure-RNMEYTXS.js} +42 -2
  8. package/dist/allure-RNMEYTXS.js.map +1 -0
  9. package/dist/appium-server-66GVUL24.js +119 -0
  10. package/dist/appium-server-66GVUL24.js.map +1 -0
  11. package/dist/baseline-manager-5TIUCNP5.js +38 -0
  12. package/dist/baseline-manager-5TIUCNP5.js.map +1 -0
  13. package/dist/chunk-24KSKK2I.js +1289 -0
  14. package/dist/chunk-24KSKK2I.js.map +1 -0
  15. package/dist/chunk-3J4NG7JU.js +80 -0
  16. package/dist/chunk-3J4NG7JU.js.map +1 -0
  17. package/dist/{chunk-5XO6S7AI.js → chunk-3TRMQCUT.js} +5 -4
  18. package/dist/chunk-3TRMQCUT.js.map +1 -0
  19. package/dist/{chunk-V62HFH6E.js → chunk-4OHBO7LD.js} +23 -8
  20. package/dist/chunk-4OHBO7LD.js.map +1 -0
  21. package/dist/chunk-5245YBLL.js +127 -0
  22. package/dist/chunk-5245YBLL.js.map +1 -0
  23. package/dist/{chunk-VDWWIVM6.js → chunk-7IA2XG3G.js} +119 -69
  24. package/dist/chunk-7IA2XG3G.js.map +1 -0
  25. package/dist/{chunk-RJ5VPHVX.js → chunk-7VOWF42B.js} +42 -8
  26. package/dist/chunk-7VOWF42B.js.map +1 -0
  27. package/dist/{chunk-WIJYK22K.js → chunk-DSTUWLSW.js} +15 -4
  28. package/dist/chunk-DSTUWLSW.js.map +1 -0
  29. package/dist/{chunk-53MUJUJY.js → chunk-FJAJ4YNC.js} +17 -4
  30. package/dist/chunk-FJAJ4YNC.js.map +1 -0
  31. package/dist/chunk-IHVZKQQW.js +24 -0
  32. package/dist/chunk-IHVZKQQW.js.map +1 -0
  33. package/dist/{chunk-CKJQX73M.js → chunk-KAKHFSVA.js} +987 -240
  34. package/dist/chunk-KAKHFSVA.js.map +1 -0
  35. package/dist/chunk-KJPHH2TW.js +168 -0
  36. package/dist/chunk-KJPHH2TW.js.map +1 -0
  37. package/dist/chunk-OBCFACUW.js +28 -0
  38. package/dist/chunk-OBCFACUW.js.map +1 -0
  39. package/dist/{chunk-RK4Z6C7M.js → chunk-QPIE3IMG.js} +65 -69
  40. package/dist/chunk-QPIE3IMG.js.map +1 -0
  41. package/dist/{chunk-PWEOJKUF.js → chunk-X2TJP7LB.js} +26 -7
  42. package/dist/chunk-X2TJP7LB.js.map +1 -0
  43. package/dist/chunk-YXQEPVEW.js +372 -0
  44. package/dist/chunk-YXQEPVEW.js.map +1 -0
  45. package/dist/cli.js +332 -41
  46. package/dist/cli.js.map +1 -1
  47. package/dist/{compiler-G75RIIYS.js → compiler-X6WTFMYF.js} +16 -8
  48. package/dist/compiler-X6WTFMYF.js.map +1 -0
  49. package/dist/config-loader-QM72GKEL.js +9 -0
  50. package/dist/{console-FV4RJPO4.js → console-7UW7VROK.js} +109 -7
  51. package/dist/console-7UW7VROK.js.map +1 -0
  52. package/dist/{discover-RWBKI5IB.js → discover-NPNF6SWQ.js} +4 -3
  53. package/dist/doctor-command-C3SEQGRQ.js +71 -0
  54. package/dist/doctor-command-C3SEQGRQ.js.map +1 -0
  55. package/dist/{element-CGteXiXB.d.ts → element-DZ0HyJ3C.d.ts} +2 -0
  56. package/dist/flow-CW0_j7tw.d.ts +146 -0
  57. package/dist/gherkin/steps.d.ts +2 -2
  58. package/dist/{html-JP2HBIJQ.js → html-F3X3XPSX.js} +100 -9
  59. package/dist/html-F3X3XPSX.js.map +1 -0
  60. package/dist/index.d.ts +167 -3
  61. package/dist/index.js +6 -3
  62. package/dist/index.js.map +1 -1
  63. package/dist/{init-command-CELKL2CX.js → init-command-U66XCM66.js} +4 -3
  64. package/dist/init-command-U66XCM66.js.map +1 -0
  65. package/dist/init-flow-command-PR7J5FBM.js +37 -0
  66. package/dist/init-flow-command-PR7J5FBM.js.map +1 -0
  67. package/dist/{installer-R6NX7BYQ.js → installer-W5DITECS.js} +3 -2
  68. package/dist/{ios-ZZU6DHH7.js → ios-3GRECXAP.js} +3 -2
  69. package/dist/{junit-UDY5JG22.js → junit-HLC62MK6.js} +2 -2
  70. package/dist/junit-HLC62MK6.js.map +1 -0
  71. package/dist/machine-6H25TRTU.js +16 -0
  72. package/dist/provider-YIPU5K42.js +12 -0
  73. package/dist/{redact-IDA3C4UH.js → redact-U72BUBBR.js} +2 -2
  74. package/dist/{redact-IDA3C4UH.js.map → redact-U72BUBBR.js.map} +1 -1
  75. package/dist/{runner-QEF6PJOE.js → runner-6HK62Q7B.js} +2 -2
  76. package/dist/screenshot-compare-JFHH2WR4.js +75 -0
  77. package/dist/screenshot-compare-JFHH2WR4.js.map +1 -0
  78. package/dist/{server-MMK7PZIH.js → server-MZERO364.js} +401 -69
  79. package/dist/server-MZERO364.js.map +1 -0
  80. package/dist/session-3UZ5WAAD.js +17 -0
  81. package/dist/storybook-BK2JE4ld.d.ts +447 -0
  82. package/dist/{studio-command-CDVPREMG.js → studio-command-5BUER2RH.js} +2 -2
  83. package/dist/test-command-2PXTHASW.js +3161 -0
  84. package/dist/test-command-2PXTHASW.js.map +1 -0
  85. package/dist/validator-HZ2A3NEI.js +17 -0
  86. package/dist/validator-HZ2A3NEI.js.map +1 -0
  87. package/package.json +6 -1
  88. package/studio-dist/assets/index-C-Io44gy.js +193 -0
  89. package/studio-dist/assets/index-DfM9lK4p.css +1 -0
  90. package/studio-dist/index.html +2 -2
  91. package/dist/allure-PTTVORQ6.js.map +0 -1
  92. package/dist/chunk-53MUJUJY.js.map +0 -1
  93. package/dist/chunk-5XO6S7AI.js.map +0 -1
  94. package/dist/chunk-BZRLA4Z3.js +0 -82
  95. package/dist/chunk-BZRLA4Z3.js.map +0 -1
  96. package/dist/chunk-CKJQX73M.js.map +0 -1
  97. package/dist/chunk-PANFRTIU.js +0 -310
  98. package/dist/chunk-PANFRTIU.js.map +0 -1
  99. package/dist/chunk-PWEOJKUF.js.map +0 -1
  100. package/dist/chunk-RJ5VPHVX.js.map +0 -1
  101. package/dist/chunk-RK4Z6C7M.js.map +0 -1
  102. package/dist/chunk-U564GCO2.js +0 -259
  103. package/dist/chunk-U564GCO2.js.map +0 -1
  104. package/dist/chunk-V62HFH6E.js.map +0 -1
  105. package/dist/chunk-VDWWIVM6.js.map +0 -1
  106. package/dist/chunk-WIJYK22K.js.map +0 -1
  107. package/dist/compiler-G75RIIYS.js.map +0 -1
  108. package/dist/config-Dg9O0rcQ.d.ts +0 -219
  109. package/dist/config-loader-JJ5RPP53.js +0 -9
  110. package/dist/console-FV4RJPO4.js.map +0 -1
  111. package/dist/flow-D-_tlLpp.d.ts +0 -99
  112. package/dist/html-JP2HBIJQ.js.map +0 -1
  113. package/dist/init-command-CELKL2CX.js.map +0 -1
  114. package/dist/junit-UDY5JG22.js.map +0 -1
  115. package/dist/provider-CUWPULGC.js +0 -10
  116. package/dist/server-MMK7PZIH.js.map +0 -1
  117. package/dist/session-FBJABNXL.js +0 -16
  118. package/dist/test-command-SB5KYPQI.js +0 -1929
  119. package/dist/test-command-SB5KYPQI.js.map +0 -1
  120. package/dist/validator-CFQ55NUQ.js +0 -13
  121. package/studio-dist/assets/index-CPdpC9i-.css +0 -1
  122. package/studio-dist/assets/index-L1Wd0vop.js +0 -183
  123. /package/dist/{config-loader-JJ5RPP53.js.map → config-loader-QM72GKEL.js.map} +0 -0
  124. /package/dist/{discover-RWBKI5IB.js.map → discover-NPNF6SWQ.js.map} +0 -0
  125. /package/dist/{installer-R6NX7BYQ.js.map → installer-W5DITECS.js.map} +0 -0
  126. /package/dist/{ios-ZZU6DHH7.js.map → ios-3GRECXAP.js.map} +0 -0
  127. /package/dist/{provider-CUWPULGC.js.map → machine-6H25TRTU.js.map} +0 -0
  128. /package/dist/{runner-QEF6PJOE.js.map → provider-YIPU5K42.js.map} +0 -0
  129. /package/dist/{session-FBJABNXL.js.map → runner-6HK62Q7B.js.map} +0 -0
  130. /package/dist/{validator-CFQ55NUQ.js.map → session-3UZ5WAAD.js.map} +0 -0
  131. /package/dist/{studio-command-CDVPREMG.js.map → studio-command-5BUER2RH.js.map} +0 -0
@@ -66,13 +66,16 @@ export default flow(
66
66
  | `app.inputText(text)` | Type text into focused element |
67
67
  | `app.pressKey(key)` | Press a keyboard key |
68
68
  | `app.hideKeyboard()` | Dismiss keyboard |
69
+ | `app.dismissKeyboard(opts?)` | Platform-aware keyboard dismissal |
69
70
  | `app.swipe(direction, opts?)` | Swipe: "up"/"down"/"left"/"right" |
70
71
  | `app.scroll(direction)` | Scroll (slower swipe) |
72
+ | `app.scrollUntilVisible(sel)` | Scroll until target is visible |
71
73
  | `app.launch(opts?)` | Launch/relaunch app |
72
74
  | `app.stop()` / `app.kill()` | Stop or force-kill app |
73
75
  | `app.clearState()` | Clear app data |
74
76
  | `app.openLink(url)` | Open deep link or URL |
75
77
  | `app.back()` | Navigate back |
78
+ | `app.backUntilVisible(sel)` | Back until target is visible |
76
79
  | `app.takeScreenshot(name?)` | Capture screenshot |
77
80
  | `app.evaluate(fn, ...args)` | Run JS in web context |
78
81
 
@@ -172,7 +175,7 @@ await app.tap({ testID: "email-input" });
172
175
  await app.inputText("user@example.com");
173
176
  await app.tap({ testID: "password-input" });
174
177
  await app.inputText("secret123");
175
- await app.hideKeyboard();
178
+ await app.dismissKeyboard();
176
179
  await app.tap({ testID: "submit-btn" });
177
180
  await expect({ testID: "dashboard" }).toBeVisible();
178
181
  ```
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # spana
2
2
 
3
- TypeScript-native E2E testing for React Native + Web
3
+ TypeScript-native E2E testing for React Native + Web.
4
4
 
5
5
  [Documentation](https://wezter96.github.io/spana/) | [GitHub](https://github.com/wezter96/spana) | [npm](https://www.npmjs.com/package/spana-test) | [E2E Test Report](https://htmlpreview.github.io/?https://github.com/wezter96/spana/blob/main/docs/e2e-report.html)
6
6
 
@@ -8,13 +8,16 @@ TypeScript-native E2E testing for React Native + Web
8
8
 
9
9
  ## Features
10
10
 
11
- - Pure TypeScript — no YAML, no JVM, no app modification required
12
- - Cross-platform — Web, Android, iOS from a single test file
13
- - Web via Playwright (CDP), Android via UiAutomator2, iOS via WebDriverAgent
14
- - Agent-first design — JSON reporter, hierarchy dump, and selector discovery for AI agents
15
- - Auto-wait with configurable poll interval, settle timeout, and retries
16
- - Multiple reporters: console, JSON, JUnit XML, HTML
17
- - Artifact capture (screenshots + UI hierarchy) on failure
11
+ - Pure TypeScript flows, plus optional Gherkin / BDD `.feature` support
12
+ - Cross-platform execution across web, Android, and iOS from the same suite
13
+ - Local web via Playwright, local Android via UiAutomator2, local iOS via WebDriverAgent, plus Appium cloud mode
14
+ - Smart waits, retries, relative selectors, and per-flow stability defaults
15
+ - Reporters: console, JSON, JUnit XML, HTML, and Allure
16
+ - Artifacts on failure or success: screenshots, UI hierarchy dumps, and per-step capture
17
+ - App auto-install with `appPath`, iOS device signing, and BrowserStack / Sauce helper services
18
+ - CLI tooling for teams and agents: `validate`, `validate-config`, `init`, `studio`, `selectors`, `hierarchy`, and `devices`
19
+ - Execution controls for targeted and CI runs: `--device`, `--shard`, `--bail`, `--debug-on-failure`
20
+ - Browser helpers for network/auth state plus WebView / hybrid context APIs where the driver supports them
18
21
 
19
22
  ---
20
23
 
@@ -34,23 +37,36 @@ import { defineConfig } from "spana-test";
34
37
  export default defineConfig({
35
38
  apps: {
36
39
  web: { url: "http://localhost:3000" },
37
- android: { packageName: "com.example.app" },
38
- ios: { bundleId: "com.example.app" },
40
+ android: {
41
+ packageName: "com.example.app",
42
+ appPath: "./builds/app.apk",
43
+ },
44
+ ios: {
45
+ bundleId: "com.example.app",
46
+ appPath: "./builds/MyApp.app",
47
+ },
39
48
  },
40
49
  platforms: ["web", "android"],
50
+ reporters: ["console", "html"],
51
+ artifacts: {
52
+ outputDir: ".spana/artifacts",
53
+ captureOnFailure: true,
54
+ },
41
55
  });
42
56
  ```
43
57
 
44
- Create `flows/login.ts`:
58
+ Create `flows/login.flow.ts`:
45
59
 
46
60
  ```ts
47
61
  import { flow } from "spana-test";
48
62
 
49
63
  export default flow("user can log in", async ({ app, expect }) => {
50
64
  await app.tap({ testID: "email-input" });
51
- await app.typeText("user@example.com");
65
+ await app.inputText("user@example.com");
66
+ await app.dismissKeyboard();
52
67
  await app.tap({ testID: "password-input" });
53
- await app.typeText("secret");
68
+ await app.inputText("secret");
69
+ await app.dismissKeyboard();
54
70
  await app.tap({ testID: "login-button" });
55
71
  await expect({ testID: "home-screen" }).toBeVisible();
56
72
  });
@@ -59,11 +75,27 @@ export default flow("user can log in", async ({ app, expect }) => {
59
75
  Run:
60
76
 
61
77
  ```bash
78
+ spana validate-config
79
+ spana validate ./flows
62
80
  spana test
63
81
  ```
64
82
 
65
83
  ---
66
84
 
85
+ ## Capability Matrix
86
+
87
+ | Capability | Web | Local Android / iOS | Appium cloud |
88
+ | ---------------------------------------------------- | --- | -------------------------------- | ------------------------------------------ |
89
+ | TypeScript `.flow.ts` suites | Yes | Yes | Yes |
90
+ | Gherkin `.feature` suites | Yes | Yes | Yes |
91
+ | Smart waits, retries, relative selectors | Yes | Yes | Yes |
92
+ | HTML / JUnit / Allure reports and artifacts | Yes | Yes | Yes |
93
+ | App install / app reference handling | n/a | Yes, via `appPath` | Yes, via capabilities and provider helpers |
94
+ | Browser helpers (`mockNetwork`, cookies, auth state) | Yes | No | No |
95
+ | WebView context APIs | n/a | Android yes, iOS via Appium mode | Yes |
96
+
97
+ ---
98
+
67
99
  ## Writing Flows
68
100
 
69
101
  ### Basic API
@@ -71,74 +103,104 @@ spana test
71
103
  ```ts
72
104
  import { flow } from "spana-test";
73
105
 
74
- export default flow("flow name", async ({ app, expect, platform }) => {
75
- // tap, type, scroll
76
- await app.tap({ text: "Sign In" });
77
- await app.typeText("hello");
78
- await app.scroll({ direction: "down" });
79
-
80
- // assertions
81
- await expect({ testID: "welcome" }).toBeVisible();
82
- await expect({ text: "Welcome" }).toBeVisible();
83
-
84
- // platform branching
85
- if (platform === "web") {
86
- await app.tap({ testID: "web-only-button" });
87
- }
88
- });
89
- ```
90
-
91
- ### With config
92
-
93
- ```ts
94
106
  export default flow(
95
107
  "checkout flow",
96
- { tags: ["smoke", "payments"], platforms: ["android", "ios"], timeout: 60000 },
108
+ {
109
+ tags: ["smoke", "payments"],
110
+ platforms: ["android", "ios"],
111
+ timeout: 60_000,
112
+ defaults: {
113
+ waitForIdleTimeout: 250,
114
+ typingDelay: 20,
115
+ },
116
+ },
97
117
  async ({ app, expect }) => {
98
- // ...
118
+ await app.tap({ text: "Sign In" });
119
+ await app.inputText("hello@example.com");
120
+ await app.dismissKeyboard();
121
+
122
+ await app.scrollUntilVisible({ testID: "order-summary" });
123
+ await app.doubleTap({ testID: "promo-card" });
124
+ await app.longPress({ testID: "options-trigger" });
125
+ await app.scroll("down");
126
+
127
+ await expect({ testID: "welcome" }).toBeVisible();
128
+ await expect({ text: "Welcome" }).toBeVisible();
99
129
  },
100
130
  );
101
131
  ```
102
132
 
133
+ Use `scrollUntilVisible()` for off-screen targets instead of hand-written scroll loops. Use `dismissKeyboard()` for a platform-aware keyboard close path, and `backUntilVisible()` when you want system back navigation to stop on a known screen. Tap-like actions also prefer the nearest actionable container for nested label-inside-button layouts.
134
+
103
135
  ### FlowConfig options
104
136
 
105
- | Option | Type | Default | Description |
106
- | ------------ | ------------ | -------------- | ------------------------------ |
107
- | `tags` | `string[]` | — | Tag for filtering with `--tag` |
108
- | `platforms` | `Platform[]` | all | Restrict to specific platforms |
109
- | `timeout` | `number` | config default | Timeout in ms for this flow |
110
- | `autoLaunch` | `boolean` | `true` | Launch app before flow starts |
137
+ | Option | Type | Default | Description |
138
+ | ------------ | ---------------- | -------------- | -------------------------------------------- |
139
+ | `tags` | `string[]` | - | Tags for `--tag` filtering |
140
+ | `platforms` | `Platform[]` | all | Restrict a flow to specific platforms |
141
+ | `timeout` | `number` | config default | Flow timeout in ms |
142
+ | `autoLaunch` | `boolean` | `true` | Launch app before the flow starts |
143
+ | `when` | `WhenCondition` | - | Conditionally run by platform or env |
144
+ | `artifacts` | `ArtifactConfig` | config default | Per-flow artifact overrides |
145
+ | `defaults` | `FlowDefaults` | config default | Per-flow wait / typing / stability overrides |
146
+
147
+ ### BDD parity
148
+
149
+ Spana can compile `.feature` files into the same runtime as `.flow.ts` files. Keep Gherkin scenarios for high-value readable coverage, and use step definitions for reuse:
150
+
151
+ ```gherkin
152
+ Feature: Login
153
+ Scenario: Signed-out user logs in
154
+ Given I am on the login screen
155
+ When I type valid credentials
156
+ Then I should see the home screen
157
+ ```
111
158
 
112
159
  ---
113
160
 
114
161
  ## CLI Commands
115
162
 
116
- | Command | Description |
117
- | ----------------------- | ------------------------------------------------- |
118
- | `spana test [path]` | Run test flows (default: `./flows`) |
119
- | `spana hierarchy` | Dump full element hierarchy as JSON |
120
- | `spana selectors` | List actionable elements with suggested selectors |
121
- | `spana validate [path]` | Validate flow files without a device connection |
122
- | `spana devices` | List connected devices across all platforms |
123
- | `spana version` | Show version |
163
+ | Command | Description |
164
+ | ------------------------------ | ------------------------------------------------- |
165
+ | `spana test [path]` | Run test flows (default: `./flows`) |
166
+ | `spana hierarchy` | Dump full element hierarchy as JSON |
167
+ | `spana selectors` | List actionable elements with suggested selectors |
168
+ | `spana validate [path]` | Validate flow files without a device connection |
169
+ | `spana validate-config [path]` | Validate `spana.config.ts` without running flows |
170
+ | `spana doctor` | Check environment readiness before a run |
171
+ | `spana studio` | Launch Spana Studio |
172
+ | `spana init` | Scaffold a new Spana project |
173
+ | `spana init-flow <name>` | Generate a starter `.flow.ts` file |
174
+ | `spana devices` | List connected devices across all platforms |
175
+ | `spana version` | Show version |
124
176
 
125
177
  ### test options
126
178
 
127
179
  ```bash
128
- spana test flows/login.ts # run a single file
129
- spana test --platform android,ios # target platforms (default: web)
130
- spana test --tag smoke # filter by tag
131
- spana test --grep "log in" # filter by name pattern
132
- spana test --reporter json # reporter format
133
- spana test --reporter html # self-contained HTML report
134
- spana test --config ./spana.config.ts # explicit config path
180
+ spana test flows/login.flow.ts # run a single file
181
+ spana test --platform android,ios # target platforms
182
+ spana test --device emulator-5554 # target a specific local device
183
+ spana test --tag smoke --grep "log in" # filter flows
184
+ spana test --reporter html,allure # choose reporters
185
+ spana test --retries 2 --shard 1/3 --bail 5 # CI-friendly execution
186
+ spana test --last-failed # rerun only previous failures
187
+ spana test --watch # rerun automatically on changes
188
+ spana test --parallel --workers 2 # parallelize across devices
189
+ spana test --update-baselines # refresh screenshot baselines
190
+ spana test --debug-on-failure # open REPL on the first failure
191
+ spana test --driver appium --appium-url $BROWSERSTACK_URL --caps ./caps/android.json --platform android
192
+ spana test --config ./spana.config.ts # explicit config path
135
193
  ```
136
194
 
137
- ### hierarchy / selectors options
195
+ ### inspection and debugging
138
196
 
139
197
  ```bash
140
198
  spana hierarchy --platform android --pretty
141
199
  spana selectors --platform ios
200
+ spana validate-config
201
+ spana doctor --platform android,ios
202
+ spana init-flow "checkout smoke" --preset smoke --platform web,android
203
+ spana studio --no-open
142
204
  ```
143
205
 
144
206
  ---
@@ -151,29 +213,56 @@ import { defineConfig } from "spana-test";
151
213
  export default defineConfig({
152
214
  apps: {
153
215
  web: { url: "http://localhost:3000" },
154
- android: { packageName: "com.example.app" },
155
- ios: { bundleId: "com.example.app" },
216
+ android: {
217
+ packageName: "com.example.app",
218
+ appPath: "./builds/app.apk",
219
+ },
220
+ ios: {
221
+ bundleId: "com.example.app",
222
+ appPath: "./builds/MyApp.app",
223
+ signing: { teamId: "ABCDE12345" },
224
+ },
156
225
  },
157
226
  execution: {
158
227
  web: {
159
228
  browser: "chromium",
160
229
  headless: true,
161
230
  storageState: "./auth/web-user.json",
231
+ storybook: {
232
+ url: "http://localhost:6006",
233
+ },
234
+ },
235
+ appium: {
236
+ serverUrl: process.env.BROWSERSTACK_URL,
237
+ capabilitiesFile: "./caps/browserstack-android.json",
238
+ reportToProvider: true,
239
+ browserstack: {
240
+ local: { enabled: true },
241
+ },
162
242
  },
163
243
  },
164
244
  platforms: ["web", "android", "ios"],
165
245
  flowDir: "./flows",
166
- reporters: ["console", "json", "html"],
246
+ reporters: ["console", "json", "html", "allure"],
167
247
  defaults: {
168
- waitTimeout: 5000, // ms to wait for element
169
- pollInterval: 200, // ms between polls
170
- settleTimeout: 300, // ms of stability before match
171
- retries: 2, // retries on action failure
248
+ waitTimeout: 5000,
249
+ pollInterval: 200,
250
+ settleTimeout: 300,
251
+ retries: 2,
252
+ waitForIdleTimeout: 250,
253
+ typingDelay: 20,
254
+ initialPollInterval: 50,
255
+ hierarchyCacheTtl: 100,
256
+ retryDelay: 0,
257
+ },
258
+ launchOptions: {
259
+ clearState: false,
172
260
  },
173
261
  artifacts: {
174
262
  outputDir: ".spana/artifacts",
175
- captureOnFailure: true, // screenshot + hierarchy on failure
263
+ captureOnFailure: true,
176
264
  captureOnSuccess: false,
265
+ captureSteps: false,
177
266
  screenshot: true,
178
267
  uiHierarchy: true,
179
268
  },
@@ -194,11 +283,13 @@ export default defineConfig({
194
283
  });
195
284
  ```
196
285
 
197
- `execution.web` controls the local Playwright runtime for web flows. Use it to switch browser engines, run headed for debugging, or preload a saved storage state file.
286
+ `appPath` lets Spana install the app automatically for local Android and iOS runs. `execution.appium.browserstack` and `execution.appium.saucelabs` can also manage uploaded app references plus BrowserStack Local / Sauce Connect lifecycles for cloud runs.
198
287
 
199
288
  ### Browser runtime helpers (web)
200
289
 
201
290
  ```ts
291
+ import { flow } from "spana-test";
292
+
202
293
  export default flow("web dashboard", async ({ app, platform }) => {
203
294
  if (platform !== "web") return;
204
295
 
@@ -208,35 +299,114 @@ export default flow("web dashboard", async ({ app, platform }) => {
208
299
  });
209
300
  await app.blockNetwork("**/analytics/**");
210
301
  await app.setNetworkConditions({ offline: false, latencyMs: 120 });
302
+ await app.evaluate(() => console.info("dashboard hydrated"));
303
+ console.log(await app.getConsoleLogs());
304
+ console.log(await app.getJSErrors());
211
305
  await app.saveCookies("./tmp/cookies.json");
212
306
  });
213
307
  ```
214
308
 
215
- `mockNetwork`, `blockNetwork`, `clearNetworkMocks`, `setNetworkConditions`, `saveCookies`, `loadCookies`, `saveAuthState`, and `loadAuthState` are web-only helpers backed by Playwright. Latency and throughput throttling require the Chromium browser runtime.
309
+ `mockNetwork`, `blockNetwork`, `clearNetworkMocks`, `setNetworkConditions`, `saveCookies`, `loadCookies`, `saveAuthState`, `loadAuthState`, `getConsoleLogs`, and `getJSErrors` are web-only helpers backed by local Playwright runs. Latency and throughput throttling require Chromium. When artifact capture is enabled, web failures also include captured console logs and JavaScript errors in `spana-output/` and the HTML report.
310
+
311
+ ### Storybook component flows (web)
312
+
313
+ ```ts
314
+ import { defineConfig, flow } from "spana-test";
315
+
316
+ // spana.config.ts
317
+ export default defineConfig({
318
+ apps: {
319
+ web: { url: "http://localhost:3000" },
320
+ },
321
+ execution: {
322
+ web: {
323
+ storybook: { url: "http://localhost:6006" },
324
+ },
325
+ },
326
+ });
327
+
328
+ // flows/button.flow.ts
329
+ export default flow("primary button story", async ({ app, expect, platform }) => {
330
+ if (platform !== "web") return;
331
+
332
+ await app.openStory("components-button--primary", {
333
+ args: { disabled: false, size: "lg" },
334
+ globals: { theme: "dark" },
335
+ });
336
+
337
+ await expect({ text: "Continue" }).toBeVisible();
338
+ });
339
+ ```
340
+
341
+ `app.openStory()` opens Storybook's isolated `iframe.html` entry inside Spana's existing browser runtime. That makes Storybook a good component surface for Spana web flows, screenshots, and accessibility checks. `execution.web.storybook.url` is optional; when omitted, `openStory()` falls back to `apps.web.url`. `args` and `globals` support simple scalar values (`string`, `number`, `boolean`, `null`).
342
+
343
+ ### Hybrid / WebView helpers
344
+
345
+ ```ts
346
+ import { flow } from "spana-test";
347
+
348
+ export default flow("hybrid checkout", async ({ app, platform }) => {
349
+ if (platform === "web") return;
350
+
351
+ const contexts = await app.getContexts();
352
+ await app.switchToWebView();
353
+ await app.switchToNativeApp();
354
+
355
+ console.log(contexts);
356
+ });
357
+ ```
358
+
359
+ Context APIs depend on driver support. Appium mode is the best path for iOS WebView automation.
216
360
 
217
361
  ---
218
362
 
219
363
  ## Selectors
220
364
 
221
- | Selector | Example | Notes |
222
- | -------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------- |
223
- | `testID` | `{ testID: "login-btn" }` | Preferred — maps to `accessibilityIdentifier` (iOS), `resource-id` (Android), `data-testid` (web) |
224
- | `text` | `{ text: "Sign In" }` | Visible label text, partial match supported |
225
- | `accessibilityLabel` | `{ accessibilityLabel: "Close" }` | OS accessibility label |
226
- | `point` | `{ point: { x: 100, y: 200 } }` | Absolute coordinate tap, use as last resort |
365
+ | Selector | Example | Notes |
366
+ | -------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------- |
367
+ | `testID` | `{ testID: "login-btn" }` | Preferred - maps to `accessibilityIdentifier` (iOS), `resource-id` (Android), and `data-testid` (web) |
368
+ | `text` | `{ text: "Sign In" }` | Visible label text, partial match supported |
369
+ | `accessibilityLabel` | `{ accessibilityLabel: "Close" }` | OS accessibility label |
370
+ | `point` | `{ point: { x: 100, y: 200 } }` | Absolute coordinate tap, use as a last resort |
227
371
 
228
372
  Selectors can be combined. When multiple fields are set, all must match.
229
373
 
374
+ ### Relative selectors
375
+
376
+ For actions that accept an extended selector, you can locate an element relative to another one:
377
+
378
+ ```ts
379
+ await app.tap({
380
+ selector: { testID: "confirm-button" },
381
+ below: { text: "Delete account" },
382
+ });
383
+ ```
384
+
385
+ Supported relations: `below`, `above`, `leftOf`, `rightOf`, and `childOf`.
386
+
387
+ ---
388
+
389
+ ## Tooling and Debugging
390
+
391
+ Spana ships a few built-in workflows that are easy to miss from the minimal quick start:
392
+
393
+ - `spana validate-config` catches config issues before a suite starts
394
+ - `spana init` scaffolds a starter project
395
+ - `spana devices` lists local execution targets
396
+ - `spana studio` launches a browser UI for inspection and test runs
397
+ - `--debug-on-failure` drops into an interactive REPL with bound `app` and driver context
398
+ - `--device`, `--shard`, and `--bail` help with targeted local runs and CI fan-out
399
+
230
400
  ---
231
401
 
232
402
  ## Agent Integration
233
403
 
234
404
  `spana` is designed for AI agent workflows:
235
405
 
236
- - `spana selectors --platform android` returns JSON with element details and suggested selectors — feed this to an agent to identify what to interact with
237
- - `spana hierarchy --platform web --pretty` dumps the full accessibility tree as structured JSON
238
- - `spana validate` exits non-zero on invalid flows — use in CI preflight
239
- - `--reporter json` emits structured JSON events to stdout — pipe to an agent for result analysis
406
+ - `spana selectors --platform android` returns JSON with element details and suggested selectors
407
+ - `spana hierarchy --platform web --pretty` dumps the accessibility tree as structured JSON
408
+ - `spana validate` exits non-zero on invalid flows, which works well as a preflight step
409
+ - `--reporter json` emits structured JSON events to stdout for downstream analysis
240
410
 
241
411
  Example agent loop:
242
412
 
@@ -245,29 +415,85 @@ Example agent loop:
245
415
  spana selectors --platform web | jq '.[] | select(.testID != null)'
246
416
 
247
417
  # 2. run a specific flow with JSON output
248
- spana test flows/login.ts --reporter json 2>&1 | jq '.results'
418
+ spana test flows/login.flow.ts --reporter json 2>&1 | jq '.results'
249
419
  ```
250
420
 
251
421
  ---
252
422
 
423
+ ## Cloud Testing
424
+
425
+ Spana supports running the same TypeScript flows on cloud device farms via Appium mode.
426
+
427
+ ```bash
428
+ # BrowserStack
429
+ spana test --driver appium --appium-url $BROWSERSTACK_URL --caps ./caps/browserstack-android.json --platform android
430
+
431
+ # Sauce Labs
432
+ spana test --driver appium --appium-url $SAUCE_URL --caps ./caps/saucelabs-android.json --platform android
433
+ ```
434
+
435
+ Or configure it in `spana.config.ts`:
436
+
437
+ ```ts
438
+ import { defineConfig } from "spana-test";
439
+
440
+ export default defineConfig({
441
+ execution: {
442
+ mode: "appium",
443
+ appium: {
444
+ serverUrl: process.env.BROWSERSTACK_URL,
445
+ capabilitiesFile: "./caps/browserstack-android.json",
446
+ reportToProvider: true,
447
+ browserstack: {
448
+ local: { enabled: true },
449
+ },
450
+ },
451
+ },
452
+ apps: {
453
+ android: {
454
+ packageName: "com.example.myapp",
455
+ appPath: "./builds/app.apk",
456
+ },
457
+ },
458
+ });
459
+ ```
460
+
461
+ Spana ships first-class helper services for **BrowserStack** and **Sauce Labs**:
462
+
463
+ - managed app upload and app reference resolution
464
+ - BrowserStack Local lifecycle management
465
+ - Sauce Connect lifecycle management
466
+ - provider result reporting
467
+
468
+ Generic Appium hubs still work even without provider-specific helpers.
469
+
470
+ Guides:
471
+
472
+ - [BrowserStack setup](https://github.com/wezter96/spana/blob/main/docs/cloud/browserstack.md)
473
+ - [Sauce Labs setup](https://github.com/wezter96/spana/blob/main/docs/cloud/saucelabs.md)
474
+ - [Example capabilities](https://github.com/wezter96/spana/tree/main/examples/caps)
475
+
476
+ ---
477
+
253
478
  ## Architecture
254
479
 
255
480
  spana uses a layered architecture: CLI -> TestRunner -> PlatformOrchestrator -> SmartLayer -> RawDriver.
256
481
 
257
- Raw drivers are thin HTTP clients. All selector matching, auto-wait, retry, and element resolution lives in the TypeScript SmartLayer — no logic in companion binaries.
482
+ Raw drivers are thin HTTP clients. All selector matching, auto-wait, retry, and element resolution lives in the TypeScript smart layer instead of companion binaries.
258
483
 
259
- See [ARCHITECTURE.md](./ARCHITECTURE.md) for details.
484
+ See [ARCHITECTURE.md](https://github.com/wezter96/spana/blob/main/ARCHITECTURE.md) for details.
260
485
 
261
486
  ---
262
487
 
263
488
  ## Platforms
264
489
 
265
- | Platform | Driver | Companion binary |
266
- | ------------- | -------------------------- | ----------------------------------------------------------------- |
267
- | Web / RN Web | Playwright (CDP) | None — Playwright is a dev dependency |
268
- | Android | UiAutomator2 HTTP client | Appium UiAutomator2 server APK (bundled, ~2-3 MB) |
269
- | iOS Simulator | WebDriverAgent HTTP client | WDA XCTest bundle (bundled unsigned, ~5 MB) |
270
- | iOS Device | Same WDA bundle | Re-signed with user certificate via `codesign`; requires `iproxy` |
490
+ | Platform | Driver | Companion binary |
491
+ | ------------- | --------------------------- | -------------------------------------------------------- |
492
+ | Web / RN Web | Playwright (CDP) | None - Playwright is a dev dependency |
493
+ | Android | UiAutomator2 HTTP client | Appium UiAutomator2 server APK (bundled) |
494
+ | iOS Simulator | WebDriverAgent HTTP client | WDA XCTest bundle (bundled unsigned) |
495
+ | iOS Device | Same WDA bundle | Re-signed with `codesign`; requires `iproxy` |
496
+ | Appium cloud | Appium 2 / 3 compatible hub | BrowserStack, Sauce Labs, or another W3C-compatible grid |
271
497
 
272
498
  ---
273
499