Skip to content

robocorp/java-access-bridge-wrapper

 
 

Repository files navigation

Version License

Introduction

Python wrapper around the Java Access Bridge / Windows Access Bridge.

Requirements

Enable the Java Access Bridge in windows

C:\path\to\java\bin\jabswitch -enable

Install

pip install java-access-bridge-wrapper

How to use

Import the Java Access Bridge (JAB) wrapper and optionally the context tree

from JABWrapper.jab_wrapper import JavaAccessBridgeWrapper
from JABWrapper.context_tree import ContextNode, ContextTree, SearchElement

The JAB creates an virtual GUI window when it is opened. For the JAB to operate and receive events from the GUI, the calling code needs to implement the windows message pump and call it in a loop. The JABWrapper object needs to be in the same thread.

This can be achieved for example by starting the message pump in a separate thread, where the JAB object is also initialized.

GetMessage = ctypes.windll.user32.GetMessageW
TranslateMessage = ctypes.windll.user32.TranslateMessage
DispatchMessage = ctypes.windll.user32.DispatchMessageW

def pump_background(pipe: queue.Queue):
    try:
        jab_wrapper = JavaAccessBridgeWrapper()
        pipe.put(jab_wrapper)
        message = byref(wintypes.MSG())
        while GetMessage(message, 0, 0, 0) > 0:
            TranslateMessage(message)
            logging.debug("Dispatching msg={}".format(repr(message)))
            DispatchMessage(message)
    except Exception as err:
        pipe.put(None)

def main():
    pipe = queue.Queue()
        thread = threading.Thread(target=pump_background, daemon=True, args=[pipe])
        thread.start()
        jab_wrapper = pipe.get()
        if not jab_wrapper:
            raise Exception("Failed to initialize Java Access Bridge Wrapper")
        time.sleep(0.1) # Wait until the initial messages are parsed, before accessing frames

if __name__ == "__main__":
    main()

Once the JABWrapper object is initialized, attach to some frame and optionally create the context tree to get the element tree of the application.

jab_wrapper.switch_window_by_title("Frame title")
context_tree = ContextTree(jab_wrapper)

Development

Prerequisites

  • uv - Fast Python package manager

Setup

Install all dependencies (including dev tools):

uv sync --all-groups

Testing

Run test script against a simple Swing application.

Set environment variable:

set RC_JAVA_ACCESS_BRIDGE_DLL="C:\path\to\Java\bin\WindowsAccessBridge-64.dll"

Run tests:

inv test                                    # run all tests
inv test -t test_jab_wrapper.py             # run tests from a file
inv test -t test_jab_wrapper.py::test_depth -c  # specific test with output
inv test -s                                 # simple mode (single scenario, no callbacks)

Linting

Check code style:

inv lint

Apply formatting fixes:

inv lint -a

Packaging

Build and publish:

inv publish

Build only (no publish):

inv publish --build-only

TODO:

  • Support for 32-bit Java Access Bridge version
  • Implement rest of the utility functions to the JABWrapper

About

Python wrapper around the Java Access Bridge Windows .dll

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors