{"id":19607182,"url":"https://github.com/robocorp/working-with-java","last_synced_at":"2025-06-22T00:05:30.723Z","repository":{"id":174652299,"uuid":"652563387","full_name":"robocorp/working-with-java","owner":"robocorp","description":"Repository for developers working with Java applications","archived":false,"fork":false,"pushed_at":"2023-10-18T14:49:04.000Z","size":301,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-23T16:53:27.859Z","etag":null,"topics":["assistant","inspect","java","python","robotframework","rpa"],"latest_commit_sha":null,"homepage":"","language":"RobotFramework","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robocorp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-12T10:26:11.000Z","updated_at":"2023-07-10T10:43:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7c1fb92-3a0b-4b23-9798-73d17be26d48","html_url":"https://github.com/robocorp/working-with-java","commit_stats":null,"previous_names":["robocorp/working-with-java"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robocorp/working-with-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Fworking-with-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Fworking-with-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Fworking-with-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Fworking-with-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robocorp","download_url":"https://codeload.github.com/robocorp/working-with-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Fworking-with-java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261212483,"owners_count":23125583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assistant","inspect","java","python","robotframework","rpa"],"created_at":"2024-11-11T10:09:11.258Z","updated_at":"2025-06-22T00:05:25.669Z","avatar_url":"https://github.com/robocorp.png","language":"RobotFramework","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Working with Java\n\n## Introduction\n\nThis repository contains some helpful (hopefully :) ) tips for the developer on how to work with\nJava applications. Especially concentrating on Java application element structure and\nbuilding locators that work.\n\nDirect [link](#using-robocorp-java-assistant-to-inspect-java-application) to the Java assistant window description.\n\nRecent ``rpaframework`` have included improvements on how to interact with Java application information. It is now possible for example to iterate through Java structures although improvements on the library part are still going to be improved in the future releases.\n\nThe locator for each element of the application can be using `View locator Tree` button.\n\nIt is also possible to test locators against output from keyword ``Print Element Tree`` even when target Java application is not running, [read more](#using-command-line-tool-java_tree_reader).\n\nRepository consists:\n\n- example Java application `BasicSwing.jar` which is used in ``rpaframework`` testing\n- a customized [RPA.Assistant](https://robocorp.com/docs/libraries/rpa-framework/rpa-assistant) `CustomAssistant.py`\n- the Assistant implementation in `assistant.robot` file\n\n### Configurations\n\n1. The path to the Java access bridge DLL needs to be with set environment variable `RC_JAVA_ACCESS_BRIDGE_DLL`.\n2. Also library init parameter `ignore_callbacks=True` is set as this is case especially for older Java applications.\n\n### Background story\n\nThe current recommended way of inspecting Java application element structure is to use [Google's Access Bridge Explorer](https://github.com/google/access-bridge-explorer) application. Unfortunately repository for this tool has been archived since July 27th 2022 thus it is important to investigate alternative ways for developers to work with Java applications.\n\n**Note.** Contents of this repository are still under work and due to change!\n\n## Locator tree\n\nThe **locator tree** is a representation of the locators (usable by the `RPA.JavaAccessBridge` library) for each of the Java application's elements and this can be output with library keyword ``Print Locator Tree`` (keyword was added in rpaframework release 23.5.0).\n\n## Element tree\n\nThe **element tree** is a representation of the Java application's structure and this can be output with library keyword ``Print Element Tree``.\n\nImportant aspect to note about element/locator tree is that it is representation of the **current state** of the application. If application page structure changes in any way then usual method is to call library keyword ``Application Refresh`` so that library's internal model of the structure is updated.\n\n## Iterating Java context tree\n\n**Note.** This will get better in the future releases of `rpaframework` but currently iteration works like this\n\nRobot Framework example (really clunky)\n```robotframework\nIterating RPA.JavaAccessBridge context_info_tree\n    ${lib}=    Get Library Instance    RPA.JavaAccessBridge\n    Select Window By Title    Oracle Applications\n    FOR    ${item}    IN    @{lib.context_info_tree}\n        Log To Console    \\nname: ${{ $item.context_info.name }}\n        Log To Console    role: ${{ $item.context_info.role }}\n        Log To Console    x: ${{ $item.context_info.x }}\n        Log To Console    y: ${{ $item.context_info.y }}\n        Log To Console    width: ${{ $item.context_info.width }}\n        Log To Console    height: ${{ $item.context_info.height }}\n        Log To Console    states: ${{ $item.context_info.states }}\n        Log To Console    ancestry: ${{ $item.ancestry }}\n    END\n```\n\nPython example\n```python\nfrom RPA.JavaAccessBridge import JavaAccessBridge\n\njava = JavaAccessBridge()\n\njava.select_window_by_title(\"Oracle Applications\")\nfor item in java.context_info_tree:\n    print(f\"\\nname: {item.context_info.name}\")\n    print(f\"role: {item.context_info.role}\")\n    print(f\"x: {item.context_info.x}\")\n    print(f\"y: {item.context_info.y}\")\n    print(f\"width: {item.context_info.width}\")\n    print(f\"height: {item.context_info.height}\")\n    print(f\"states: {item.context_info.states}\")\n    print(f\"ancestry: {item.ancestry}\")\n```\n\n## Starting the BasicSwing.jar\n\n```bash\njava -jar BasicSwing.jar\n```\nBy default application's title will be \"`Chat Frame`\" but this JAR file can be started by adding arguments to give the application a different title.\n\nfor example.\n```\njava -jar BasicSwing.jar \"Oracle Applications\"\n```\n\n## Using Robocorp Java Assistant to inspect Java application\n\nProbably the most interesting approach on how to work with Java applications is the Assistant application implementation.\n\nTask to launch with `Robocorp Code` VS Code extension.\n```bash\nJava Assistant\n```\n\nThe assistant will automatically use `Select Window` to get access to Java available on the system.\n\n\u003cimg src=\"images/assistant.png\" style=\"margin-bottom:20px\"\u003e\n\nAssistant can be used to test locator against visible and selected Java application by entering locator into input field and then by clicking `Inspect Locator` (the hidden elements can be seen in inspect result by unchecking `Only visible` checkbox).\n\nThe `Load/Refresh element tree` button can be used to call `Application Refresh` keyword of the library.\n\nThe `List element roles` button lists all possible different element roles and their count on the application view.\n\nThe `View locator tree` opens the application's element tree on new page for view. On a condensed table the button to copy row's locator to clipboard and locator for the element is shown. The `|` characters mark the\ndepth of the element in the application's element tree.\n\n\u003cimg src=\"images/locator_tree_txt.png\" style=\"margin-bottom:20px\"\u003e\n\n## Using command line tool java_tree_reader\n\nThe `java_tree_reader` command line tool is available in Robot's Python environment, which can be launched with Robocorp Extension's `Open Robot Terminal`.\n\nThis tool takes in 2 input arguments, first the path to the element tree output file and second the locator you want to run against that element tree output to check for matches.\n\nCommand works with `element tree`, which can be saved using `Write locator tree to file` button in the Assistant UI. Button action will save both `locator tree` and `element tree` into Assistant's **output** folder.\n\n```bash\njava_tree_reader ./output/element-tree.txt role:push button\n```\n\n\u003cimg src=\"images/java_tree_reader.png\" style=\"margin-bottom:20px\"\u003e\n\n## Learning materials\n\n- [RPA.JavaAccessBridge library](https://robocorp.com/docs/libraries/rpa-framework/rpa-javaaccessbridge)\n- [Robocorp Developer Training Courses](https://robocorp.com/docs/courses)\n- [Documentation links on Robot Framework](https://robocorp.com/docs/languages-and-frameworks/robot-framework)\n- [Example bots in Robocorp Portal](https://robocorp.com/portal)\n- [Java locators](https://robocorp.com/docs/development-guide/locators#java-locators)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobocorp%2Fworking-with-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobocorp%2Fworking-with-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobocorp%2Fworking-with-java/lists"}