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"
--------------------------------------------------------------------------------