# WebdriverIO v10 documentation: WebdriverIO Session > 6 pages. Index of all sections: https://webdriver.io/llms.txt --- Source: https://webdriver.io/docs/session.md # wdio session `wdio session` keeps one WebdriverIO session alive across many short shell commands. Use it to explore a UI, check a change, and turn the steps that worked into a test. It is part of `@wdio/cli` (WebdriverIO v10). ``` npx wdio session open chrome http://localhost:3000 npx wdio session snapshot --interactive npx wdio session click e3 npx wdio session export --out test/specs/cart.e2e.ts npx wdio session close ``` The session is named `default`. Pass `-s ` only when you need two sessions at once. The [targets](/docs/session/targets.md) page drives one Expo guinea pig in a headed Chrome window and in an Electron window, both at a desktop size. Android and iOS commands for the same app are on that page. ## Install[​](#install "Direct link to Install") `wdio session` is part of the WebdriverIO CLI. `npx wdio` installs the unscoped [`wdio`](https://www.npmjs.com/package/wdio) package and runs that CLI. You do not install `@wdio/session` yourself. ``` npx wdio session --help npx wdio session click --help ``` `--help` prints the workflow, the actions by group, global flags and exit codes. ` --help` prints that action's arguments, flags, platforms, examples and related actions. The same text is on the [commands](/docs/session-commands.md) page. The agent skill keeps only the core loop and sends agents to `--help` for the rest, so it does not go stale when the CLI changes. Scaffold a project with: ``` npm init wdio@latest ``` Accept "Set up coding agent support" to write `.agents/skills/wdio-session/SKILL.md`, an `AGENTS.md` section and a `.wdio/session/` gitignore entry. Install the skill later with: ``` npx wdio session skill --install . ``` `npx wdio session doctor` checks Node.js, the browser, Appium, SDKs and cloud credentials. `doctor ` checks only what that target needs. The process exits 1 when a check fails. ## Open a page and act on it[​](#open-a-page-and-act-on-it "Direct link to Open a page and act on it") Open headless Chrome (add `--headed` to show the window). `open` prints the page's interactive elements: ``` npx wdio session open chrome http://localhost:3000 ``` An element looks like `button "Add to cart" [ref=e3]`. Use that ref. Every action reports what it changed on the page, with refs for new elements, so you rarely need a separate `snapshot`: ``` npx wdio session click e3 npx wdio session exec -e "await expect($('aria/Cart (1)')).toBeDisplayed()" ``` `open firefox`, `open edge` and `open safari` take the same URL. Chrome, Firefox and Edge are downloaded on first use when they are not installed. Safari requires macOS. ### Android[​](#android "Direct link to Android") Android and iOS run through Appium 3. `doctor android` reports a missing server or driver with the install command. ``` npx wdio session doctor android npx wdio session open android --app ./shop.apk npx wdio session snapshot --interactive npx wdio session tap e3 ``` iOS: `open ios --bundle-id com.example.shop`. Native desktop: `open macos --bundle-id com.example.shop` and `open windows --app Root`. ### Electron[​](#electron "Direct link to Electron") ``` npx wdio session open electron ./main.js npx wdio session snapshot --interactive npx wdio session click e2 ``` `open tauri ./my-app` and `open dioxus ./my-app` need their driver on `PATH`. On Linux without `DISPLAY` or `WAYLAND_DISPLAY`, install Xvfb or weston. ## Observation and refs[​](#observation-and-refs "Direct link to Observation and refs") | Command | Use it for | | ------------------------ | ------------------------------------------------------------------------------------- | | `snapshot --interactive` | The elements you can act on, each with a ref | | `snapshot --compact` | The same tree with unnamed empty wrappers removed | | `snapshot --urls` | Link addresses on each link | | `find "Add to cart"` | A line from a fresh snapshot | | `diff` | What changed since the previous snapshot | | `screenshot` | Layout. Skip it when a snapshot answers the question | | `pdf` | A PDF of the current page (`pdf report.pdf`). BiDi sessions print headed and headless | | `source` | The page HTML or the native XML | Refs come from the latest snapshot. After navigation, snapshot again. An old ref fails with `REF_STALE`. An unknown ref fails with `REF_NOT_FOUND`. ## `exec`[​](#exec "Direct link to exec") `exec` runs WebdriverIO code. Always `await` commands. `$` returns one element and throws when it is missing. There is no sync mode and no `browser.element`. ``` npx wdio session exec -e "await browser.getTitle()" npx wdio session <<'JS' await $('aria/Cart (1)').waitForDisplayed() JS ``` Put assertions in `exec` with `expect-webdriverio`. Use `visual check ` (needs `@wdio/visual-service`) when the question is how the screen looks. ## Export[​](#export "Direct link to Export") `export` writes a spec from the recorded steps. Refs are replaced with stable selectors. ``` npx wdio session export --out test/specs/cart.e2e.ts npx wdio run wdio.conf.ts --spec test/specs/cart.e2e.ts npx wdio session close ``` `open firefox`, `open edge` and `open safari` take the same URL. Other targets, snapshots, `exec`, export and a paused test run are separate pages in this section. ## This section[​](#this-section "Direct link to This section") | Page | Use it for | | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- | | [Targets](/docs/session/targets.md) | Browsers, Android, iOS, desktop, Electron, Tauri, Dioxus and cloud devices, including the demo app in Chrome, Android and Electron | | [Snapshots and refs](/docs/session/snapshots.md) | What is on screen, and the refs you click | | [Run code](/docs/session/exec.md) | `exec`, assertions and visual checks | | [Export a test](/docs/session/export.md) | Specs, page objects and `.wdio/helpers` | | [Debug a test](/docs/session/debug.md) | `wdio run --debug=agent` and `wdio repl --session` | | [Commands](/docs/session-commands.md) | Every action and flag | ## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting") | Message | What to do | | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `SESSION_EXISTS` | The name is already running. Use `-s` another name, or `open --replace`. | | `REF_STALE` / `REF_NOT_FOUND` | Run `snapshot` again and use a ref from that output. | | `NOT_EDITABLE` | The `fill` target is not an editable field and has no single editable field inside it (or behind `aria-controls`/`aria-owns`/label). Run `snapshot --scope ` and fill the field ref. | | `MISSING_DEPENDENCY` | Install the package named in the error, or run `wdio session doctor `. | | `MISSING_APPIUM_DRIVER` | Run the `npx appium driver install …` line from the error. | | `MISSING_CREDENTIALS` | Export the named variables. Doctor never prints their values. | | `Session closed from wdio session` | The debug session was closed. Resume instead of close when the test should continue. | Exit codes: 0 success, 1 the action failed, 2 usage, 3 a missing dependency or credentials, 4 no session with that name. ## Next steps[​](#next-steps "Direct link to Next steps") * [Targets](/docs/session/targets.md) — open a browser, an Android or iOS app, or an Electron window * [WebdriverIO for Coding Agents](/docs/ai-agents.md) — skill, docs and project rules * [wdio session commands](/docs/session-commands.md) — every action and flag --- Source: https://webdriver.io/docs/session/targets.md # Session targets `wdio session open` starts the session. The first argument is the target. Reuse the `default` session. Pass `-s ` only when you need two sessions at once. Run `npx wdio session doctor ` first when the target needs Appium, a desktop driver or cloud credentials. The Chrome, Android and Electron players drive the same [WebdriverIO demo app](https://github.com/webdriverio/native-demo-app) (the Expo guinea pig, tag `v2.2.0`). Chrome and Electron use a local Expo web server in a normal desktop window. Android installs the [v2.2.0 release apk](https://github.com/webdriverio/native-demo-app/releases/download/v2.2.0/android.wdio.native.app.v2.2.0.apk) (`com.wdiodemoapp`). iOS installs the v2.2.0 simulator app (`org.wdiodemoapp`) and uses `touchId`. Each player types the command, then the window shows the result. Pause, or step to the previous or next command, to read the line that changed the window. The shared path is: open the app, log in as `alice@webdriver.io` / `supersecret`, reach the robot logo ("You found me!!!"), then finish the 9-piece puzzle. Chrome and Electron also set a location and a night clock on the Weather view, open the in-app WebView of the WebdriverIO frontpage, and drag the carousel. The Android player scrolls the native swipe screen to that robot. `export` writes a Mocha spec of whichever session you just drove. []() ## Browsers[​](#browsers "Direct link to Browsers") ``` npx wdio session open chrome http://localhost:3000 npx wdio session open firefox http://localhost:3000 npx wdio session open edge http://localhost:3000 npx wdio session open safari http://localhost:3000 ``` Chrome opens headless. Add `--headed` to show the window. Chrome, Firefox and Edge are downloaded on first use when they are not installed. Safari requires macOS. ### User agent in headless mode[​](#user-agent-in-headless-mode "Direct link to User agent in headless mode") Headless Chrome and Edge identify themselves as `HeadlessChrome/` in the user agent. A visible window of the same browser sends `Chrome/`. Many sites refuse requests with the headless token: Akamai answers "Access Denied" and Cloudflare shows "Just a moment...". They decide from the request, before any page script runs. An agent would then see a block page that a person opening the same site never gets. A headless Chrome or Edge session therefore sends the user agent that a visible window of the same browser would send. This only changes the token. It doesn't hide automation: * `navigator.webdriver` stays `true`. * chromedriver's own markers are still on the page. * Sites that check for automation still see it. While the user agent is overridden, Chrome sends no user agent client hints, so `navigator.userAgentData.brands` is empty. The override needs WebDriver BiDi, so a session opened with `--no-bidi` keeps the headless user agent. To send a specific user agent, pass it as a browser argument. The session then leaves the user agent alone: ``` npx wdio session open chrome https://example.com --arg=--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/154.0.0.0 Safari/537.36" ``` If a site still shows a bot check, try a visible window with `--headed`. If that is blocked too, the site doesn't let automated browsers in. Report that instead of trying to get past the check. A headed Chrome window keeps its tab strip and address bar, which is how you tell it from an Electron window. `--viewport 1280x800` is a normal browser page. On web the app uses a left sidebar. The WebdriverIO logo is at the top of that sidebar. The items are Home, Weather, Web, Login, Forms, Swipe, Drag, Perms and Data. The home screen lists browser and desktop next to iOS and Android. Weather reads `navigator.geolocation` and `Date`. `geolocation 35.6762 139.6503` is Tokyo. It applies on the next load, so run `reload` before `click "aria/Weather"`. The widget then shows Tokyo, 21° and rain. `emulate clock 2026-06-21T23:30:00Z` switches the same card from a day sky to a night sky and sets the clock to 11:30 PM. A second `emulate clock` replaces the first. The WebView tab loads `https://webdriver.io/` inside the app. Login waits about 1.5 seconds, then opens a dialog whose text is `Success` and `You are logged in!`. The LOGIN button stays a 200×50 orange control while that wait is on screen. `dialog accept` closes the dialog. `swipe` is mobile-only. Drag `[data-testid=Carousel]` onto `aria/Next card` twice to page the carousel. The recorded web build listens for `pointerup` on `document`, so the drag can start on the carousel and the pointer can be released on `Next card`, which sits outside the carousel. `scroll down --px 560` brings the WebdriverIO robot into view. The caption under it is "You found me!!!". The puzzle pieces are `aria/drag-l2` through `aria/drag-l3`, dropped on the matching `aria/drop-…` target. The tray order is `l2`, `r3`, `r1`, `c1`, `c3`, `r2`, `c2`, `l1`, `l3`. ``` npx wdio session open chrome http://127.0.0.1:8081 --headed --viewport 1280x800 npx wdio session geolocation 35.6762 139.6503 npx wdio session reload npx wdio session click "aria/Weather" npx wdio session emulate clock 2026-06-21T23:30:00Z npx wdio session click "aria/Webview" npx wdio session click "aria/Login" npx wdio session fill "aria/input-email" "alice@webdriver.io" npx wdio session fill "aria/input-password" "supersecret" npx wdio session click "aria/button-LOGIN" npx wdio session dialog accept npx wdio session click "aria/Swipe" npx wdio session drag "[data-testid=Carousel]" "aria/Next card" npx wdio session drag "[data-testid=Carousel]" "aria/Next card" npx wdio session scroll down --px 560 npx wdio session click "aria/Drag" npx wdio session drag "aria/drag-l2" "aria/drop-l2" ``` Repeat `drag` for `r3`, `r1`, `c1`, `c3`, `r2`, `c2`, `l1` and `l3`. *terminal* $ npx wdio session open chrome http\://127.0.0.1:8081 --headed --viewport 1280x800 Session "default" ready: chrome (headed) · http\://127.0.0.1:8081/ [](/img/session/browser.mp4) `--viewport 1280x720` sets the initial size. `--arg` adds a browser argument and can be repeated. `--profile ` keeps a profile between opens. []()[]()[]() ## Android and iOS[​](#android-and-ios "Direct link to Android and iOS") Android and iOS run through Appium 3. `doctor android` reports a missing server or driver with the install command. ``` npx wdio session doctor android npx wdio session open android --app ./shop.apk npx wdio session snapshot --interactive npx wdio session tap e3 ``` iOS: `open ios --bundle-id com.example.shop`. An installed Android package uses `--package` and `--activity`. Mobile web uses `--browser chrome` or `--browser safari` instead of an app. `--appium-url http://127.0.0.1:4723/` attaches to a server that is already running. A cloud app URL such as `bs://…` is passed through as `--app` and is not treated as a local file. []() ### Native demo app[​](#native-demo-app "Direct link to Native demo app") On an emulator or a device the same guinea pig is the v2.2.0 apk: ``` curl -fsSL -o android.wdio.native.app.v2.2.0.apk \ https://github.com/webdriverio/native-demo-app/releases/download/v2.2.0/android.wdio.native.app.v2.2.0.apk adb install -r android.wdio.native.app.v2.2.0.apk ``` `open` waits up to eight minutes. UiAutomator2 installs a server and starts instrumentation before the app is usable, and that is slower than launching a browser. The first request is not retried: a retry starts a second Appium session on the same device while the first is still installing. `tap "~Login"`, `fill`, then `tap "~button-LOGIN"` logs in with the same email and password. On a short screen the LOGIN button sits below the fold, so scroll the `~Login-screen` before that tap. `dialog accept` closes the success alert, and it has to run after that alert is on screen. The alert text is `Success` / `You are logged in!`. The fingerprint button is `~button-biometric`. It is on the login form only after a fingerprint is enrolled, so this player does not tap it. `exec -e "await browser.fingerPrint(1)"` answers the system prompt (`fingerPrint` is Android-only; there is no `wdio session` subcommand for it). `tap "~Webview"` is the in-app WebView of `https://webdriver.io/`. On a one-CPU software emulator the WebView renderer dies with `SIGTRAP` in `libmonochrome` after the LOADING label, and the page never paints. The player leaves that tab alone. `tap "~Swipe"` opens the carousel. `swipe left` does not page it: the carousel is `react-native-reanimated-carousel`, and a UIAutomator swipe springs back to the first card. An `exec` of `mobile: swipeGesture` on the scroll view, repeated, is what brings up the robot and the caption "You found me!!!". A full-screen `swipe up` from the bottom edge opens Android's screenshot UI instead. `drag "~drag-l2" "~drop-l2"` (and the other eight pairs, in tray order) finishes the puzzle. The last frame is the assembled robot and the retry control. `-s android` keeps this session beside the browser one. Drop `-s android` when it is the only session. `open` uses the package and activity already installed by the apk, with `--no-reset` so an enrolled fingerprint stays. `"~Login"` is the tab's accessibility label. `wait` does not apply to a native session. ``` npx wdio session -s android open android --package com.wdiodemoapp --activity com.wdiodemoapp.MainActivity --no-reset npx wdio session -s android tap "~Login" npx wdio session -s android fill "~input-email" "alice@webdriver.io" npx wdio session -s android fill "~input-password" "supersecret" npx wdio session -s android exec -e 'await browser.execute("mobile: scrollGesture", { elementId: (await $("~Login-screen")).elementId, direction: "down", percent: 0.75 }); return "scrolled the login form"' npx wdio session -s android tap "~button-LOGIN" npx wdio session -s android dialog accept npx wdio session -s android tap "~Swipe" npx wdio session -s android exec -e 'for (let i = 0; i < 6; i++) { await browser.execute("mobile: swipeGesture", { left: 80, top: 180, width: 560, height: 320, direction: "up", percent: 0.95 }) } for (let i = 0; i < 4; i++) { await browser.execute("mobile: swipeGesture", { left: 40, top: 700, width: 640, height: 280, direction: "up", percent: 0.9 }) } return "revealed the robot"' npx wdio session -s android tap "~Drag" npx wdio session -s android drag "~drag-l2" "~drop-l2" ``` Repeat `drag` for `r3`, `r1`, `c1`, `c3`, `r2`, `c2`, `l1` and `l3`. *terminal* $ npx wdio session -s android open android --package com.wdiodemoapp --activity com.wdiodemoapp.MainActivity --no-reset Session "android" ready: android (UiAutomator2) [](/img/session/android.mp4) ### iOS simulator[​](#ios-simulator "Direct link to iOS simulator") The same screens are in the v2.2.0 simulator build, [ios.simulator.wdio.native.app.v2.2.0.zip](https://github.com/webdriverio/native-demo-app/releases/download/v2.2.0/ios.simulator.wdio.native.app.v2.2.0.zip). Unzip it and install `wdiodemoapp.app` on a booted simulator (`xcrun simctl install booted`). The bundle id is `org.wdiodemoapp`. That binary is an iPhone Simulator app (arm64, iOS 15.1 or newer). It needs macOS and Xcode. There is no iOS player on this page. Login, swipe and drag use the same accessibility labels as Android. `swipe left` was not run on the simulator. On the Android apk it does not page this carousel. The biometric call is `browser.touchId(true)`, not `fingerPrint`. `touchId` needs the capability `appium:allowTouchIdEnroll` set to `true` (pass it with `--capabilities`). Enroll Touch ID on the simulator before opening the login form, or the biometric button stays hidden. ``` npx wdio session -s ios open ios --bundle-id org.wdiodemoapp --capabilities '{"appium:allowTouchIdEnroll":true}' npx wdio session -s ios tap "~Webview" npx wdio session -s ios tap "~Login" npx wdio session -s ios fill "~input-email" "alice@webdriver.io" npx wdio session -s ios fill "~input-password" "supersecret" npx wdio session -s ios tap "~button-LOGIN" npx wdio session -s ios dialog accept npx wdio session -s ios tap "~button-biometric" npx wdio session -s ios exec -e "await browser.touchId(true)" npx wdio session -s ios dialog accept npx wdio session -s ios tap "~Swipe" npx wdio session -s ios swipe left npx wdio session -s ios swipe left npx wdio session -s ios swipe up npx wdio session -s ios tap "~Drag" npx wdio session -s ios drag "~drag-l2" "~drop-l2" ``` Repeat `drag` for the other eight pieces, in the same tray order as Android. ## Desktop apps[​](#desktop-apps "Direct link to Desktop apps") ``` npx wdio session open macos --bundle-id com.example.shop npx wdio session open windows --app Root ``` `macos` requires macOS. `windows` requires Windows. `--app Root` attaches to the desktop. An installed Windows app is named by its application id, for example `--app Microsoft.WindowsCalculator`. A path or a `.exe` is resolved as a file. []() ## Electron, Tauri and Dioxus[​](#electron-tauri-and-dioxus "Direct link to Electron, Tauri and Dioxus") ``` npx wdio session open electron ./main.js npx wdio session snapshot --interactive npx wdio session click e2 ``` `open tauri ./my-app` and `open dioxus ./my-app` need their driver on `PATH` unless the service package starts the session itself. On Linux without `DISPLAY` or `WAYLAND_DISPLAY`, install Xvfb or weston. Electron stays on the classic WebDriver protocol. Pass `--app-arg` to forward a flag to the app, including `--app-arg=--no-sandbox` when the environment requires it. A value that starts with `-` has to use `=`, because the strict parser otherwise treats it as its own option. Install `electron` and `@wdio/electron-service` in the directory you open. `main.js` uses `import`, so that directory's `package.json` needs `"type": "module"` (or name the file `main.mjs`). Size the window to the work area so a smaller display does not place the title bar off screen: ``` { "type": "module" } ``` ``` import { app, BrowserWindow, screen } from 'electron' app.whenReady().then(() => { const area = screen.getPrimaryDisplay().workArea const width = Math.min(1280, area.width) const height = Math.min(800, area.height) const win = new BrowserWindow({ width, height, x: area.x + Math.max(0, Math.round((area.width - width) / 2)), y: area.y + Math.max(0, Math.round((area.height - height) / 2)), autoHideMenuBar: true, webPreferences: { contextIsolation: true, sandbox: true } }) win.loadURL('http://127.0.0.1:8081/') }) ``` The open command below does not disable the renderer sandbox. Add `--app-arg=--no-sandbox` only when the environment cannot start Electron with the sandbox, such as some Linux containers. The Electron player loads the same Expo URL in a 1280×800 window with no address bar. The logo, sidebar, weather card, login card, carousel and puzzle match the browser. `-s electron` is the session name used beside the browser demo. Electron stays on the classic protocol, so `geolocation` and `emulate clock` go through Chromedriver instead of BiDi. The commands match Chrome, including `reload` before Weather, except the success dialog. On Linux, `dialog accept` accepts the native alert and the bubble stays painted. That bubble is not part of the page, so a later click cannot reach it. The recording replaces `window.alert` with an in-page dialog and runs `click "aria/OK"`. The LOGIN button stays a 200×50 orange control while it waits. The carousel, the scroll and the puzzle use the same commands as Chrome. ``` npx wdio session -s electron open electron ./main.js npx wdio session -s electron geolocation 35.6762 139.6503 npx wdio session -s electron reload npx wdio session -s electron click "aria/Weather" npx wdio session -s electron emulate clock 2026-06-21T23:30:00Z npx wdio session -s electron click "aria/Webview" npx wdio session -s electron click "aria/Login" npx wdio session -s electron fill "aria/input-email" "alice@webdriver.io" npx wdio session -s electron fill "aria/input-password" "supersecret" npx wdio session -s electron click "aria/button-LOGIN" npx wdio session -s electron click "aria/OK" npx wdio session -s electron click "aria/Swipe" npx wdio session -s electron drag "[data-testid=Carousel]" "aria/Next card" npx wdio session -s electron drag "[data-testid=Carousel]" "aria/Next card" npx wdio session -s electron scroll down --px 560 npx wdio session -s electron click "aria/Drag" npx wdio session -s electron drag "aria/drag-l2" "aria/drop-l2" ``` Repeat `drag` for `r3`, `r1`, `c1`, `c3`, `r2`, `c2`, `l1` and `l3`. *terminal* $ npx wdio session -s electron open electron ./main.js --app-arg=--no-sandbox Electron sessions use the classic WebDriver protocol. Session "electron" ready: electron · http\://127.0.0.1:8081/ [](/img/session/electron.mp4) ## Cloud devices[​](#cloud-devices "Direct link to Cloud devices") ``` npx wdio session open chrome https://webdriver.io --provider browserstack ``` `--provider` is `browserstack`, `saucelabs`, `testingbot` or `testmu`. Export the provider's username and access key. `doctor ` checks that they are set and does not print the values. `--tunnel` starts the provider's tunnel when the app under test is on your machine. ## A WebdriverIO config[​](#a-webdriverio-config "Direct link to A WebdriverIO config") `open` can take a config file and a capability index instead of a target name: ``` npx wdio session open ./wdio.conf.ts 0 ``` A TypeScript config loads with `tsx` when your project has it. `tsx` is optional: without it the config loads through Node type stripping or jiti, and a config that fails to load reports `MISSING_DEPENDENCY` with an install line. `--hostname`, `--port`, `--path` and `--protocol` point the session at a WebDriver endpoint that is already running. Closing the session does not stop that endpoint. ## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting") | Message | What to do | | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `MISSING_DEPENDENCY` | Install the package named in the error. `doctor ` prints the same install line. Electron needs `@wdio/electron-service` and `electron` in the directory you open. | | `MISSING_APPIUM_DRIVER` | Run the `npx appium driver install …` line from the error. | | `MISSING_BINARY` | Put the named driver (`tauri-driver` or `wdio-dioxus-driver`) on `PATH`. | | `MISSING_CREDENTIALS` | Export the variables named in the error. | | `NOT_SUPPORTED` | `macos` is macOS-only and `windows` is Windows-only. `swipe` is mobile-only. On Chrome and Electron, drag `[data-testid=Carousel]` onto `aria/Next card`. | | `No dialog open.` | The alert is not open. On Android, wait until the success alert is visible before `dialog accept`. On Linux Electron the native bubble can stay painted after `acceptAlert` and still report no dialog. The player uses an in-page dialog and `click "aria/OK"` instead. | | `The instrumentation process cannot be initialized` | UiAutomator2 did not start listening in time. The session allows 240s for that launch, after up to 180s to install the server. On a software emulator, one CPU and a 720×1280 skin gets the v2.2.0 apk to the home screen. A 1080×2400 image with two CPUs ANRs `system_server` and the server never listens. | | `Request timed out! Consider increasing the "connectionRetryTimeout" option.` | The client gave up while Appium was still creating the session. Android and iOS wait 480s for that first request and do not send it again. | | `"wait" is not supported for android (UiAutomator2) sessions.` | `wait` is for browser sessions. | | `The fingerPrint command is only available for Android.` | `browser.fingerPrint` is the Android call. iOS uses `browser.touchId`. | | `App not found:` | Pass an apk path that exists, or use `--package` and `--activity` for an app that is already installed. | | `Pass --package .` | `deeplink` needs `--package` on Android. | ## Next steps[​](#next-steps "Direct link to Next steps") * [Snapshots and refs](/docs/session/snapshots.md) — read the screen after `open` * [Commands](/docs/session-commands.md) — every `open` flag * [wdio session](/docs/session.md) — the default loop --- Source: https://webdriver.io/docs/session/snapshots.md # Snapshots and refs Take a snapshot before you click. The snapshot is the list of elements you can act on. Each interactive line ends with a ref such as `[ref=e3]`. ``` npx wdio session open chrome http://localhost:3000 npx wdio session snapshot --interactive ``` A line looks like `button "Add to cart" [ref=e3]`. The next command uses that ref: ``` npx wdio session click e3 ``` Refs come from the latest snapshot. After navigation, snapshot again. An old ref fails with `REF_STALE`. An unknown ref fails with `REF_NOT_FOUND`. Experimental The text layout of a snapshot, and the shape `--json` prints for it, are experimental: a minor release may change them, for example to share one snapshot engine with the [DevTools trace](/docs/devtools/wdio/trace-mode.md). The ref syntax (`e3`, `@e3`), the actions that take a ref and the code they record stay stable. Take refs from a snapshot and don't parse the rest of its lines. ## What to run[​](#what-to-run "Direct link to What to run") | Command | Use it for | | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `snapshot --interactive` | The elements you can act on, each with a ref | | `find "Add to cart"` | Each match with the node around it, e.g. a whole list item, so a value next to the match comes along. `-A`, `-B` and `-C` print plain line context like grep | | `diff` | What changed since the previous snapshot | | `screenshot` | Layout. Skip it when a snapshot answers the question | | `source` | The page HTML or the native XML | `snapshot` without `--interactive` includes more of the tree. Prefer `--interactive` when you are about to click or type. ## What an action changed[​](#what-an-action-changed "Direct link to What an action changed") In a web session, `open` prints the interactive snapshot of the page it opened, and every action that can change the page (`click`, `fill`, `type`, `press`, `select`, `check`, `navigate`, `frame`, …) reports what changed: ``` Clicked e6 (button "Start subscription") Changes: + - status "Subscription started. Confirmation code: 4F2A9C" ``` When the action opened a tab, the report says so (`Opened a new tab [1]: https://…`); the session stays on the current tab until you run `tabs switch`. When the page is a bot check (Cloudflare, DataDome, Akamai, …) rather than the site, the report says that too, once per page. The session doesn't try to get past it; in a headless browser it suggests reopening with `--headed`. On the same page you get the new or changed lines with their refs, including text that is not interactive, like the status above. After a navigation you get the new page's interactive elements, or for a large page a one-line summary that points to `find`. So you rarely need a separate `snapshot` after an action. Set `WDIO_SESSION_CHANGES=0` to turn the report off, and pass `open --no-snapshot` to skip the snapshot after `open`. ## Frames[​](#frames "Direct link to Frames") In a WebDriver BiDi session the snapshot shows the content of the page's iframes, cross-origin ones included, under the iframe they are in: ``` - iframe "Payment" [ref=e4] - textbox "Card number" [ref=e5] - button "Pay" [ref=e6] ``` Actions on these refs enter the frame, act, and come back to the page, and the printed code does the same. Up to five iframes are shown, each cut at 300 elements; `frame e4` and `snapshot` show all of a frame that was cut short. Iframes smaller than 100 square pixels, like tracking pixels, are left out. ## Shadow DOM and clickable elements without a role[​](#shadow-dom-and-clickable-elements-without-a-role "Direct link to Shadow DOM and clickable elements without a role") With WebDriver BiDi, the snapshot also covers closed shadow roots, and elements that only have a click listener (an icon wired up with `addEventListener`) get a ref. Such an element has no accessible name, so the snapshot describes it instead: ``` - generic [ref=e8] (icon 3 of 3 in "Invoice #1002 · Contoso Ltd · $860.00") ``` On Android, iOS, macOS and Windows the snapshot comes from the Appium page source. Two controls that share an accessibility id stay separate refs when the rest of their selectors differ. `snapshot --scope e3` limits the tree to that ref. ## Repeated controls[​](#repeated-controls "Direct link to Repeated controls") When several controls share a role and a name, such as the "Add to cart" button of every row in a product table, the ref line ends with `∈ ""`, the text of the row, card or list item that holds that control and no other of the same name: ``` - button "Add to cart" [ref=e9] ∈ "Desk lamp · Brass · In stock · $49.00" ``` The text is cut at 80 characters. A control whose item is a page landmark (a "Sign in" link in both the header and the footer) gets none. The label of a visible form control is not listed: the control carries the name. ## Native taps[​](#native-taps "Direct link to Native taps") Web sessions use `click`. Mobile and native desktop sessions use `tap` on the same ref: ``` npx wdio session open android --app ./shop.apk npx wdio session snapshot --interactive npx wdio session tap e3 ``` ## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting") | Message | What to do | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `REF_STALE` | The element from the last snapshot is gone. Run `snapshot` and use a new ref. | | `REF_NOT_FOUND` | That id was never in this session. The ref in your command does not match the latest snapshot. | | `NO_MATCH` | `find` did not see that text. Snapshot and read the names that are actually there. | | `NOT_EDITABLE` | The `fill` target is not an editable field and has no single editable field inside it (or behind `aria-controls`/`aria-owns`/label). Run `snapshot --scope ` and fill the field ref. | ## Next steps[​](#next-steps "Direct link to Next steps") * [Run code](/docs/session/exec.md) — assertions and steps that are more than one command * [Commands](/docs/session-commands.md) — `snapshot`, `find`, `diff`, `screenshot` and `source` flags --- Source: https://webdriver.io/docs/session/exec.md # Run code in a session `exec` runs WebdriverIO code in the open session. Use it when a step is more than a single `click` or `fill`, and for every assertion. ``` npx wdio session exec -e "await browser.getTitle()" npx wdio session <<'JS' await $('aria/Cart (1)').waitForDisplayed() JS ``` Always `await` commands. `$` returns one element and throws when it is missing. `$$` returns a list. There is no sync mode and no `browser.element`. Names you declare stay available in the next `exec`. A top-level `import` is loaded from the project directory. ## Assertions[​](#assertions "Direct link to Assertions") Put assertions in `exec` with `expect-webdriverio`. Install it in your project. Without it, `expect(...)` fails with an install hint. ``` npx wdio session exec -e "await expect($('h1')).toHaveText('Cart')" ``` Use `visual check ` when the question is how the screen looks. That command needs `@wdio/visual-service`: ``` npx wdio session visual check cart ``` `visual accept cart` copies the latest actual image for that tag over the baseline. It does not copy older images that share the tag prefix. ## When to use a shortcut instead[​](#when-to-use-a-shortcut-instead "Direct link to When to use a shortcut instead") `click`, `fill`, `type`, `press` and `tap` are shorter than `exec` for one interaction, and they print the WebdriverIO line they ran. Prefer those with a ref from the latest [snapshot](/docs/session/snapshots.md). Use `exec` for waits, assertions and anything that needs more than one command. ## Next steps[​](#next-steps "Direct link to Next steps") * [Export a test](/docs/session/export.md) — save the steps, including `exec` * [Commands](/docs/session-commands.md) — `exec` and `visual` flags --- Source: https://webdriver.io/docs/session/export.md # Export a session as a test `export` writes a spec from the recorded steps. Refs are replaced with stable selectors. For a web page, the first of these that matches exactly one element is used: a test id (`data-testid`, `data-test`, `data-qa`), a [role selector](/docs/selectors.md#role-selector) such as `role/button[name="Add to cart"]`, an accessible name (`aria/Add to cart`), an id, the text of a button or link, a form field name, and finally a CSS path. A role selector or accessible name is skipped when the name the snapshot computed may not be the one the driver computes, for example a name next to an icon, with a non-breaking space or spread over block elements. This happens in WebDriver BiDi and in classic sessions, and the text or CSS path is used instead. When the element has no selector at all, such as one of several nameless buttons inside shadow roots, the action still runs on the ref. The step is recorded as `ref('e12')` with a comment: it replays in the session, but `export` stops with `Step N still contains ref()` until the step is removed or rewritten with a selector. ``` npx wdio session export --out test/specs/cart.e2e.ts npx wdio run wdio.conf.ts --spec test/specs/cart.e2e.ts ``` `history` prints the steps before you export. `history clear` drops them. ## Page objects[​](#page-objects "Direct link to Page objects") `--page-objects` writes a page object next to the spec. Selectors are grouped by the path they ran on. A literal `$('…')` in a recorded step becomes a getter. `$$`, strings that happen to contain `$('…')`, and a dynamic `$(selector)` stay as they are. ``` npx wdio session export --page-objects --out test/specs/cart.e2e.ts ``` The command refuses to overwrite a page object that is already in the output directory. Move `--out` or remove that file first. The spec file itself is written again. A `import` at the top of an `exec` step is hoisted to the top of the spec, outside the test function. ## Helpers[​](#helpers "Direct link to Helpers") Add a file under `.wdio/helpers/` when a step is too long for `exec`. Each file default-exports a function that receives the browser and registers commands with `addCommand`. Relative imports stay relative to that file. Bare package imports resolve from the project. .wdio/helpers/login.js ``` import { mark } from './util.js' export default function login (browser) { browser.addCommand('fillLogin', async (email) => { await browser.$('#email').setValue(email + mark) }) } ``` Helpers are loaded when the session opens and again with `npx wdio session helpers --reload`. If `.wdio/helpers` does not exist yet, the session watches for it. Helpers become custom commands in the exported test. ## Next steps[​](#next-steps "Direct link to Next steps") * [Run code](/docs/session/exec.md) — the steps `export` records * [Commands](/docs/session-commands.md) — `export`, `history` and `helpers` flags --- Source: https://webdriver.io/docs/session/debug.md # Debug a test with a session `wdio run --debug=agent` pauses the worker on `await browser.debug()` and after a failed test, and raises the framework timeout to 24 hours. The pause covers both Mocha tests and Cucumber steps. The run prints the session name (`debug-0-0` for the first worker): ``` npx wdio run wdio.conf.ts --debug=agent npx wdio session -s debug-0-0 snapshot npx wdio session -s debug-0-0 exec -e "await browser.getTitle()" npx wdio session -s debug-0-0 resume ``` `close` on that session fails the paused test with `Session closed from wdio session`. Resume when the test should continue. Close when you want the run to fail at the pause. `browser.debug()` without `--debug=agent` still opens the [REPL](/docs/repl.md) inside the test. `--debug=agent` is the path that lets another process, including a coding agent, drive the paused worker with `wdio session`. ## Attach a REPL[​](#attach-a-repl "Direct link to Attach a REPL") `wdio repl --session ` attaches to a session that is already open and leaves it running when you exit: ``` npx wdio session open chrome https://webdriver.io npx wdio repl --session default ``` Each REPL line runs as `wdio session exec`. `.exit` prints `Detached from "default" (still running)`. ## Doctor[​](#doctor "Direct link to Doctor") `npx wdio session doctor` checks Node.js, the browser, Appium, SDKs and cloud credentials before you open a session. `doctor ` checks only what that target needs. The process exits 1 when a check fails. A session that is still starting is left in place. A session whose process is gone is removed. ## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting") | Message | What to do | | ---------------------------------- | -------------------------------------------------------------------------------------------------------------- | | `Session closed from wdio session` | You closed the debug session. Use `resume` when the test should continue. | | No `debug-0-0` session | The run has not paused yet, or it used a different worker id. `wdio session list` prints the names. | | The pause never happens | The command must be `wdio run --debug=agent`. A passing test does not pause unless it calls `browser.debug()`. | ## Next steps[​](#next-steps "Direct link to Next steps") * [Debugging](/docs/debugging.md) — `browser.debug()`, breakpoints and flaky tests * [REPL](/docs/repl.md) — the interactive shell * [wdio session](/docs/session.md) — open a session that is not attached to a test run