Start and control a virtualbox machine
Project description
Virtualbox helper
This library helps to automate UI tasks on a Virtualbox machine using OpenCV.
It's based on remotevbox
to interact with the SOAP service and OpenCV
to
perform region detection.
Features:
- can start the
vboxwebsrv
SOAP server programmatically and shut it down - match a region of the screen with a given fragment
- wait for a fragment and click on its center
- store if required a representation of the area it matched
- accepts images as NumPy ndarray, raw bytes of filesystem paths
Installation
python3 -m pip install virtualbox_helper
Example usage
from virtualbox_helper import (
ensure_server_running,
get_machine,
wait_for_fragment,
wait_click_on_fragment,
)
# this starts the server and stops it when the interpreter exits
# or you can use the command vboxwebsrv manually
ensure_server_running()
machine = get_machine('vbox', 'yourpassphrase', 'Debian testing')
machine.launch()
no_match = detect_fragment(screenshot_data, 'some/random_image.png')
assert no_match is None
detection = detect_fragment(screenshot_data, 'valid_element.png')
assert detection is not None
# similarity score
assert detection[0] > 0.9
# coordinates of the bounding box that was detected
assert detection[1] == (19, 59)
assert detection[2] == (172, 114)
# raw bytes or a numpy (X, Y, 3) matrix can be used instead of a file path
button_data = open('button.png', 'rb').read()
target = wait_click_on_fragment(machine, button_data, timeout=60.0)
# target has the same structure of match above
wait_for_fragment(machine, 'some/element/to/wait_for.png')
with open('screenshot.png', 'wb') as f:
screenshot_data = machine.take_screenshot_to_bytes()
f.write(screenshot_data)
# this functionality is part of remotevbox
machine.send_character_string('hello world')
machine.send_key_combination(['<enter>'])
machine.poweroff()
When shoulkd I use this?
Hopefully never! If you have a proper API for what you want to automate,
go with that.
To automate UI operations look into PyAutoGUI
, and Selenium
or Puppeteer
for the web.
However, if you can't do that, for example if you are writing tests for TempleOS or something weird, then this may be fine.
Tests
The tests are based on pytest, can be run using poetry run test
.
They expect a machine called "Debian testing" running Debian 11.
Should be trivial to adapt to some other image.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file virtualbox_helper-0.1.2.tar.gz
.
File metadata
- Download URL: virtualbox_helper-0.1.2.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.8.6 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbbede8a3742d4da50f96db956983b05b9ea2aab0f101d5ce63dda05997e0a88 |
|
MD5 | 37ab58b935bb1eaf424ad52afd0a3920 |
|
BLAKE2b-256 | 1573b9671b105bafa325ca58e39c8eba1cfc946a107a068fd7f8ee3d9b1df675 |
File details
Details for the file virtualbox_helper-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: virtualbox_helper-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.8.6 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5608e1408e68a8ac37644099e55a9119dd1d61c0ae1bf7ff5b307763d64f36f |
|
MD5 | b65a21f5f73e9b4549c693195baa35a9 |
|
BLAKE2b-256 | 7b2fb42722e7acc048e593548c53e14b085fc433decb8f39319b10f7fb06b10e |