{"id":"9f8c1c017b454016","repo":"vitest-dev/vitest","slug":"switch-context-is-only-available-for-webdriverio-p","errorCode":null,"errorMessage":"Switch context is only available for WebDriverIO provider.","messagePattern":"Switch context is only available for WebDriverIO provider\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/rpc.ts","lineNumber":332,"sourceCode":"        cancelCurrentRun(reason) {\n          vitest.cancelCurrentRun(reason)\n        },\n        async resolveId(id, importer) {\n          return mockResolver.resolveId(id, importer)\n        },\n        debug(...args) {\n          vitest.logger.console.debug(...args)\n        },\n        getCountOfFailedTests() {\n          return vitest.state.getCountOfFailedTests()\n        },\n        async wdioSwitchContext(direction) {\n          const provider = project.browser!.provider\n          if (!provider) {\n            throw new Error('Commands are only available for browser tests.')\n          }\n          if (provider.name !== 'webdriverio') {\n            throw new Error('Switch context is only available for WebDriverIO provider.')\n          }\n          if (direction === 'iframe') {\n            await (provider as any).switchToTestFrame()\n          }\n          else {\n            await (provider as any).switchToMainFrame()\n          }\n        },\n        async triggerCommand(sessionId, command, testPath, payload) {\n          debug?.('[%s] Triggering command \"%s\"', sessionId, command)\n          const provider = project.browser!.provider\n          if (!provider) {\n            throw new Error('Commands are only available for browser tests.')\n          }\n          const context = Object.assign(\n            {\n              testPath,\n              project,","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/node/rpc.ts#L314-L350","documentation":"After confirming a provider exists, `wdioSwitchContext` checks `provider.name === 'webdriverio'`. Frame-switching is a WebDriver-specific operation; Playwright and the preview provider manage frames differently and don't expose this RPC.","triggerScenarios":"Calling `switchToTestFrame`/`switchToMainFrame` (via the `wdioSwitchContext` RPC) while running under Playwright or the preview provider.","commonSituations":"Migrating from WebDriverIO to Playwright without removing frame-switching calls; copy-pasted helpers from a WebDriverIO test suite into a Playwright project.","solutions":["Switch the project's provider to `webdriverio` if you need WebDriver-style frame switching.","Replace the call with the Playwright/preview equivalent (e.g. `page.frameLocator(...)` or `page.mainFrame()`).","Gate the call behind a provider check (`server.provider === 'webdriverio'`)."],"exampleFix":"// before — under playwright provider\nawait switchToTestFrame()\n\n// after — use provider-appropriate API\nimport { page } from 'vitest/browser'\nawait page.frameLocator('iframe').locator('#in').click()","handlingStrategy":"validation","validationCode":"function isWebdriverioProvider(provider: { name?: string }): boolean {\n  return provider?.name === 'webdriverio'\n}","typeGuard":"const isWebdriverioProvider = (p: { name?: string }): p is { name: 'webdriverio' } =>\n  p?.name === 'webdriverio'","tryCatchPattern":null,"preventionTips":["Use the WebDriverIO provider if you rely on WebDriver-style frame switching.","Replace with Playwright frame APIs (frameLocator) when on Playwright.","Guard helper code with `server.provider === 'webdriverio'`."],"tags":["webdriverio","browser-provider","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}