Skip to main content

wdio session commands

Every wdio session action. Global flags apply to all of them. The rest of the WebdriverIO Session section covers targets, snapshots, exec, export and debugging.

npx wdio session <action> [arguments] [flags]

Global flags​

FlagDescription
--session, -sSession name (env WDIO_SESSION, default default)
--jsonPrint one JSON object (env WDIO_SESSION_JSON=1)
--timeoutRequest timeout in ms
--quiet, -qPrint nothing on success except requested data
--color, --no-colorColorize human output

Exit codes: 0 success, 1 the action failed, 2 usage, 3 a missing dependency or credentials, 4 no session with that name.

open​

Start a session: browser, android, ios, macos, windows, electron, tauri, dioxus or a wdio config file.

Arguments

NameRequiredDescription
targetyeschrome | firefox | edge | safari | android | ios | macos | windows | electron <app> | tauri <app> | dioxus <app> | <wdio.conf>
urlnoURL to open (browsers), app path (desktop apps) or capability (config)

Flags

FlagDescription
--replaceClose a running session with the same name first
--launch-timeoutMilliseconds to wait for the session to become ready
--idle-timeoutShut down after this long without requests (e.g. 30m, 0 disables)
--capabilitiesExtra capabilities as JSON or a path to a JSON file
--hostnameRemote WebDriver host
--portRemote WebDriver port
--pathRemote WebDriver path
--protocolRemote WebDriver protocol
--log-levelWebdriverIO log level written to daemon.log
--bidiRequest WebDriver BiDi (use --no-bidi to disable) Default: true.
--headedShow the browser window
--viewportInitial viewport, e.g. 1280x720
--browser-versionBrowser version
--binaryBrowser binary
--argExtra browser argument (repeatable). A value that starts with - needs =, for example --arg=--headless
--profilePersistent profile directory
--attachAttach to a running Chrome/Edge (debugging port or URL)
--appApp file or cloud app URL
--packageAndroid app package
--activityAndroid app activity
--bundle-idiOS/macOS bundle id
--browserMobile web browser (chrome, safari)
--deviceDevice name
--platform-versionPlatform version
--udidDevice UDID
--resetUse --no-reset to keep app state (appium:noReset)
--full-resetappium:fullReset
--orientationInitial orientation Choices: portrait, landscape.
--appium-urlUse a running Appium server
--app-argArgument passed to a desktop app (repeatable). A value that starts with - needs =, for example --app-arg=--no-sandbox
--chromedriverElectron: Chromedriver binary
--electron-versionElectron: override version detection
--providerCloud provider Choices: browserstack, saucelabs, testingbot, testmu.
--osCloud: desktop OS
--os-versionCloud: desktop OS version
--regionCloud: Sauce Labs region
--tunnelCloud: start the provider tunnel (or "external")
--tunnel-nameCloud: tunnel identifier
--projectCloud: project label
--buildCloud: build label
--nameCloud: session name label
$0 session open chrome http://localhost:3000

Open headless Chrome

$0 session open android --app ./app.apk

Open an Android app through Appium

$0 session open electron ./main.js

Open an Electron app

$0 session open ./wdio.conf.ts 0

Open the first capability of a config

close​

End the session and stop its daemon.

Flags

FlagDescription
--allClose every session
--cleanAlso delete the artifacts dir

list​

List running sessions.

info​

Show session details.

restart​

Close and re-open with the same target and flags.

status​

Exit 0 if the session is running, 4 if not.

exec​

Run WebdriverIO code from stdin, -e or a file.

Arguments

NameRequiredDescription
filenoScript file (.js, .ts, .mjs)

Flags

FlagDescription
--e, -evalCode to run
--historyRecord the code in the history (use --no-history to skip) Default: true.
$0 session exec -e "await browser.getTitle()"

Run a one-liner

$0 session <<'JS'
await $('aria/Sign in').click()
JS

Pipe code on stdin

helpers​

List project helpers from .wdio/helpers.

Flags

FlagDescription
--reloadRe-import the helpers

snapshot​

Accessibility snapshot with refs. Applies to web, native mobile, native desktop.

Flags

FlagDescription
--depthMaximum depth
--scopeOnly snapshot below this target
--interactive, -iOnly interactive elements
--allInclude hidden elements
--boxesAppend bounding boxes
--compactDrop unnamed nodes that have no content
--urls, -uInclude link hrefs
--file-onlyOnly write the file
--max-charsPrint inline up to this many characters (default 8000)

find​

Search a fresh snapshot for text. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
textyesText to search for

Flags

FlagDescription
--regexTreat text as a regular expression
--contextLines of context (default 2)

diff​

Diff a fresh snapshot against the previous one. Applies to web, native mobile, native desktop.

Flags

FlagDescription
--baselineSnapshot file to compare with

screenshot​

Save a PNG of the viewport, an element or the full page. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
targetnoElement to capture

Flags

FlagDescription
--fullFull page (web)
--pathOutput file

