Skip to content

Commit

Permalink
Merge pull request #178 from healenium/feature/EPMHLM-204
Browse files Browse the repository at this point in the history
Feature/epmhlm 204
  • Loading branch information
Alex-Reif authored Mar 14, 2022
2 parents 34560dd + 032f8c3 commit 6d4b157
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 69 deletions.
65 changes: 22 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.epam.healenium</groupId>
<artifactId>healenium-web</artifactId>
<version>3.2.1</version>
<version>3.2.3</version>
<packaging>jar</packaging>
<name>healenium-web</name>
<description>healenium web client</description>
Expand Down Expand Up @@ -66,24 +66,24 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<typesafe.version>1.3.4</typesafe.version>
<maven.apache>3.8.4</maven.apache>
<typesafe.version>1.4.2</typesafe.version>
<treecomparing.version>0.4.10</treecomparing.version>
<selenium.version>4.1.1</selenium.version>
<jacksondatabind.version>2.10.0</jacksondatabind.version>
<commonslang3.version>3.11</commonslang3.version>
<commonscodec.version>1.12</commonscodec.version>
<slf4jsimple.version>1.7.30</slf4jsimple.version>
<annotations.version>18.0.0</annotations.version>
<selenium.version>4.1.0</selenium.version>
<jacksondatabind.version>2.13.1</jacksondatabind.version>
<commonslang3.version>3.12.0</commonslang3.version>
<commonscodec.version>1.15</commonscodec.version>
<okhttp3.version>4.9.3</okhttp3.version>
<annotations.version>23.0.0</annotations.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<lombok.version>1.18.20</lombok.version>
<streamex.version>0.7.2</streamex.version>
<lombok.version>1.18.22</lombok.version>
<streamex.version>0.8.1</streamex.version>
<jettyserver.version>9.4.41.v20210516</jettyserver.version>
<hamcrestcore.version>2.2</hamcrestcore.version>
<selenide.version>6.1.2</selenide.version>
<testcontainersjunit.version>1.16.2</testcontainersjunit.version>
<junit.version>5.7.1</junit.version>
<webdrivermanager.version>4.2.0</webdrivermanager.version>
<okhttp3.version>4.9.3</okhttp3.version>
<selenide.version>6.1.1</selenide.version>
<testcontainersjunit.version>1.16.3</testcontainersjunit.version>
<junit.version>5.8.2</junit.version>
<webdrivermanager.version>5.1.0</webdrivermanager.version>
</properties>

