├── .github └── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── custom.yml ├── .gitignore ├── HEADER ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── com │ └── epam │ └── healenium │ └── appium │ ├── MobileSelectorComponent.java │ ├── MobileSelfHealingEngine.java │ ├── elementcreators │ ├── MobileParentElementCreator.java │ ├── MobilePathElementCreator.java │ ├── MobilePositionElementCreator.java │ ├── MobileTagElementCreator.java │ └── attribute │ │ ├── AbstractAttributeElementCreator.java │ │ ├── ContentDescElementCreator.java │ │ ├── MobileIdElementCreator.java │ │ ├── ResourceIdElementCreator.java │ │ └── TextElementCreator.java │ ├── handlers │ └── proxy │ │ ├── MobileBaseHandler.java │ │ ├── MobileSelfHealingProxyInvocationHandler.java │ │ └── MobileWebElementProxyHandler.java │ ├── service │ ├── MobileHealingService.java │ └── MobileNodeService.java │ ├── utils │ └── MobileStackTraceReader.java │ └── wrapper │ ├── DriverWrapper.java │ └── ElementWrapper.java └── resources └── application.conf /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Create a report to help us improve 3 | title: "[BUG]: " 4 | labels: [ bug ] 5 | assignees: Alex-Reif 6 | body: 7 | - type: textarea 8 | id: description 9 | attributes: 10 | label: Describe the bug 11 | description: | 12 | Provide a clear and concise description of what the bug is. 13 | placeholder: | 14 | Please add as many details as possible to avoid assumptions from our side. 15 | validations: 16 | required: true 17 | - type: textarea 18 | id: reproduction 19 | attributes: 20 | label: How to reproduce the issue 21 | description: | 22 | Describe steps to reproduce the behavior. The more details you write, the faster we can help you. 23 | placeholder: | 24 | Please, describe step by step how you start Healenium: how you start Docker, how you create WebDriver, etc. 25 | Notes: 26 | -If the problem appeares during healing process provide code with creating locators and creating WebDriver. 27 | -If the problem relates to Docker provide folder structure with docker-compose file and what you add to this file. 28 | -Write as more as you can by your company policy. 29 | render: shell 30 | validations: 31 | required: true 32 | - type: textarea 33 | id: logs 34 | attributes: 35 | label: Logs appeared during using Healenium 36 | description: | 37 | Provide logs you've seen during investigation 38 | placeholder: | 39 | Notes: 40 | -If the problem appeares during healing process provide stacktrace with exception. 41 | -If the problem relates to Docker or Proxy provide docker hlm-backend container logs. 42 | -Add as more logs as you can by your company policy. 43 | render: shell 44 | validations: 45 | required: true 46 | - type: textarea 47 | id: epx-behavior 48 | attributes: 49 | label: Expected behavior 50 | description: | 51 | Please provide clear and concise description of what you expected to happen. 52 | - type: textarea 53 | id: act-behavior 54 | attributes: 55 | label: Actual behavior 56 | description: | 57 | Please provide clear and concise description of what you've seen instead. 58 | - type: input 59 | id: back-hlm 60 | attributes: 61 | label: Healenium Backend version 62 | description: What healenium-backend version do you use? 63 | validations: 64 | required: true 65 | - type: input 66 | id: appium-hlm 67 | attributes: 68 | label: Healenium Appium version 69 | description: What healenium-backend version do you use? 70 | validations: 71 | required: true 72 | - type: input 73 | id: selenium-version 74 | attributes: 75 | label: Selenium version 76 | description: What Selenium version do you use for testing? 77 | - type: input 78 | id: platform 79 | attributes: 80 | label: Platform 81 | placeholder: Java? .NET? Python? Something else? 82 | validations: 83 | required: true 84 | - type: textarea 85 | id: additional 86 | attributes: 87 | label: Additional context 88 | description: Add any other context about the problem here 89 | placeholder: For example, screenshot or using of additional frameworks like Sizzle library, Robot Framework or JDI, etc. If you can please, send a link to your project. 90 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.yml: -------------------------------------------------------------------------------- 1 | name: Help-support template 2 | description: Describe you problem happened using Healenium and team will help 3 | title: "[Need support]: " 4 | labels: [ help wanted ] 5 | assignees: Alex-Reif 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | If you didn't see the video how to use Healenium, please, firstly, get it know on link https://healenium.io/ 11 | 12 | - type: textarea 13 | id: description 14 | attributes: 15 | label: Describe the problem 16 | description: | 17 | Provide a clear and concise description of the problem you've faced with. 18 | placeholder: | 19 | Please add as many details as possible to avoid assumptions from our side. 20 | validations: 21 | required: true 22 | 23 | - type: input 24 | id: back-hlm 25 | attributes: 26 | label: Healenium Backend version 27 | description: What healenium-backend version do you use? 28 | validations: 29 | required: true 30 | 31 | - type: input 32 | id: appium-hlm 33 | attributes: 34 | label: Healenium Appium version 35 | description: What healenium-backend version do you use? 36 | validations: 37 | required: true 38 | 39 | - type: input 40 | id: selenium-version 41 | attributes: 42 | label: Selenium version 43 | description: What Selenium version do you use for testing? 44 | - type: input 45 | id: platform 46 | attributes: 47 | label: Platform 48 | placeholder: Java? .NET? Python? Something else? 49 | 50 | - type: textarea 51 | id: logs 52 | attributes: 53 | label: Logs appeared during using Healenium 54 | description: | 55 | Provide logs you've seen during investigation 56 | placeholder: | 57 | Notes: 58 | -If the problem appeares during healing process provide stacktrace with exception. 59 | -If the problem relates to Docker or Proxy provide docker hlm-backend container logs. 60 | -Add as more logs as you can by your company policy. 61 | render: shell 62 | validations: 63 | required: true 64 | 65 | - type: textarea 66 | id: additional 67 | attributes: 68 | label: Additional context 69 | description: Add any other context about the problem here 70 | placeholder: For example, screenshot or using of additional frameworks like Sizzle library, Robot Framework or JDI, etc. If you can please, send a link to your project. 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.war 2 | *.ear 3 | *.zip 4 | *.iml 5 | *.pydevproject 6 | .project 7 | .metadata 8 | .svn/ 9 | target/ 10 | build/ 11 | classes/ 12 | /drivers/ 13 | .gradle/ 14 | bin/** 15 | tmp/** 16 | tmp/**/* 17 | *.tmp 18 | *.bak 19 | local.properties 20 | .classpath 21 | .settings/ 22 | .loadpath 23 | 24 | # Locally stored "Eclipse launch configurations" 25 | *.launch 26 | 27 | .idea/ 28 | .idea 29 | *.classpath 30 | *.project 31 | *.settings 32 | 33 | out/ 34 | .DS_Store -------------------------------------------------------------------------------- /HEADER: -------------------------------------------------------------------------------- 1 | Healenium-appium Copyright (C) 2019 EPAM 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Healenium-Appium 2 | 3 | [![Docker Pulls](https://img.shields.io/docker/pulls/healenium/hlm-backend.svg?maxAge=25920)](https://hub.docker.com/u/healenium) 4 | [![License](https://img.shields.io/badge/license-Apache-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0) 5 | [![@healenium](https://img.shields.io/badge/Telegram-%40healenium-orange.svg)](https://t.me/healenium) 6 | 7 | ### Table of Contents 8 | 9 | [Overall information](#overall-information) 10 | 11 | [Compatibility with OSs](#compatibility-with-oss) 12 | 13 | [Healenium Appium installation](#healenium-appium-installation) 14 | 15 | [Language Examples](#language-examples) 16 | * [Java](#java) 17 | * [Python](#python) 18 | 19 | 20 | ### Overall information 21 | Self-healing framework based on Selenium and able to use all Selenium supported languages like Java/Python/JS/C# 22 | Healenium acts as proxy between client and Appium server. 23 | 24 | `Docker-compose` includes the following services: 25 | - `postgres-db` (PostgreSQL database to store etalon selector / healing / report) 26 | - `hlm-proxy` (Proxy client request to Appium server) 27 | - `hlm-backend` (CRUD service) 28 | - `selector-imitator` (Convert healed locator to convenient format) 29 | 30 | ### Compatibility with OSs 31 | 32 | Support: Android Web/native and IOS Web/native apps. 33 | 34 | ### Healenium-Appium installation 35 | 36 | Clone Healenium repository: 37 | ```sh 38 | git clone https://github.com/healenium/healenium.git 39 | ``` 40 | 41 | > Before run healenium you have to specify appium server host and port using appropriate environment variables of hlm-proxy container: APPIUM_SERVER_URL 42 | 43 | Example setup hlm-proxy's env variables in case of local Appium server (specified by default): 44 | 45 | ```dockerfile 46 | - APPIUM_SERVER_URL=http://host.docker.internal:4723/wd/hub 47 | ``` 48 | 49 | Run Healenium with Appium only 50 | 51 | ```sh 52 | docker-compose -f docker-compose-appium.yaml up -d 53 | ``` 54 | 55 | Run Healenium with Appium and Selenoid 56 | 57 | ```sh 58 | docker-compose up -d 59 | ``` 60 | 61 | ### Language examples 62 | 63 | ``` 64 | /** 65 | * "http://127.0.0.1:8085" OR "http://localhost:8085" if you are using locally running proxy server 66 | * 67 | * if you want to use a remote proxy server, 68 | * specify the ip address of this server - "http://remote_ip_address:8085" 69 | */ 70 | ``` 71 | 72 | ###### Java: 73 | ```java 74 | String nodeURL = "http://localhost:8085"; 75 | 76 | MutableCapabilities cap = new MutableCapabilities(); 77 | cap.setCapability("platformName", "android"); 78 | cap.setCapability("deviceName", "emulator-5554"); 79 | cap.setCapability("browserName", "chrome"); 80 | cap.setCapability("nativeWebScreenshot",true); 81 | 82 | AppiumDriver driver = new AppiumDriver(new URL(nodeURL), cap); 83 | ``` 84 | 85 | ###### Python 86 | ```py 87 | nodeURL = "http://localhost:8085" 88 | 89 | # Set the desired capabilities. 90 | desired_caps = {} 91 | desired_caps['platformName'] = 'Android' 92 | desired_caps['platformVersion'] = '9' 93 | desired_caps['deviceName'] = 'emulator-5554' 94 | desired_caps['browserName'] = 'chrome' 95 | desired_caps['nativeWebScreenshot'] = 'true' 96 | 97 | wd = webdriver.Remote('http://127.0.0.1:8085', desired_caps) 98 | ``` 99 | 100 | ## Community / Support 101 | 102 | * [Telegram chat](https://t.me/healenium) 103 | * [GitHub Issues](https://github.com/healenium/healenium/issues) 104 | * [YouTube Channel](https://www.youtube.com/channel/UCsZJ0ri-Hp7IA1A6Fgi4Hvg) 105 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 4.0.0 11 | com.epam.healenium 12 | healenium-appium 13 | 1.5.12 14 | jar 15 | healenium-appium 16 | healenium appium client 17 | https://healenium.io/ 18 | 19 | 20 | Apache License 2.0 21 | http://www.apache.org/licenses/ 22 | repo 23 | 24 | 25 | 26 | 27 | engineer 28 | Aliaksei Ashukha 29 | aliaksei_ashukha@epam.com 30 | UTC+3 31 | 32 | 33 | engineer 34 | Anatoli Zaitsau 35 | anatoli_zaitsau@epam.com 36 | UTC+3 37 | 38 | 39 | 40 | scm:git:git@github.com:healenium/healenium-web.git 41 | scm:git:git@github.com:healenium/healenium-web.git 42 | git@github.com:healenium/healenium-web.git 43 | 44 | 45 | 46 | 47 | ossrh 48 | https://oss.sonatype.org/content/repositories/snapshots 49 | 50 | 51 | ossrh 52 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 53 | 54 | 55 | 56 | 57 | 58 | 3.5.5 59 | UTF-8 60 | 1.3.4 61 | 3.11 62 | 1.7.30 63 | 18.0.0 64 | 1.18.20 65 | 3.26.0-GA 66 | 5.7.1 67 | 9.2.3 68 | 69 | 70 | 71 | 72 | sign-artifacts 73 | 74 | 75 | performRelease 76 | true 77 | 78 | 79 | 80 | 81 | 82 | org.apache.maven.plugins 83 | maven-gpg-plugin 84 | 1.6 85 | 86 | ${gpg.passphrase} 87 | 88 | --no-tty 89 | 90 | 91 | 92 | 93 | sign-artifacts 94 | verify 95 | 96 | sign 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-source-plugin 111 | 2.2.1 112 | 113 | 114 | attach-sources 115 | package 116 | 117 | jar 118 | 119 | 120 | 121 | 122 | 123 | org.apache.maven.plugins 124 | maven-jar-plugin 125 | 2.3.1 126 | 127 | 128 | false 129 | 130 | 131 | 132 | 133 | org.sonatype.plugins 134 | nexus-staging-maven-plugin 135 | 1.6.3 136 | true 137 | 138 | 139 | deploy 140 | 141 | 142 | 143 | ossrh 144 | https://oss.sonatype.org/ 145 | false 146 | 147 | 148 | 149 | org.apache.maven.plugins 150 | maven-surefire-plugin 151 | 3.0.0-M5 152 | 153 | 0 154 | false 155 | 156 | 157 | 158 | org.apache.maven.plugins 159 | maven-compiler-plugin 160 | 3.8.1 161 | 162 | 8 163 | 8 164 | 165 | 166 | 167 | org.apache.maven.plugins 168 | maven-javadoc-plugin 169 | 3.3.2 170 | 171 | 8 172 | 173 | 174 | 175 | attach-javadocs 176 | package 177 | 178 | jar 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | com.epam.healenium 189 | healenium-web 190 | ${healenium.version} 191 | 192 | 193 | org.apache.maven 194 | maven-plugin-api 195 | 3.9.7 196 | 197 | 198 | com.typesafe 199 | config 200 | ${typesafe.version} 201 | compile 202 | 203 | 204 | org.apache.commons 205 | commons-lang3 206 | ${commonslang3.version} 207 | compile 208 | 209 | 210 | org.projectlombok 211 | lombok 212 | ${lombok.version} 213 | compile 214 | 215 | 216 | org.junit.jupiter 217 | junit-jupiter-engine 218 | ${junit.version} 219 | test 220 | 221 | 222 | org.junit.jupiter 223 | junit-jupiter-api 224 | ${junit.version} 225 | test 226 | 227 | 228 | io.appium 229 | java-client 230 | ${appium.version} 231 | 232 | 233 | org.javassist 234 | javassist 235 | ${javassist.version} 236 | 237 | 238 | 239 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/MobileSelectorComponent.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium; 2 | 3 | import com.epam.healenium.appium.elementcreators.MobileParentElementCreator; 4 | import com.epam.healenium.appium.elementcreators.MobilePathElementCreator; 5 | import com.epam.healenium.appium.elementcreators.MobilePositionElementCreator; 6 | import com.epam.healenium.appium.elementcreators.MobileTagElementCreator; 7 | import com.epam.healenium.appium.elementcreators.attribute.ContentDescElementCreator; 8 | import com.epam.healenium.appium.elementcreators.attribute.MobileIdElementCreator; 9 | import com.epam.healenium.appium.elementcreators.attribute.ResourceIdElementCreator; 10 | import com.epam.healenium.appium.elementcreators.attribute.TextElementCreator; 11 | import com.epam.healenium.elementcreators.ElementCreator; 12 | import com.epam.healenium.treecomparing.Node; 13 | import lombok.AllArgsConstructor; 14 | 15 | @AllArgsConstructor 16 | public enum MobileSelectorComponent { 17 | 18 | MOBILE_PATH(new MobilePathElementCreator()), 19 | MOBILE_PARENT(new MobileParentElementCreator()), 20 | MOBILE_TAG(new MobileTagElementCreator()), 21 | RESOURCE_ID(new ResourceIdElementCreator()), 22 | MOBILE_ID(new MobileIdElementCreator()), 23 | TEXT(new TextElementCreator()), 24 | CONTENT_DESC(new ContentDescElementCreator()), 25 | MOBILE_POSITION(new MobilePositionElementCreator()); 26 | 27 | private final ElementCreator elementCreator; 28 | 29 | public String createComponent(Node node) { 30 | return elementCreator.create(node); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/MobileSelfHealingEngine.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium; 2 | 3 | import com.epam.healenium.SelfHealingEngine; 4 | import com.epam.healenium.treecomparing.JsoupXMLParser; 5 | import com.epam.healenium.treecomparing.Node; 6 | import com.typesafe.config.Config; 7 | import io.appium.java_client.AppiumDriver; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.openqa.selenium.OutputType; 10 | import org.openqa.selenium.TakesScreenshot; 11 | import org.openqa.selenium.WebDriver; 12 | import org.openqa.selenium.WebElement; 13 | 14 | import java.io.ByteArrayInputStream; 15 | import java.nio.charset.StandardCharsets; 16 | 17 | public class MobileSelfHealingEngine extends SelfHealingEngine { 18 | 19 | public MobileSelfHealingEngine(@NotNull WebDriver delegate, @NotNull Config config) { 20 | super(delegate, config); 21 | } 22 | 23 | @Override 24 | public String getCurrentUrl() { 25 | return (String) ((AppiumDriver) getWebDriver()).getCapabilities().asMap() 26 | .getOrDefault("appActivity", ""); 27 | } 28 | 29 | @Override 30 | public String pageSource() { 31 | return getWebDriver().getPageSource(); 32 | } 33 | 34 | @Override 35 | public Node parseTree(String tree) { 36 | return new JsoupXMLParser().parse(new ByteArrayInputStream(tree.getBytes(StandardCharsets.UTF_8))); 37 | } 38 | 39 | @Override 40 | public byte[] captureScreen(WebElement element) { 41 | return ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.BYTES); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/MobileParentElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators; 2 | 3 | import com.epam.healenium.appium.elementcreators.attribute.ContentDescElementCreator; 4 | import com.epam.healenium.appium.elementcreators.attribute.MobileIdElementCreator; 5 | import com.epam.healenium.appium.elementcreators.attribute.ResourceIdElementCreator; 6 | import com.epam.healenium.appium.elementcreators.attribute.TextElementCreator; 7 | import com.epam.healenium.elementcreators.ElementCreator; 8 | import com.epam.healenium.treecomparing.Node; 9 | import org.apache.commons.lang3.StringUtils; 10 | 11 | import java.util.stream.Collectors; 12 | import java.util.stream.Stream; 13 | 14 | public class MobileParentElementCreator implements ElementCreator { 15 | 16 | private final MobileTagElementCreator classElementCreator = new MobileTagElementCreator(); 17 | private final MobileIdElementCreator idElementCreator = new MobileIdElementCreator(); 18 | private final ResourceIdElementCreator resourceIdElementCreator = new ResourceIdElementCreator(); 19 | private final TextElementCreator textCreator = new TextElementCreator(); 20 | private final ContentDescElementCreator contentDescElementCreator = new ContentDescElementCreator(); 21 | 22 | @Override 23 | public String create(Node node) { 24 | Node parent = node.getParent(); 25 | if (parent == null) { 26 | return ""; 27 | } 28 | return Stream.of(classElementCreator, resourceIdElementCreator, idElementCreator, textCreator, contentDescElementCreator) 29 | .map(creator -> creator.create(parent)) 30 | .filter(s -> !StringUtils.isEmpty(s)) 31 | .collect(Collectors.joining()) 32 | .concat("/"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/MobilePathElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators; 2 | 3 | import com.epam.healenium.elementcreators.ElementCreator; 4 | import com.epam.healenium.treecomparing.Node; 5 | 6 | import java.util.ArrayDeque; 7 | import java.util.Deque; 8 | 9 | public class MobilePathElementCreator implements ElementCreator { 10 | 11 | private final MobilePositionElementCreator positionCreator = new MobilePositionElementCreator(); 12 | 13 | @Override 14 | public String create(Node node) { 15 | Node current = node; 16 | Deque path = new ArrayDeque<>(); 17 | while (current != null) { 18 | String item = current.getTag(); 19 | if (hasSimilarNeighbours(current)) { 20 | item += positionCreator.create(current); 21 | } 22 | path.addFirst(item); 23 | current = current.getParent(); 24 | } 25 | return String.join("/", path); 26 | } 27 | 28 | private boolean hasSimilarNeighbours(Node current) { 29 | Node parent = current.getParent(); 30 | if (parent == null) { 31 | return false; 32 | } 33 | return parent.getChildren() 34 | .stream() 35 | .map(Node::getTag) 36 | .filter(tag -> tag.equals(current.getTag())) 37 | .count() > 1L; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/MobilePositionElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators; 2 | 3 | import com.epam.healenium.elementcreators.ElementCreator; 4 | import com.epam.healenium.treecomparing.Node; 5 | 6 | 7 | public class MobilePositionElementCreator implements ElementCreator { 8 | 9 | @Override 10 | public String create(Node current) { 11 | Node parent = current.getParent(); 12 | if (parent == null) { 13 | return ""; 14 | } 15 | int i = 1; 16 | for (Node child : parent.getChildren()) { 17 | if (child.getTag().equals(current.getTag())) { 18 | if (child.getOtherAttributes().get("index").equals(current.getOtherAttributes().get("index"))) { 19 | break; 20 | } else { 21 | i++; 22 | } 23 | } 24 | } 25 | return String.format("[%s]", i); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/MobileTagElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators; 2 | 3 | 4 | import com.epam.healenium.elementcreators.ElementCreator; 5 | import com.epam.healenium.treecomparing.Node; 6 | 7 | public class MobileTagElementCreator implements ElementCreator { 8 | 9 | @Override 10 | public String create(Node node) { 11 | return node.getTag(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/attribute/AbstractAttributeElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators.attribute; 2 | 3 | import com.epam.healenium.elementcreators.ElementCreator; 4 | import com.epam.healenium.treecomparing.Node; 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import java.util.Optional; 8 | 9 | public abstract class AbstractAttributeElementCreator implements ElementCreator { 10 | 11 | @Override 12 | public String create(Node node) { 13 | return Optional.ofNullable(node.getOtherAttributes().get(getFieldName())) 14 | .filter(StringUtils::isNotBlank) 15 | .map(a -> String.format("[@%s='%s']", getFieldName(), a)) 16 | .orElse(""); 17 | } 18 | 19 | protected abstract String getFieldName(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/attribute/ContentDescElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators.attribute; 2 | 3 | public class ContentDescElementCreator extends AbstractAttributeElementCreator { 4 | 5 | @Override 6 | protected String getFieldName() { 7 | return "content-desc"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/attribute/MobileIdElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators.attribute; 2 | 3 | public class MobileIdElementCreator extends AbstractAttributeElementCreator { 4 | 5 | @Override 6 | protected String getFieldName() { 7 | return "id"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/attribute/ResourceIdElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators.attribute; 2 | 3 | public class ResourceIdElementCreator extends AbstractAttributeElementCreator { 4 | 5 | @Override 6 | protected String getFieldName() { 7 | return "resource-id"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/elementcreators/attribute/TextElementCreator.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.elementcreators.attribute; 2 | 3 | public class TextElementCreator extends AbstractAttributeElementCreator { 4 | 5 | @Override 6 | protected String getFieldName() { 7 | return "text"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/handlers/proxy/MobileBaseHandler.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.handlers.proxy; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import org.openqa.selenium.By; 5 | 6 | import java.util.Map; 7 | import java.util.function.Function; 8 | 9 | public interface MobileBaseHandler { 10 | 11 | Map> MOBILE_METHOD_MAP = 12 | ImmutableMap.>builder() 13 | .put("findElementByClassName", By::className) 14 | .put("findElementsByClassName", By::className) 15 | .put("findElementByName", By::name) 16 | .put("findElementsByName", By::name) 17 | .put("findElementByTagName", By::tagName) 18 | .put("findElementsByTagName", By::tagName) 19 | .put("findElementByPartialLinkText", By::partialLinkText) 20 | .put("findElementsByPartialLinkText", By::partialLinkText) 21 | .put("findElementByLinkText", By::linkText) 22 | .put("findElementsByLinkText", By::linkText) 23 | .put("findElementByCssSelector", By::cssSelector) 24 | .put("findElementsByCssSelector", By::cssSelector) 25 | .put("findElementById", By::id) 26 | .put("findElementsById", By::id) 27 | .build(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/handlers/proxy/MobileSelfHealingProxyInvocationHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Healenium-appium Copyright (C) 2019 EPAM 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.epam.healenium.appium.handlers.proxy; 14 | 15 | import com.epam.healenium.PageAwareBy; 16 | import com.epam.healenium.SelfHealingEngine; 17 | import com.epam.healenium.appium.wrapper.ElementWrapper; 18 | import com.epam.healenium.handlers.proxy.BaseHandler; 19 | import javassist.util.proxy.MethodHandler; 20 | import lombok.extern.slf4j.Slf4j; 21 | import org.openqa.selenium.By; 22 | import org.openqa.selenium.WebDriver; 23 | import org.openqa.selenium.WebElement; 24 | 25 | import java.lang.reflect.Method; 26 | import java.util.List; 27 | import java.util.Optional; 28 | import java.util.stream.Collectors; 29 | 30 | @Slf4j 31 | public class MobileSelfHealingProxyInvocationHandler extends BaseHandler implements MethodHandler, MobileBaseHandler { 32 | 33 | public final static String PAGE_PREFIX = "page"; 34 | 35 | public MobileSelfHealingProxyInvocationHandler(SelfHealingEngine engine) { 36 | super(engine); 37 | } 38 | 39 | @Override 40 | public Object invoke(Object proxy, Method method, Method proceed, Object[] args) throws Throwable { 41 | switch (method.getName()) { 42 | case "findElement": 43 | WebElement element = findElement((By) args[0]); 44 | return engine.isProxy() ? element : wrap(element); 45 | case "findElements": 46 | List elements = findElements((By) args[0]); 47 | return engine.isProxy() ? elements : elements.stream().map(this::wrap).collect(Collectors.toList()); 48 | case "switchTo": 49 | WebDriver.TargetLocator switched = (WebDriver.TargetLocator) method.invoke(driver, args); 50 | ClassLoader loader = driver.getClass().getClassLoader(); 51 | return engine.isProxy() ? wrapTarget(switched, loader) : switched; 52 | default: 53 | By locator = MOBILE_METHOD_MAP.get(method.getName()).apply((String) args[0]); 54 | if (method.getName().contains("findElements")) { 55 | List elementsBy = findElements(locator); 56 | return engine.isProxy() ? elementsBy : elementsBy.stream().map(this::wrap).collect(Collectors.toList()); 57 | } else { 58 | WebElement el = findElement(locator); 59 | return engine.isProxy() ? el : wrap(el); 60 | } 61 | } 62 | } 63 | 64 | private Object wrap(WebElement element) { 65 | return Optional.ofNullable(element).map(it -> ElementWrapper.wrap(it, engine)).orElse(null); 66 | } 67 | 68 | @Override 69 | protected PageAwareBy awareBy(By by) { 70 | return (by instanceof PageAwareBy) ? (PageAwareBy) by : PageAwareBy.by(PAGE_PREFIX, by); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/handlers/proxy/MobileWebElementProxyHandler.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.handlers.proxy; 2 | 3 | import com.epam.healenium.SelfHealingEngine; 4 | import com.epam.healenium.appium.wrapper.ElementWrapper; 5 | import com.epam.healenium.handlers.proxy.WebElementProxyHandler; 6 | import javassist.util.proxy.MethodHandler; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.WebElement; 10 | 11 | import java.lang.reflect.Method; 12 | import java.util.List; 13 | import java.util.Optional; 14 | import java.util.stream.Collectors; 15 | 16 | @Slf4j 17 | public class MobileWebElementProxyHandler extends WebElementProxyHandler implements MethodHandler, MobileBaseHandler { 18 | 19 | public MobileWebElementProxyHandler(WebElement delegate, SelfHealingEngine engine) { 20 | super(delegate, engine); 21 | } 22 | 23 | @Override 24 | public Object invoke(Object o, Method method, Method method1, Object[] args) { 25 | switch (method.getName()) { 26 | case "findElement": 27 | return wrap(findElement((By) args[0])); 28 | case "findElements": 29 | List elements = findElements((By) args[0]); 30 | return elements.stream().map(this::wrap).collect(Collectors.toList()); 31 | default: 32 | By locator = MOBILE_METHOD_MAP.get(method.getName()).apply((String) args[0]); 33 | if (method.getName().contains("findElements")) { 34 | List elementsBy = findElements(locator); 35 | return elementsBy.stream().map(this::wrap).collect(Collectors.toList()); 36 | } else { 37 | return wrap(findElement(locator)); 38 | } 39 | } 40 | } 41 | 42 | private Object wrap(WebElement element) { 43 | return Optional.ofNullable(element).map(it -> ElementWrapper.wrap(it, engine)).orElse(null); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/service/MobileHealingService.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.service; 2 | 3 | import com.epam.healenium.appium.MobileSelectorComponent; 4 | import com.epam.healenium.model.Context; 5 | import com.epam.healenium.model.HealedElement; 6 | import com.epam.healenium.service.HealingService; 7 | import com.epam.healenium.treecomparing.Node; 8 | import com.epam.healenium.treecomparing.Scored; 9 | import com.typesafe.config.Config; 10 | import org.openqa.selenium.By; 11 | import org.openqa.selenium.WebDriver; 12 | import org.openqa.selenium.WebElement; 13 | import org.openqa.selenium.remote.RemoteWebElement; 14 | 15 | import java.util.ArrayList; 16 | import java.util.Collections; 17 | import java.util.EnumSet; 18 | import java.util.List; 19 | import java.util.Set; 20 | import java.util.stream.Collectors; 21 | 22 | public class MobileHealingService extends HealingService { 23 | 24 | private final List> mobileSelectorDetailLevels; 25 | 26 | private final static List> MOBILE_TEMP = new ArrayList>() {{ 27 | add(EnumSet.of(MobileSelectorComponent.RESOURCE_ID)); 28 | add(EnumSet.of(MobileSelectorComponent.MOBILE_ID)); 29 | add(EnumSet.of(MobileSelectorComponent.TEXT)); 30 | add(EnumSet.of(MobileSelectorComponent.CONTENT_DESC)); 31 | add(EnumSet.of(MobileSelectorComponent.MOBILE_TAG, MobileSelectorComponent.RESOURCE_ID, MobileSelectorComponent.MOBILE_ID, MobileSelectorComponent.CONTENT_DESC)); 32 | add(EnumSet.of(MobileSelectorComponent.MOBILE_PARENT, MobileSelectorComponent.MOBILE_TAG, MobileSelectorComponent.RESOURCE_ID, MobileSelectorComponent.MOBILE_ID, MobileSelectorComponent.CONTENT_DESC)); 33 | add(EnumSet.of(MobileSelectorComponent.MOBILE_PATH)); 34 | }}; 35 | 36 | public MobileHealingService(Config finalizedConfig, WebDriver driver) { 37 | super(finalizedConfig, driver); 38 | this.mobileSelectorDetailLevels = Collections.unmodifiableList(MOBILE_TEMP); 39 | } 40 | 41 | @Override 42 | protected HealedElement toLocator(Scored node, Context context) { 43 | for (Set detailLevel : mobileSelectorDetailLevels) { 44 | By locator = mobileConstruct(node.getValue(), detailLevel); 45 | if (locator == null) { 46 | continue; 47 | } 48 | List elements = driver.findElements(locator); 49 | if (elements.size() == 1 && !context.getElementIds().contains(((RemoteWebElement) elements.get(0)).getId())) { 50 | Scored byScored = new Scored<>(node.getScore(), locator); 51 | context.getElementIds().add(((RemoteWebElement) elements.get(0)).getId()); 52 | HealedElement healedElement = new HealedElement(); 53 | healedElement.setElement(elements.get(0)).setScored(byScored); 54 | return healedElement; 55 | } 56 | } 57 | return null; 58 | } 59 | 60 | private By mobileConstruct(Node node, Set detailLevel) { 61 | String xpath = detailLevel.stream() 62 | .map(component -> component.createComponent(node)) 63 | .collect(Collectors.joining()); 64 | if (!xpath.isEmpty()) { 65 | return xpath.startsWith("[@") 66 | ? By.xpath("//*".concat(xpath)) 67 | : By.xpath("//".concat(xpath)); 68 | } 69 | return null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/service/MobileNodeService.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.service; 2 | 3 | import com.epam.healenium.model.Context; 4 | import com.epam.healenium.service.NodeService; 5 | import com.epam.healenium.treecomparing.Node; 6 | import com.epam.healenium.treecomparing.NodeBuilder; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.jsoup.Jsoup; 10 | import org.jsoup.nodes.Attribute; 11 | import org.jsoup.nodes.Document; 12 | import org.jsoup.nodes.Element; 13 | import org.jsoup.parser.Parser; 14 | import org.openqa.selenium.WebDriver; 15 | import org.openqa.selenium.WebElement; 16 | 17 | import java.util.ArrayList; 18 | import java.util.Arrays; 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.Iterator; 22 | import java.util.LinkedList; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | @Slf4j 27 | public class MobileNodeService extends NodeService { 28 | private static final int ONE_ELEMENT = 1; 29 | private static final int THE_ONLY_ELEMENT = 0; 30 | 31 | @Override 32 | public List getNodePath(WebDriver driver, WebElement element, Context context) { 33 | return getHierarchyElements(driver, element); 34 | } 35 | 36 | private List getHierarchyElements(WebDriver driver, WebElement element) { 37 | String xmlString = driver.getPageSource(); 38 | 39 | Document doc = Jsoup.parse(xmlString, "", Parser.xmlParser()); 40 | Element currentElementInDoc = getElementFromDoc(doc, element); 41 | List list = new ArrayList<>(); 42 | 43 | while (currentElementInDoc.hasParent()) { 44 | Node currentNode = toNode(currentElementInDoc); 45 | list.add(currentNode); 46 | currentElementInDoc = currentElementInDoc.parent(); 47 | } 48 | Collections.reverse(list); 49 | return new LinkedList<>(list); 50 | } 51 | 52 | private Element getElementFromDoc(Document doc, WebElement webElement) { 53 | List paramsList = Arrays.asList("bounds", "resource-id", "class", "content-desc", "text", "checked", 54 | "enabled", "selected", "focused", "displayed", "type", "name", "value", "label", "visible", "accessible"); 55 | 56 | List tempElements = new ArrayList<>(doc.getAllElements()); 57 | 58 | if (tempElements.size() == ONE_ELEMENT) { 59 | return tempElements.get(THE_ONLY_ELEMENT); 60 | } 61 | 62 | Iterator it = paramsList.iterator(); 63 | while (it.hasNext()) { 64 | String nextParam = it.next(); 65 | String tempValue = webElementParamValue(nextParam, webElement); 66 | tempElements.removeIf(e -> !e.attributes().get(nextParam).equals(tempValue)); 67 | 68 | if (tempElements.size() == ONE_ELEMENT) { 69 | return tempElements.get(THE_ONLY_ELEMENT); 70 | } 71 | } 72 | return tempElements.get(THE_ONLY_ELEMENT); 73 | } 74 | 75 | private String webElementParamValue(String currentAttribute, WebElement webElement) { 76 | String temp = webElement.getAttribute(currentAttribute); 77 | return temp != null ? temp : ""; 78 | } 79 | 80 | private Node toNode(Element e) { 81 | Map otherAttributes = new HashMap<>(); 82 | List list = e.attributes().asList(); 83 | list.forEach(attr -> otherAttributes.put(attr.getKey(), attr.getValue())); 84 | 85 | String index = e.attributes().getIgnoreCase("index"); 86 | return new NodeBuilder() 87 | .setId(e.attributes().getIgnoreCase("resource-id")) 88 | .setTag(e.attributes().getIgnoreCase("class")) 89 | .setClasses(Collections.singleton(e.attributes().getIgnoreCase("content-desc"))) 90 | .setIndex(StringUtils.isEmpty(index) ? 0 : Integer.parseInt(index)) 91 | .setMobileAttributes(otherAttributes) 92 | .build(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/utils/MobileStackTraceReader.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.utils; 2 | 3 | import com.epam.healenium.appium.handlers.proxy.MobileSelfHealingProxyInvocationHandler; 4 | import com.epam.healenium.handlers.proxy.BaseHandler; 5 | import com.epam.healenium.utils.StackTraceReader; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class MobileStackTraceReader extends StackTraceReader { 11 | 12 | @Override 13 | public List getProxyHandlerNames() { 14 | return Arrays.asList(MobileSelfHealingProxyInvocationHandler.class.getName(), BaseHandler.class.getName()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/wrapper/DriverWrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Healenium-appium Copyright (C) 2019 EPAM 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.epam.healenium.appium.wrapper; 14 | 15 | 16 | import com.epam.healenium.SelfHealingEngine; 17 | import com.epam.healenium.appium.MobileSelfHealingEngine; 18 | import com.epam.healenium.appium.utils.MobileStackTraceReader; 19 | import com.epam.healenium.appium.handlers.proxy.MobileSelfHealingProxyInvocationHandler; 20 | import com.epam.healenium.appium.service.MobileHealingService; 21 | import com.epam.healenium.appium.service.MobileNodeService; 22 | import com.epam.healenium.client.RestClient; 23 | import com.epam.healenium.mapper.HealeniumMapper; 24 | import com.typesafe.config.Config; 25 | import com.typesafe.config.ConfigFactory; 26 | import com.typesafe.config.ConfigValueFactory; 27 | import io.appium.java_client.AppiumDriver; 28 | import java.net.URL; 29 | import javassist.util.proxy.ProxyFactory; 30 | import lombok.extern.slf4j.Slf4j; 31 | import org.openqa.selenium.Capabilities; 32 | 33 | /** 34 | *

A wrapper for the android driver provided by appium. 35 | * locators that indicate that an element is a subject to healing.

36 | *

Overrides logic for MobileDriver.findElement* methods

37 | */ 38 | @Slf4j 39 | @SuppressWarnings("unchecked") 40 | public final class DriverWrapper { 41 | 42 | /** 43 | * Don't use wrapper to create SelfHealingDriver for Appium. 44 | * 45 | * Use remote driver with connection to hlm-proxy 46 | */ 47 | @Deprecated 48 | public static T wrap(T delegate) { 49 | return wrap(delegate, null); 50 | } 51 | 52 | /** 53 | * Don't use wrapper to create SelfHealingDriver for Appium. 54 | * 55 | * Use remote driver with connection to hlm-proxy 56 | */ 57 | @Deprecated 58 | public static T wrap(T delegate, Config config) { 59 | if(config == null){ 60 | config = ConfigFactory.systemProperties() 61 | .withValue("proxy", ConfigValueFactory.fromAnyRef(true)) 62 | .withFallback(ConfigFactory.load()); 63 | } 64 | SelfHealingEngine engine = new MobileSelfHealingEngine(delegate, config); 65 | engine.setClient(new RestClient(engine.getConfig())); 66 | engine.setNodeService(new MobileNodeService()); 67 | engine.setHealingService(new MobileHealingService(engine.getConfig(), delegate)); 68 | engine.getClient().setMapper(new HealeniumMapper(new MobileStackTraceReader())); 69 | return create(engine); 70 | } 71 | 72 | /** 73 | * Don't use wrapper to create SelfHealingDriver for Appium. 74 | * 75 | * Use remote driver with connection to hlm-proxy 76 | */ 77 | @Deprecated 78 | public static T create(SelfHealingEngine engine){ 79 | T origin = (T) engine.getWebDriver(); 80 | try{ 81 | ProxyFactory factory = new ProxyFactory(); 82 | factory.setSuperclass(origin.getClass()); 83 | factory.setFilter(method -> method.getName().startsWith("findElement") 84 | || method.getName().equalsIgnoreCase("switchTo")); 85 | return (T) factory.create( 86 | new Class[]{URL.class, Capabilities.class}, 87 | new Object[]{origin.getRemoteAddress(), origin.getCapabilities()}, 88 | new MobileSelfHealingProxyInvocationHandler(engine) 89 | ); 90 | } catch (Exception ex){ 91 | log.error("Failed to create wrapper! Exception: {0}", ex); 92 | return origin; 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/epam/healenium/appium/wrapper/ElementWrapper.java: -------------------------------------------------------------------------------- 1 | package com.epam.healenium.appium.wrapper; 2 | 3 | import com.epam.healenium.SelfHealingEngine; 4 | import com.epam.healenium.appium.handlers.proxy.MobileWebElementProxyHandler; 5 | import javassist.util.proxy.ProxyFactory; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.openqa.selenium.WebElement; 8 | 9 | @Slf4j 10 | public class ElementWrapper { 11 | 12 | public static T wrap(T delegate, SelfHealingEngine engine) { 13 | try { 14 | ProxyFactory factory = new ProxyFactory(); 15 | factory.setSuperclass(delegate.getClass()); 16 | factory.setFilter(method -> method.getName().startsWith("findElement")); 17 | 18 | return (T) factory.create( 19 | new Class[]{}, 20 | new Object[]{}, 21 | new MobileWebElementProxyHandler(delegate, engine) 22 | ); 23 | } catch (Exception ex) { 24 | log.error("Failed to create wrapper!", ex); 25 | return delegate; 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | recovery-tries = 1 2 | score-cap = .6 3 | basePath = "target/selenium" 4 | reportPath = "target/reports" 5 | screenshotPath = "target/screenshots/" 6 | heal-enabled = true 7 | backend-integration = true 8 | hlm.server.url = "http://localhost:7878" 9 | hlm.imitator.url = "http://localhost:8000" --------------------------------------------------------------------------------