pyjab
pyjab copied to clipboard
Python implementation for Java application UI automation with Java Access Bridge
pyjab
Python implementation for Java application UI automation with Java Access Bridge
_.
The pyjab
package enables run UI automation(selenium like) through with
Java UI application.
Package will invoke Java Access Bridge
_ API to get information form
Java application.
And this package is only support for Windows.
Sources code referenced from NVDA
_.
.. contents:: :local:
Installation
The pyjab
package is available on PyPI
_ which means installation should
be as simple as:
.. code-block:: console
$ pip install pyjab
There's actually a multitude of ways to install Python packages (e.g. the per user site-packages directory
, virtual environments
or just installing
system wide) and I have no intention of getting into that discussion here, so
if this intimidates you then read up on your options before returning to these
instructions.
Optional dependencies
`Access Bridge Explorer`_ is a Windows application that allows exploring,
as well as interacting with, the Accessibility tree of any Java applications
that uses the Java Access Bridge to expose their accessibility features,
for example Android Studio and IntelliJ.
Usage
-----
JRE, JDK or JAB standalone package is required.
Need setup environment variable ``JAVA_HOME`` or ``JAB_HOME`` before usage.
Here's an example of how easy it is to get started:
.. code-block:: python
from pyjab.jabdriver import JABDriver
# Create a JABDriver object.
jabdriver = JABDriver("java app window title")
# Find a JABElement by element name
login_btn = jabdriver.find_element_by_name("Login")
# Click a JABElement
login_btn.click()
# Some other examples.
jabdriver.find_element_by_xpath("//push button[@name=contains('OK')]")
jabdriver.wait_until_element_exist(by=By.NAME, value="Dashboard")
login_btn.get_screenshot_as_file("./screenshot.png")
You may also use a context manager approach to kill the Java Window after the JABDriver is cleared:
.. code-block:: python
from pyjab.jabdriver import JABDriver
# Create a JABDriver object.
with JABDriver("java app window title") as jabdriver:
# Find a JABElement by element name
login_btn = jabdriver.find_element_by_name("Login")
# Click a JABElement
login_btn.click()
You can also open the Java window process by specifying the file path which will launch the Java WebStart process for the given file :
.. code-block:: python
from pyjab.jabdriver import JABDriver
# Create a JABDriver object.
with JABDriver(title="java app window title", file_path="C:\\jnlps\\test.jnlp") as jabdriver:
# Find a JABElement by element name
login_btn = jabdriver.find_element_by_name("Login")
# Click a JABElement
login_btn.click()
Contact
-------
The latest version of `pyjab` is available on `PyPI`_ and `GitHub`_.
For bug reports please create an issue on `GitHub`_. If you have questions,
suggestions, etc. feel free to send me an e-mail at `[email protected]`_.
License
-------
This software is licensed under the `GPLv2 license`_.
© 2021 Gary Gao.
.. External references:
.. _Java Access Bridge: https://docs.oracle.com/javase/accessbridge/2.0.2/toc.htm
.. _NVDA: https://github.com/nvaccess/nvda
.. _PyPI: https://pypi.org/
.. _GitHub: https://github.com/
.. _Access Bridge Explorer: https://github.com/google/access-bridge-explorer
.. _per user site-packages directory: https://www.python.org/dev/peps/pep-0370/
.. _virtual environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/
.. [email protected]: [email protected]
.. _GPLv2 license: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html