<profiles>
Expand Down Expand Up @@ -127,7 +127,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -141,7 +141,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<version>3.3.2</version>
<configuration>
<source>8</source>
</configuration>
Expand All @@ -158,7 +158,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<version>3.2.2</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
Expand Down Expand Up @@ -193,7 +193,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.0</version>
<configuration>
<source>8</source>
<target>8</target>
Expand All @@ -211,83 +211,68 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.11</version>
<version>${maven.apache}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.8.1</version>
<version>${maven.apache}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.1</version>
<version>${maven.apache}</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>${typesafe.version}</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.epam.healenium/tree-comparing -->
<dependency>
<groupId>com.epam.healenium</groupId>
<artifactId>tree-comparing</artifactId>
<version>${treecomparing.version}</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jacksondatabind.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commonslang3.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commonscodec.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp3.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4jsimple.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${annotations.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>one.util</groupId>
Expand All @@ -298,37 +283,31 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyserver.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrestcore.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>${selenide.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainersjunit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/epam/healenium/SelfHealingDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
*/
package com.epam.healenium;

import com.epam.healenium.client.RestClient;
import com.epam.healenium.handlers.proxy.SelfHealingProxyInvocationHandler;
import com.epam.healenium.service.HealingService;
import com.epam.healenium.service.NodeService;
import com.epam.healenium.utils.ProxyFactory;
import com.typesafe.config.Config;
import org.openqa.selenium.WebDriver;
Expand All @@ -31,11 +34,22 @@ public interface SelfHealingDriver extends WebDriver {
* @return SelfHealingDriver instance
*/
static SelfHealingDriver create(WebDriver delegate) {
return create(new SelfHealingEngine(delegate));
SelfHealingEngine selfHealingEngine = new SelfHealingEngine(delegate);
setEngineFields(delegate, selfHealingEngine);
return create(selfHealingEngine);
}

static SelfHealingDriver create(WebDriver delegate, Config config) {
return create(new SelfHealingEngine(delegate, config));
SelfHealingEngine selfHealingEngine = new SelfHealingEngine(delegate, config);
setEngineFields(delegate, selfHealingEngine);
return create(selfHealingEngine);
}

static void setEngineFields(WebDriver delegate, SelfHealingEngine selfHealingEngine) {
Config finalizedConfig = selfHealingEngine.getConfig();
selfHealingEngine.setClient(new RestClient(finalizedConfig));
selfHealingEngine.setNodeService(new NodeService(delegate));
selfHealingEngine.setHealingService(new HealingService(finalizedConfig, delegate));
}

static SelfHealingDriver create(SelfHealingEngine engine) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/epam/healenium/SelfHealingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class SelfHealingEngine {
private final Config config;
private final WebDriver webDriver;
private final double scoreCap;
private final boolean isProxy;

private RestClient client;
private NodeService nodeService;
Expand All @@ -67,10 +68,7 @@ public SelfHealingEngine(@NotNull WebDriver delegate, @NotNull Config config) {
this.webDriver = delegate;
this.config = finalizedConfig;
this.scoreCap = finalizedConfig.getDouble("score-cap");

this.client = new RestClient(finalizedConfig);
this.nodeService = new NodeService(delegate);
this.healingService = new HealingService(finalizedConfig, delegate);
this.isProxy = finalizedConfig.getBoolean("proxy");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/epam/healenium/client/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class RestClient {
public RestClient(Config config) {
objectMapper = initMapper();
baseUrl = "http://" + config.getString("serverHost") + ":" + config.getInt("serverPort") + "/healenium";
imitateUrl = "http://" + config.getString("serverHost") + ":" + config.getInt("imitatePort") + "/imitate";
imitateUrl = "http://" + config.getString("imitateHost") + ":" + config.getInt("imitatePort") + "/imitate";
sessionKey = config.hasPath("sessionKey") ? config.getString("sessionKey") : "";
mapper = new HealeniumMapper(new StackTraceReader());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface ProcessorHandler {
/**
* validate data before run 'execute' method. And skip whole chain in case fail validate
* @return
* validating result
*/
boolean validate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.epam.healenium.PageAwareBy;
import com.epam.healenium.SelfHealingEngine;
import com.epam.healenium.config.ProcessorConfig;
import com.epam.healenium.mapper.HealeniumMapper;
import com.epam.healenium.model.Context;
import com.epam.healenium.processor.BaseProcessor;
import com.epam.healenium.utils.ProxyFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
switch (method.getName()) {
case "findElement":
WebElement element = findElement((By) args[0]);
if (engine.isProxy()) {
return element;
}
return Optional.ofNullable(element).map(it -> wrapElement(it, loader)).orElse(null);
case "findElements":
List<WebElement> elements = findElements((By) args[0]);
if (engine.isProxy()) {
return elements;
}
return elements.stream().map(it -> wrapElement(it, loader)).collect(Collectors.toList());
case "getCurrentEngine":
return engine;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/epam/healenium/mapper/HealeniumMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.epam.healenium.treecomparing.Node;
import com.epam.healenium.treecomparing.Scored;
import com.epam.healenium.utils.StackTraceReader;
import com.epam.healenium.utils.StackUtils;
import lombok.Data;
import org.openqa.selenium.By;

import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.epam.healenium.SelfHealingEngine;
import com.epam.healenium.client.RestClient;
import com.epam.healenium.handlers.processor.ProcessorHandler;
import com.epam.healenium.mapper.HealeniumMapper;
import com.epam.healenium.model.Context;
import com.epam.healenium.service.HealingService;
import lombok.Setter;
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/epam/healenium/utils/StackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,17 @@
*/
package com.epam.healenium.utils;

import com.epam.healenium.handlers.proxy.SelfHealingProxyInvocationHandler;
import com.epam.healenium.handlers.proxy.WebElementProxyHandler;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import lombok.NoArgsConstructor;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import one.util.streamex.StreamEx;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.openqa.selenium.By;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
Expand Down Expand Up @@ -107,9 +97,6 @@ private Optional<StackTraceElement> findAnnotatedInTrace(StackTraceElement[] ele
.findFirst();
}

/**
* @return
*/
public Predicate<StackTraceElement> redundantPackages() {
return value -> {
Stream<String> skippingPackageStream = Stream.of("java.base", "sun.reflect", "java.lang", "org.gradle",
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ heal-enabled = true
serverHost = localhost
serverPort = 7878
imitatePort = 8000
backlight-healing = true
backlight-healing = true
imitateHost = localhost
proxy = false
2 changes: 1 addition & 1 deletion src/test/resources/compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
- healenium

healenium:
image: healenium/hlm-backend:3.2.0
image: healenium/hlm-backend:3.2.1
ports:
- "7878:7878"
links:
Expand Down

0 comments on commit 6d4b157

Please sign in to comment.