pdf​

Save the current page as a PDF. Applies to web.

This calls browser.savePDF. A BiDi session renders the file with browsingContext.print. That is the print path for Chrome, Edge, and Firefox, headed and headless. A Classic session uses printPage. Chrome's Classic print endpoint was headless-only (crbug 753118); current Chrome can also print from a headed Classic session, and older Chrome may still require headless.

Arguments

NameRequiredDescription
filenoOutput file (must end in .pdf)

Flags

FlagDescription
--pathOutput file (must end in .pdf)

source​

Save the page HTML or app XML. Applies to web, native mobile, native desktop.

Flags

FlagDescription
--pathOutput file

get​

Read text, html, value, an attribute, the title, the URL, a count or a box. Applies to web.

Arguments

NameRequiredDescription
subyestext | html | value | attr | title | url | count | box Choices: text, html, value, attr, title, url, count, box.
targetnoRef or selector (not used for title and url)
namenoAttribute name (attr only)

Examples

$0 session get text e1

Text of a ref

$0 session get url

Current URL

$0 session get attr e3 href

href of a link

is​

Check whether an element is visible, enabled or checked. Applies to web.

Arguments

NameRequiredDescription
subyesvisible | enabled | checked Choices: visible, enabled, checked.
targetyesRef or selector

Examples

$0 session is visible e1

Print true or false

logs​

Print console, page error, network and device logs since the last call. Applies to web, native mobile.

Flags

FlagDescription
--errorsOnly errors
--networkOnly network entries
--sinceOnly entries newer than this duration (e.g. 30s)
--peekDo not advance the read cursor
--sourceLog source Choices: browser, driver, logcat, syslog, main.

Open a URL. Applies to web.

Arguments

NameRequiredDescription
urlyesURL (relative URLs use baseUrl)

back​

Go back. Applies to web.

forward​

Go forward. Applies to web.

reload​

Reload the page. Applies to web.

wait​

Wait for an element, text, a URL, a load state, a condition or a few milliseconds. Applies to web.

Arguments

NameRequiredDescription
targetnoRef, selector or milliseconds

Flags

FlagDescription
--textWait until the page contains this text
--urlWait until the URL matches (substring, or * and ** globs)
--loaddomcontentloaded, load or networkidle
--fnWait until this JavaScript expression is true
--statevisible (default), hidden, enabled or disabled
--limitMilliseconds to wait (default 10000)

Examples

$0 session wait e1

Wait until a ref is visible

$0 session wait --text Welcome

Wait for text

$0 session wait --url "**/dashboard"

Wait for a URL

$0 session wait 500

Pause 500ms

click​

Click an element. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

Flags

FlagDescription
--doubleDouble click
--rightRight click
--new-tabOpen the link in a new tab

tap​

Tap an element (mobile). Applies to native mobile.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

fill​

Replace the value of an input. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector
textyesText

type​

Type into the focused element. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
textyesText

press​

Press keys, e.g. Enter, Control+a. Applies to web, native desktop.

Arguments

NameRequiredDescription
keysyesKey combination

select​

Select an option of a <select>. Applies to web.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector
valueyesOption text, value or index

Flags

FlagDescription
--byHow to match the option (default text) Choices: text, value, index.

upload​

Set a file input. Applies to web.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector
fileyesFile to upload

hover​

Move the pointer over an element. Applies to web, native desktop.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

focus​

Focus an element. Applies to web.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

check​

Check a checkbox or radio. Applies to web.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

uncheck​

Uncheck a checkbox. Applies to web.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

drag​

Drag an element onto another. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
fromyesSource
toyesDestination

scroll​

Scroll an element into view or the page. Applies to web.

Arguments

NameRequiredDescription
targetnoRef, selector, up, down, top or bottom

Flags

FlagDescription
--pxPixels for up/down (default 600)

swipe​

Swipe the screen (mobile). Applies to native mobile.

Arguments

NameRequiredDescription
directionyesDirection Choices: up, down, left, right.

Flags

FlagDescription
--percentSwipe length 0..1

long-press​

Long press an element (mobile). Applies to native mobile.

Arguments

NameRequiredDescription
targetyesRef (e12) or WebdriverIO selector

Flags

FlagDescription
--durationMilliseconds

tabs​

List, open, switch or close tabs. Applies to web.

Arguments

NameRequiredDescription
subnoswitch | new | close Choices: switch, new, close.
argnoIndex, handle or URL

windows​

List or switch windows. Applies to web, native desktop.

Arguments

NameRequiredDescription
subnoswitch Choices: switch.
argnoIndex or handle

frame​

Switch into an iframe, to the parent or to the top. Applies to web.

Arguments

NameRequiredDescription
targetyesRef, selector, parent or top

contexts​

List or switch native/webview contexts. Applies to native mobile.

Arguments

NameRequiredDescription
subnoswitch Choices: switch.
namenoContext name

dialog​

Accept, dismiss or report an open dialog. Applies to web, native mobile.

