The self healing automation framework - Healenium Updated Dec2023


Healenium 

Architecture 


Healenium Official Github Link : 

    https://github.com/healenium


And this complete project E2E available at my repo as well

    https://github.com/madanankurmalviya/HealeniumTestOnJavaSeMvnProject.git


Youtube demo for complete setup : 

    https://www.youtube.com/watch?v=Xg_sqE4VUyU


1. Healenium - Web from Maven Reporsitory:

<dependency>

    <groupId>com.epam.healenium</groupId>

    <artifactId>healenium-web</artifactId>

    <version>3.4.8</version>

</dependency>


2. Check for Selenium-Java latest dependencies:

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->

<dependency>

    <groupId>org.seleniumhq.selenium</groupId>

    <artifactId>selenium-java</artifactId>

    <version>4.16.1</version>

</dependency>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
</properties>

3. Set the below BLUE highlighted files under your Maven Project


by using these curl :

cd infra.  and ot download this file into your project use this command:

curl https://raw.githubusercontent.com/healenium/healenium-example-maven/master/infra/docker-compose.yml -o docker-compose.yml    

Create /db/sql folder on the same level in your project. Add init.sql file into ./db/sql/init.sql folder in your project via command:                                                                                                                                      

curl https://raw.githubusercontent.com/healenium/healenium-client/master/example/init.sql -o init.sql

Verify that images healenium/hlm-backend:3.4.8 (or latest version ) and postgres:11-alpine and healenium/hlm-selector-imitator:1.2 are up and running

3.1 Under Docker-Compose.yaml 


Check if we have all below properties:

version: "3.8"
services:

postgres-db:
image: postgres:11-alpine
container_name: postgres-db
ports:
- "5432:5432"
volumes:
- ./db/sql/init.sql:/docker-entrypoint-initdb.d/init.sql
restart: always
environment:
- POSTGRES_DB=healenium
- POSTGRES_USER=healenium_user
- POSTGRES_PASSWORD=YDk2nmNs4s9aCP6K
networks:
- healenium

healenium:
image: healenium/hlm-backend:3.4.1
ports:
- "7878:7878"
links:
- postgres-db
environment:
- SPRING_POSTGRES_DB=healenium
- SPRING_POSTGRES_SCHEMA=healenium
- SPRING_POSTGRES_USER=healenium_user
- SPRING_POSTGRES_PASSWORD=YDk2nmNs4s9aCP6K
- SPRING_POSTGRES_DB_HOST=postgres-db
- KEY_SELECTOR_URL=false
- COLLECT_METRICS=true
- FIND_ELEMENTS_AUTO_HEALING=false
- HLM_LOG_LEVEL=info
networks:
- healenium

selector-imitator:
image: healenium/hlm-selector-imitator:1.2
container_name: selector-imitator
restart: on-failure
ports:
- "8000:8000"
networks:
- healenium

networks:
healenium:


3.2: init.sql

CREATE SCHEMA healenium AUTHORIZATION healenium_user;
GRANT USAGE ON SCHEMA healenium TO healenium_user;


 4. Healenium properties file under src>test>>resources>healenium.properties :

recovery-tries=1
score-cap=.6
heal-enabled=true
serverHost=localhost
serverPort=7878
imitatePort=8000

Where :
recovery-tries — a list of potential healed locators

heal-enabled — Toggle the flag to enable or disable healing. ture/false

score-cap — score value to enable healing with a predefined probability of match (0.6 means that healing will be performed for newly healed locators where the probability of match with target one is greater than 60%).

serverHost — ip where hlm-backend instance is installed

serverPort — port on which hlm-backend instance is installed : 7878 ( default)

imitatePort — port on which imitate instance is installed :8000 (default)

5. Init driver instance of SelfHealingDriver

static protected SelfHealingDriver driver ;
WebDriver delegate = new ChromeDriver();
driver = SelfHealingDriver.create(delegate);

Declare the delegate and then create self-healing driver
As mentioned below in Test.java class:

package com.epam.healenium.tests;
import com.epam.healenium.SelfHealingDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.net.MalformedURLException;

public class GooglePageTest {

public static void main (String []args) throws MalformedURLException {

ChromeOptions options =
new ChromeOptions();
WebDriver delegate = new ChromeDriver(options);
SelfHealingDriver driver = SelfHealingDriver.create((WebDriver) delegate)
;

driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[@class='gLFyf']")).sendKeys("Hello");
driver.findElement(By.xpath("//a[text()='About']")).click();
driver.quit();
}
}

On Terminal run the below command under /infra folder :
docker-compose up -d
also check if all images are run properly by : docker container ps


Also we can check from docker enginer UI desktop app : 


First run the script E2E witj correct xpath successfully so that we can find and store all the correct locators at hlm-backend as below at port localhots:7878




And now we are ready to de-bug the existing script by changing the elements at DOM level while running the script so that we can find the auto-healing exist as shown below in the screen shot.






Comments

  1. New to Selenium and Java.... Tried the same setup, docker images are up and running.. and When I ran with the same code I am getting the below error, please help me to resolve it..

    Exception in thread "main" java.lang.NoSuchMethodError: 'java.util.function.Supplier org.openqa.selenium.remote.http.HttpResponse.getContent()'
    at com.epam.healenium.client.RestClient.getElements(RestClient.java:141)
    at com.epam.healenium.SelfHealingEngine.loadStoredSelectors(SelfHealingEngine.java:169)
    at com.epam.healenium.SelfHealingDriver.callInitActions(SelfHealingDriver.java:65)
    at com.epam.healenium.SelfHealingDriver.create(SelfHealingDriver.java:42)
    at com.selfheal.Healenium.AutoHealing.main(AutoHealing.java:20)

    ReplyDelete

Post a Comment

Popular posts from this blog

Heleanium - Web without using Docker