Desktop¶
Desktop is the main entry point. Create one instance per test session.
Desktop
¶
Factory for :class:Application instances.
Usage::
desktop = Desktop()
app = desktop.launch("notepad.exe")
# or
app = desktop.connect(title_re=".*Notepad")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
|
'uia'
|
hidden
|
bool | None
|
|
None
|
Source code in src\dolphin_desktop\_desktop.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
launch
¶
launch(
cmd: str,
*,
timeout: float = 10.0,
work_dir: str | None = None,
startup_delay: float = 0.5,
) -> Application
Start a new process and return an :class:Application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Command line to execute (e.g. |
required |
timeout
|
float
|
Maximum seconds to wait for the process to start. |
10.0
|
work_dir
|
str | None
|
Optional working directory for the new process. |
None
|
startup_delay
|
float
|
Seconds to wait after the process starts before returning.
Useful for single-instance apps (e.g. Windows 11 Notepad) that
hand off to an existing process — a brief pause lets the target
window appear before :meth: |
0.5
|
Source code in src\dolphin_desktop\_desktop.py
connect
¶
connect(
*,
title: str | None = None,
title_re: str | None = None,
process: int | None = None,
path: str | None = None,
class_name: str | None = None,
found_index: int = 0,
timeout: float = 10.0,
) -> Application
Connect to an already-running process.
At least one search criterion must be provided.
When the criteria match more than one window (common for single-instance
apps such as Windows 11 Notepad, where several windows share a class
name or title pattern), found_index selects which match to use — the
first one (0) by default. Without this, pywinauto raises
ElementAmbiguousError on multiple matches.
Source code in src\dolphin_desktop\_desktop.py
for_legacy_apps
classmethod
¶
launch_qt
¶
Launch a Qt app with QT_ACCESSIBILITY=1.
launch_java
¶
Enable Java Access Bridge then launch a Java app.
Source code in src\dolphin_desktop\_desktop.py
launch_electron
¶
Launch an Electron/CEF app with accessibility enabled.
Source code in src\dolphin_desktop\_desktop.py
launch_cef
¶
Launch a standalone CEF (Chromium Embedded Framework) app.
Attempts to enable UIA accessibility by appending
--force-renderer-accessibility to the command line. This flag is
respected by CEF-based apps that pass unknown CLI arguments through to
the Chromium layer (e.g. some enterprise launchers, Battle.net Launcher).
.. warning::
Apps that wrap CEF in their own proprietary launcher (Spotify,
Steam) typically ignore this flag. For those apps, UIA
coverage is limited to what the app's own accessibility layer
exposes — see docs/cef.md for workarounds using
:class:~dolphin_desktop.ImageLocator.
Usage::
app = desktop.launch_cef(r"C:\path\to\cef_app.exe", timeout=20)
win = app.window(title_re=".*My CEF App.*", timeout=15)
assert app.is_cef()
Source code in src\dolphin_desktop\_desktop.py
launch_webview2
¶
Launch a WebView2-hosted WPF/WinForms app.
Edge WebView2 exposes a full UIA accessibility tree by default — no
special command-line flags are required. This method is a semantic
wrapper over :meth:launch that documents intent and mirrors the
launch_electron / launch_java / launch_qt family.
Source code in src\dolphin_desktop\_desktop.py
find_process
¶
find_process(
*,
name: str | None = None,
pid: int | None = None,
title: str | None = None,
title_re: str | None = None,
) -> Application | None
Return an Application connected to a matching running process, or None.
Source code in src\dolphin_desktop\_desktop.py
Usage examples¶
Launch an application¶
Connect to a running application¶
app = desktop.connect(title_re=".*My Application.*")
app = desktop.connect(class_name="Notepad")
app = desktop.connect(process=12345)
Technology-specific launchers¶
# Qt app - enables QT_ACCESSIBILITY=1
app = desktop.launch_qt("myqtapp.exe")
# Java Swing - enables Java Access Bridge
app = desktop.launch_java("java -jar myapp.jar")
# Electron - adds --force-renderer-accessibility
app = desktop.launch_electron("myelectronapp.exe")
# Edge WebView2 hybrid
app = desktop.launch_webview2("myhybridapp.exe")
# Legacy apps (Delphi, MFC, VB6)
desktop = Desktop.for_legacy_apps() # backend="win32"
Find a running process¶
app = desktop.find_process(name="notepad.exe")
app = desktop.find_process(title_re=".*Notepad.*")
app = desktop.find_process(pid=1234)