Automation: let tests drive a WebView's page (run a script, click, type)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, macos, react
- Domain
- desktop-dev, testing, tooling
Research direction
Start with the native automate command implementation and the WebView host path at emitEventNamed: in appkit_host.m; also inspect completeBridgeResponse in runtime/flow.zig for response-file handling. First run the existing automation verb list under -Dautomation=true and confirm how automation commands and bridge responses are queued and read. Done means automation-only WebView commands can evaluate scripts and exercise page controls, return reliable results, and keep each bridge response isolated without affecting packaged builds.
Written by the indexing model from the issue text.
Description
#226 is about seeing what a WebView does: navigation, console messages, and page content in native automate snapshot. This issue is about the other half, driving the page from automation, so that a WebView app can have end-to-end UI tests.
The problem
native automate drives canvas widgets through the real input paths, with widget-click, widget-key, and widget-action set_text. For a WebView it has only reload and bridge. A test can't click a button in the page, type into a field, or read what the page shows. This is true in 0.11.1, and the verb list on current main (4d47c2c) is the same.
The host can already run scripts in the page. emitEventNamed: in appkit_host.m calls evaluateJavaScript: to deliver window.zero._emit(...). Automation just has no verb that reaches it.
Outside tools can't fill the gap:
- Playwright attaches to a running browser only over the Chrome DevTools Protocol (
connectOverCDP), which WKWebView doesn't speak. Itswebkitbrowser is a separate build, so it loads the page without the app's bridge. - Safari's Web Inspector can open an inspectable WKWebView, but only by hand. Since 0.11.1, packaged builds aren't inspectable.
- The macOS accessibility API can reach the page's controls, as #226 notes. But sending keys needs the app in front, so the test takes over the user's keyboard, and it needs the Accessibility permission.
Reading results back has a second problem. bridge-response.txt holds one response, and completeBridgeResponse in runtime/flow.zig writes every bridge response there, including the page's own. A busy page can overwrite a test's answer before the CLI reads it.
Sage, a Native SDK 0.11.1 app, is a React page in a WKWebView. For its screenshots, it added app-specific native commands such as app.route:<route>. Each one emits a window event, and a listener in the page opens the screen. To test entries, the lock screen, setup, and chat end to end, we would have to add a test driver to the page: a module that waits for an event, clicks and types with DOM calls, and reports back through a bridge command. Every WebView app that wants UI tests would end up building the same thing.
The proposal
All of this would exist only in automation builds (-Dautomation=true), like the rest of native automate.
1. Run a script in a WebView and get its result
native automate webview-eval [--webview <label>] [--timeout-ms <n>] '<script>'
The host runs the script in the named WebView, main by default, with callAsyncJavaScript:arguments:inFrame:inContentWorld:completionHandler:, so the script can await. It writes the JSON result or the error to webview-result-<id>.txt, and the CLI prints it. Running in a separate WKContentWorld keeps the test's globals apart from the page's scripts, while the DOM stays shared.
This alone is enough to build a test: find an element, read its text, and check the page's state.
2. Real input to an element
native automate webview-click [--webview <label>] '<selector>'
native automate webview-fill [--webview <label>] '<selector>' '<text>'
native automate webview-key [--webview <label>] <key>
native automate webview-assert [--webview <label>] [--absent] '<selector>' ...
Clicks and keys made with DOM calls aren't trusted (isTrusted is false), and frameworks handle them differently from real input. Instead, the host could find the element's frame with a script. It could then send NSEvent mouse and key events, and insertText: for typing, straight to the WKWebView. The page would get trusted events through the same path a user's input takes. Ideally the app wouldn't need to be in front, and the user's pointer and keyboard would stay theirs. This matches widget-click and widget-key, which use the real input paths for canvas widgets.
A selector could be CSS, or a role and name in the form automate assert already uses, such as role=button name="Reset". webview-assert would poll, like automate assert.
We haven't checked whether WebKit takes these events while the app is in the background. If it doesn't, trusted input that needs the app in front is still better than what exists now.
3. One response file per bridge request
Write each automation bridge response to bridge-response-<id>.txt. Or publish only the responses to requests that automation sent (zero://inline). Either way, a busy page can't overwrite a test's answer.
Notes
- Automation builds only. None of this should be in a build without
-Dautomation=true. A packaged release must never let another process run scripts in its pages. - Who can send commands. Today, anything that can write to
.zig-cache/native-sdk-automation/can queue commands.webview-evalmakes that much more powerful, so it may deserve its own opt-in, such as-Dautomation-webview=true. - Results stay local. Results go to files in the automation folder, like snapshots. Page content may be private, so the CLI shouldn't write it anywhere else.
- Related: #226 (seeing what a WebView does) and #426 (TypeScript cores and WebViews).
- Dominant language
- Zig
- Stars
- 7.9k
- Forks
- 335
- Avg merge
- 10h 33m
- Merged PRs (30d)
- 147
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel-labs/native
-
Per-view widget layout budget (1024 nodes) drops whole frames on real multi-pane app viewsPossibly taken @slicenferqin claimed this 100 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vercel-labs/native#408 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
vercel-labs/native#387 ·
Maintainers usually reply within 1 day
-
macOS: the window frame event reports the frame size where everything else expects the content sizeOpen
Difficulty 1/5 Under an hour Newbie friendliness 84/100
vercel-labs/native#355 ·
Maintainers usually reply within 1 day
-
cef.zig: InstallResult.archive_path leaks on successPossibly taken @versecafe claimed this 206 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vercel-labs/native#32 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
vercel-labs/native#957 ·
Maintainers usually reply within 1 day
All issues in vercel-labs/native
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
GUI: the space panel stays stale after a run stops with no spacePossibly taken @nikkexe0-del claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
xevrion/hatchzip#237 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
flathub/org.ardour.Ardour#89 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Javis603/token-monitor#1861 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 1 day