Arguments

NameRequiredDescription
subyesaccept | dismiss | status Choices: accept, dismiss, status.

Flags

FlagDescription
--textPrompt text

app​

Launch, terminate, install or query an app. Applies to native mobile, native desktop.

Arguments

NameRequiredDescription
subyeslaunch | terminate | install | state Choices: launch, terminate, install, state.
idyesApp id, bundle id or file

Open a deep link. Applies to native mobile.

Arguments

NameRequiredDescription
urlyesURL

Flags

FlagDescription
--packageAndroid package or iOS bundle id

rotate​

Rotate the device. Applies to native mobile.

Arguments

NameRequiredDescription
orientationyesportrait | landscape Choices: portrait, landscape.

keyboard​

Hide the on-screen keyboard. Applies to native mobile.

Arguments

NameRequiredDescription
subyeshide Choices: hide.

background​

Send the app to the background. Applies to native mobile.

Arguments

NameRequiredDescription
secondsyesSeconds (-1 keeps it there)

lock​

Lock the device. Applies to native mobile.

unlock​

Unlock the device. Applies to native mobile.

geolocation​

Set the geolocation. Applies to web, native mobile.

Arguments

NameRequiredDescription
latyesLatitude
lonyesLongitude

Flags

FlagDescription
--accuracyAccuracy in meters

emulate​

Emulate a device, viewport, network, cpu, clock or a BiDi emulation scope. Applies to web.

Arguments

NameRequiredDescription
subyesdevice | viewport | network | cpu | clock | color-scheme | user-agent | media | locale | timezone | touch | orientation | screen | viewport-meta | text-layout | scripting | scrollbar | forced-colors | reset Choices: device, viewport, network, cpu, clock, color-scheme, user-agent, media, locale, timezone, touch, orientation, screen, viewport-meta, text-layout, scripting, scrollbar, forced-colors, reset.
valuenoValue for the emulation

Flags

FlagDescription
--dprDevice pixel ratio (viewport)
--tickAdvance the emulated clock by ms

requests​

List captured network requests (BiDi). Applies to web.

Flags

FlagDescription
--filterSubstring or glob
--failedOnly failed requests
--sinceOnly requests newer than this duration
--limitMaximum lines (default 50)

mock​

Mock responses for a URL pattern (BiDi). Applies to web.

Arguments

NameRequiredDescription
patternyesURL pattern

Flags

FlagDescription
--statusStatus code
--bodyBody as JSON/text or a file path
--headerHeader k:v (repeatable)
--abortAbort matching requests
--methodOnly this method
--onceOnly the next request

unmock​

Remove mocks. Applies to web.

Arguments

NameRequiredDescription
patternnoPattern or mock id

Flags

FlagDescription
--allRemove all mocks

cookies​

Get, set or clear cookies. Applies to web.

Arguments

NameRequiredDescription
subnoget | set | clear Choices: get, set, clear.
namenoCookie name
valuenoCookie value

Flags

FlagDescription
--domain
--pathCookie path
--http-only
--secure
--same-site
--expiry

storage​

Get, set or clear localStorage (or sessionStorage). Applies to web.

Arguments

NameRequiredDescription
subnoget | set | clear Choices: get, set, clear.
keynoKey
valuenoValue

Flags

FlagDescription
--session-storageUse sessionStorage

state​

Save or load cookies and storage. Applies to web.

Arguments

NameRequiredDescription
subyessave | load Choices: save, load.
fileyesState file

visual​

Visual snapshots through @wdio/visual-service. Applies to web, native mobile, native desktop.

Arguments

NameRequiredDescription
subyessave | check | accept | list Choices: save, check, accept, list.
tagnoImage tag

Flags

FlagDescription
--elementOnly this element
--fullFull page
--tabbableTabbable page
--thresholdAllowed mismatch in percent (default 0)
--allaccept: every tag

trace​

Record every step with screenshots and snapshots.

Arguments

NameRequiredDescription
subyesstart | stop Choices: start, stop.

Flags

FlagDescription
--screenshotsDefault: true.
--snapshotsDefault: true.

record​

Record a video. Applies to web, native mobile.

Arguments

NameRequiredDescription
subyesstart | stop Choices: start, stop.

Flags

FlagDescription
--fpsFrames per second (default 5)
--pathOutput file

history​

Print the recorded steps.

Flags

FlagDescription
--clearClear the history

export​

Generate a spec from the history.

Flags

FlagDescription
--outOutput file
--titleSuite title
--page-objectsGenerate page objects
--frameworkFramework (default mocha) Choices: mocha, jasmine.

resume​

Continue a test paused by wdio run --debug=agent.

doctor​

Check your environment.

Arguments

NameRequiredDescription
targetnoOnly check what this target needs

skill​

Print the agent skill.

Flags

FlagDescription
--installWrite it to .agents/skills/wdio-session/SKILL.md (or this dir)

Welcome! How can I help?

WebdriverIO AI Copilot