fix(e2e): cross-protocol browser.execute() — works with both WebDriver + CDP

Root cause: WebDriverIO devtools protocol wraps functions in a polyfill
that puts `return` inside eval() (not a function body) → "Illegal return".

Fix: exec() wrapper in helpers/execute.ts converts function args to IIFE
strings before passing to browser.execute(). Works identically on both
WebDriver (Tauri) and CDP/devtools (Electrobun CEF).

- 35 spec files updated (browser.execute → exec)
- 4 config files updated (string-form expressions)
- helpers/actions.ts + assertions.ts updated
- 560 vitest + 116 cargo passing
This commit is contained in:
Hibryda 2026-03-22 06:33:55 +01:00
parent 407e49cc32
commit 6a8181f33a
42 changed files with 630 additions and 541 deletions

View file

@ -1,17 +1,17 @@
/**
* Custom E2E assertions domain-specific checks for Agent Orchestrator.
*
* Uses browser.execute() for DOM queries with dual selectors to support
* both Tauri and Electrobun UIs (WebKitGTK reliability).
* Uses exec() (cross-protocol safe wrapper) for DOM queries with dual
* selectors to support both Tauri and Electrobun UIs.
*/
import { browser, expect } from '@wdio/globals';
import { exec } from './execute.ts';
import * as S from './selectors.ts';
/** Assert that a project card with the given name is visible in the grid */
export async function assertProjectVisible(name: string): Promise<void> {
const found = await browser.execute((n: string) => {
// Tauri: .project-box | Electrobun: .project-card | Both: .project-header
const found = await exec((n: string) => {
const cards = document.querySelectorAll('.project-box, .project-card, .project-header');
for (const card of cards) {
if (card.textContent?.includes(n)) return true;
@ -31,7 +31,7 @@ export async function assertTerminalResponds(): Promise<void> {
/** Assert that a CSS custom property has changed after a theme switch */
export async function assertThemeApplied(varName = '--ctp-base'): Promise<void> {
const value = await browser.execute((v: string) => {
const value = await exec((v: string) => {
return getComputedStyle(document.documentElement).getPropertyValue(v).trim();
}, varName);
expect(value.length).toBeGreaterThan(0);
@ -49,12 +49,12 @@ export async function assertSettingsPersist(selector: string): Promise<void> {
export async function assertStatusBarComplete(): Promise<void> {
await browser.waitUntil(
async () =>
browser.execute(() => {
exec(() => {
const el = document.querySelector('[data-testid="status-bar"]')
?? document.querySelector('.status-bar');
if (!el) return false;
return getComputedStyle(el).display !== 'none';
}) as Promise<boolean>,
}),
{ timeout: 10_000, timeoutMsg: 'Status bar not visible within 10s' },
);
}
@ -65,7 +65,7 @@ export async function assertElementCount(
expected: number,
comparison: 'eq' | 'gte' | 'lte' = 'eq',
): Promise<void> {
const count = await browser.execute((sel: string) => {
const count = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, selector);
@ -78,7 +78,7 @@ export async function assertElementCount(
/** Assert an element has a specific CSS class */
export async function assertHasClass(selector: string, className: string): Promise<void> {
const hasIt = await browser.execute((sel: string, cls: string) => {
const hasIt = await exec((sel: string, cls: string) => {
const el = document.querySelector(sel);
return el?.classList.contains(cls) ?? false;
}, selector, className);