Skip to main content
Bring an app’s window to the front, so your next clicks and keystrokes go to it.
Use it when your test works across several apps, or after a dialog or another window has taken focus.
The provision methods focus the app they launch, so you don’t need this right after provision.chrome(), provision.vscode(), provision.electron(), or provision.installer().

Signature

Parameters

string
required
The app’s name, as it appears in its window title. For example 'Google Chrome', 'Notepad', or 'Visual Studio Code'.
object

Returns

Promise<string>. Always resolves to "The application was focused.".

Errors

focusApplication() doesn’t throw when no window matches. It returns the same message either way. To confirm the right app is in front, follow it with an assert():

How it matches windows

  • Windows: TestDriver looks for windows whose title contains name. It restores a minimized window, then brings it to the front.
  • Linux: TestDriver runs jumpapp -f <name>. If that fails, it activates the first window whose title matches name, using xdotool.
The app must already be running. Launch it first with provision or exec().

Examples

Switch between two apps

Launch an app and focus it on Windows

Return to the browser after a dialog

Complete example

tests/notepad.test.mjs
  • Launch apps: open an app and focus it in one step
  • exec(): start an app with a shell command
  • pressKeys(): switch windows with keyboard shortcuts