Controller API
pymordialblue.bluestacks_controller
Main controller for the Pymordial automation framework.
PymordialBluestacksController
Bases: PymordialController
Main controller that orchestrates device interaction via plugins.
This controller manages the lifecycle of connected devices (ADB, UI, Emulator) using the Plugin Registry.
Attributes:
| Name | Type | Description |
|---|---|---|
adb |
The PymordialAdbDevice instance. |
|
ui |
The PymordialUiDevice instance. |
|
bluestacks |
The PymordialBluestacksDevice instance. |
Source code in src/pymordialblue/bluestacks_controller.py
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
__init__(adb_host=None, adb_port=None, apps=None)
Initializes the PymordialController.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adb_host
|
str | None
|
Optional ADB host address. |
None
|
adb_port
|
int | None
|
Optional ADB port. |
None
|
apps
|
list[PymordialAndroidApp] | None
|
Optional list of PymordialAndroidApp instances to register. |
None
|
Source code in src/pymordialblue/bluestacks_controller.py
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 | |
open_app(app_name, package_name=None, timeout=None, wait_time=None)
Opens an app on the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str | PymordialAndroidApp
|
The display name of the app or a PymordialAndroidApp instance. |
required |
package_name
|
str | None
|
The Android package name. |
None
|
timeout
|
int | None
|
Maximum seconds to wait for launch. |
None
|
wait_time
|
int | None
|
Seconds to wait after launch command. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the app launched successfully, False otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
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 | |
close_app(app_name, package_name=None, timeout=None, wait_time=None)
Closes an app on the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str | PymordialAndroidApp
|
The display name of the app or a PymordialAndroidApp instance. |
required |
package_name
|
str | None
|
The Android package name. |
None
|
timeout
|
int | None
|
Maximum seconds to wait for closure. |
None
|
wait_time
|
int | None
|
Seconds to wait after close command. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the app closed successfully, False otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
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 | |
capture_screen()
Captures the current screen.
Returns:
| Type | Description |
|---|---|
bytes | None
|
Screenshot as bytes, or None if failed. |
Convenience method that delegates to adb.capture_screenshot().
Source code in src/pymordialblue/bluestacks_controller.py
202 203 204 205 206 207 208 209 210 | |
disconnect()
Closes the ADB connection and performs cleanup.
Source code in src/pymordialblue/bluestacks_controller.py
212 213 214 215 | |
click_coord(coords, times=CLICK_COORD_TIMES)
Clicks specific coordinates on the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
tuple[int, int]
|
(x, y) coordinates to click. |
required |
times
|
int
|
Number of times to click. |
CLICK_COORD_TIMES
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the click was sent successfully, False otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
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 | |
click_element(pymordial_element, times=DEFAULT_CLICK_TIMES, screenshot_img_bytes=None, max_tries=DEFAULT_MAX_TRIES)
Clicks a UI element on the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_element
|
PymordialElement
|
The element to click. |
required |
times
|
int
|
Optional number of times to click. Defaults to DEFAULT_CLICK_TIMES config. |
DEFAULT_CLICK_TIMES
|
screenshot_img_bytes
|
bytes | None
|
Optional pre-captured screenshot to look for the element in. Defaults to None. |
None
|
max_tries
|
int
|
Optional maximum number of retries to find the element. Defaults to DEFAULT_MAX_TRIES config. |
DEFAULT_MAX_TRIES
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the element was found and clicked, False otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
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 | |
click_elements(pymordial_elements, screenshot_img_bytes=None, max_tries=DEFAULT_MAX_TRIES)
Clicks any of the elements in the list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_elements
|
list[PymordialElement]
|
List of elements to try clicking. |
required |
screenshot_img_bytes
|
bytes | None
|
Optional pre-captured screenshot. |
None
|
max_tries
|
int
|
Maximum number of retries per element. |
DEFAULT_MAX_TRIES
|
Returns:
| Type | Description |
|---|---|
bool
|
True if any element was clicked, False otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
go_home()
Navigate to Android home screen.
Convenience method that delegates to adb.go_home().
Source code in src/pymordialblue/bluestacks_controller.py
328 329 330 331 332 333 | |
go_back()
Press Android back button.
Convenience method that delegates to adb.go_back().
Source code in src/pymordialblue/bluestacks_controller.py
335 336 337 338 339 340 | |
tap(x, y)
Tap at specific coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X coordinate. |
required |
y
|
int
|
Y coordinate. |
required |
Convenience method that delegates to adb.tap().
Source code in src/pymordialblue/bluestacks_controller.py
342 343 344 345 346 347 348 349 350 351 | |
swipe(start_x, start_y, end_x, end_y, duration=300)
Perform swipe gesture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_x
|
int
|
Starting X coordinate. |
required |
start_y
|
int
|
Starting Y coordinate. |
required |
end_x
|
int
|
Ending X coordinate. |
required |
end_y
|
int
|
Ending Y coordinate. |
required |
duration
|
int
|
Swipe duration in milliseconds. |
300
|
Convenience method that delegates to adb.swipe().
Source code in src/pymordialblue/bluestacks_controller.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
find_element(pymordial_element, pymordial_screenshot=None, max_tries=DEFAULT_MAX_TRIES)
Finds the coordinates of a UI element on the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_element
|
PymordialElement
|
The element to find. |
required |
pymordial_screenshot
|
bytes | None
|
Optional pre-captured screenshot. |
None
|
max_tries
|
int
|
Maximum number of retries. |
DEFAULT_MAX_TRIES
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
(x, y) coordinates if found, None otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
is_element_visible(pymordial_element, pymordial_screenshot=None, max_tries=None)
Checks if a UI element is visible on the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_element
|
PymordialElement
|
The element to check for. |
required |
pymordial_screenshot
|
bytes | None
|
Optional pre-captured screenshot. |
None
|
max_tries
|
int | None
|
Optional maximum number of retries. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the element is found, False otherwise. |
Source code in src/pymordialblue/bluestacks_controller.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
press_enter()
Press the Enter key.
Convenience method that delegates to adb.press_enter().
Source code in src/pymordialblue/bluestacks_controller.py
490 491 492 493 494 495 | |
press_esc()
Press the Esc key.
Convenience method that delegates to adb.press_esc().
Source code in src/pymordialblue/bluestacks_controller.py
497 498 499 500 501 502 | |
type_text(text, enter=False)
Send text input to the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to send. |
required |
enter
|
bool
|
Whether to press enter after typing. |
False
|
Convenience method that delegates to adb.type_text().
Source code in src/pymordialblue/bluestacks_controller.py
504 505 506 507 508 509 510 511 512 513 | |
run_command(command)
Execute ADB shell command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Shell command to execute. |
required |
Returns:
| Type | Description |
|---|---|
bytes | None
|
Command output as bytes, or None if failed. |
Convenience method that delegates to adb.run_command().
Source code in src/pymordialblue/bluestacks_controller.py
517 518 519 520 521 522 523 524 525 526 527 528 | |
get_current_app()
Get the currently running app's package name.
Returns:
| Type | Description |
|---|---|
str | None
|
Package name of current app, or None if failed. |
Convenience method that delegates to adb.get_current_app().
Source code in src/pymordialblue/bluestacks_controller.py
530 531 532 533 534 535 536 537 538 | |
read_text(image_path, case_sensitive=False, strategy=None)
Read text from an image using OCR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
Path | bytes | str
|
Path to image file, image bytes, or string path. |
required |
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of detected text lines. |
Convenience method that delegates to text.read_text().
Source code in src/pymordialblue/bluestacks_controller.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
check_text(text_to_find, image_path, case_sensitive=False, strategy=None)
Check if specific text exists in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_to_find
|
str
|
Text to search for. |
required |
image_path
|
Path | bytes | str
|
Image to search in. |
required |
case_sensitive
|
bool
|
Whether search is case-sensitive. |
False
|
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if text found, False otherwise. |
Convenience method that delegates to text.check_text().
Source code in src/pymordialblue/bluestacks_controller.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
is_bluestacks_ready()
Check if BlueStacks is in READY state.
Returns:
| Type | Description |
|---|---|
bool
|
True if BlueStacks is ready, False otherwise. |
Convenience method that delegates to self.bluestacks.is_ready().
Source code in src/pymordialblue/bluestacks_controller.py
585 586 587 588 589 590 591 592 593 | |
is_bluestacks_loading()
Check if BlueStacks is currently loading.
Returns:
| Type | Description |
|---|---|
bool
|
True if BlueStacks is loading, False otherwise. |
Convenience method that delegates to bluestacks.is_loading().
Source code in src/pymordialblue/bluestacks_controller.py
595 596 597 598 599 600 601 602 603 | |
start_streaming()
Starts the screen stream using ADB device.
Returns:
| Type | Description |
|---|---|
bool
|
True if streaming started successfully, False otherwise. |
Convenience method that delegates to adb.start_stream().
Source code in src/pymordialblue/bluestacks_controller.py
607 608 609 610 611 612 613 614 615 616 617 618 | |
get_frame()
Get the latest frame from the active stream.
Returns:
| Type | Description |
|---|---|
ndarray | None
|
Latest frame as numpy array (RGB), or None if unavailable. |
Convenience method that delegates to adb.get_latest_frame().
Example
frame = controller.get_frame() if frame is not None: ... # Process frame (OCR, template matching, etc.) ... text = controller.read_text(frame)
Source code in src/pymordialblue/bluestacks_controller.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
stop_streaming()
Stop the active video stream and disable auto-restart.
Convenience method that delegates to adb.stop_stream().
Source code in src/pymordialblue/bluestacks_controller.py
636 637 638 639 640 641 642 | |
__repr__()
Returns a string representation of the PymordialController.
Source code in src/pymordialblue/bluestacks_controller.py
644 645 646 647 648 649 650 651 | |