Giter VIP home page Giter VIP logo

osandadeshan / healenium-demo Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 3.0 263 KB

This is a demo project to demonstrate automatic locator healing capability in Healenium using Java, Maven, and the Page Object Pattern.

Home Page: https://medium.com/automationmaster/no-more-test-flakiness-from-selenium-locator-changes-c25a96d0736d

Java 41.41% CSS 0.16% JavaScript 2.97% HTML 55.46%
healenium selenium selenium-webdriver auto-healing locators page-object-model java maven allure-report

healenium-demo's Introduction

Healenium Demo

What is Healenium?

Healenium is an open-source test framework extension that enhances the stability of selenium-based test cases. It automatically handles the updated web and mobile elements. In practical scenarios, Web and mobile applications are updated constantly in every sprint and that may caused to locator changes. Healenium uses a type of machine-learning algorithm to analyze the current page state for changes, handle NoSuchElement test failures, and fix broken tests at runtime by replacing the failed locator with a new value that matches the best and performs an action with the new element successfully. After the test run, Healenium provides detailed reporting with the fixed locators and screenshots. In addition, it supports advanced features like a parallel test run, remote test run, iFrames, actions, selenide integration.

All of this decreases the time and effort required to write reliable Selenium tests, as well as the amount of test cases that fail due to test defects.

How Does It Work?

Healenium has a client component that connects to test automation frameworks. It has a Tree-comparison dependence in it. An algorithm with self-healing capabilities that examines the current DOM state and generates a new CSS locator by searching for the best subsequence in the current state. It also implements Selenium WebDriver and modifies the findElement method, triggering the Tree-comparing process and initiating self-healing if the NoSuchElement exception is caught.

Healenium's backend is a server that uses a PostgreSQL database to execute interactions between the client and the database, which records old and new locator values as well as relevant information such as DOM page, method name, class name, screenshots, and so on.

There are also Maven and Gradle plugins that generate healing results reports and interact with the backend to obtain information about the healing elements.

Healenium also offers an IntelliJ IDEA plugin for updating the codebase with new location values.

Demo Project

This demo project incorporates Healenium and uses Java with Maven and the Page Object Pattern.

Pre-requisites

How to run this Demo project?

Starting the Healenium Backend

  1. First, make sure Docker is up and running.

  2. Open a Command Prompt or Terminal in the "healenium" directory and execute:

docker-compose up -d

image

  1. Wait for docker to download the images and finish the setup.

  2. Using the Docker Desktop UI, check that the Healenium backend and database containers are running.

image

Or you can execute docker ps and check that.

Integrating Healenium in tests

It's as simple as writing one line of code to integrate Healenium into your framework. Wrapping the WebDriver in the new SelfHealingDriver is all that's required.

But, before that you have to import,

import com.epam.healenium.SelfHealingDriver;

Example code:

@BeforeMethod
public void before() {
    WebDriver delegate = new ChromeDriver(); // declare delegate
    driver = SelfHealingDriver.create(delegate); // create Self-healing driver
    driver.manage().window().maximize();
    driver.navigate().to("http://automationpractice.com/");
}

Running the tests

Run the tests with the proper locators at least once using mvn clean test. After that, we make the following changes to "index.html" in the "src/main/resources/checkout" folder. (You can change any locators as you wish)

  • id="address" to id="address1"
  • id="cc-name" to id="card-name"
  • id="cc-number" to id="card-number"
  • id="cc-expiration" to id="card-expiration"
  • id="cc-cvv" to id="card-cvv"
  • Continue to checkout to Checkout

Normally, this would cause the locators to malfunction because they rely on exact matches. The test will pass because the self-healing driver is used, and it will heal the locators during runtime.

image

The locator has been fixed, and the action has been appropriately done, as indicated by the red boxes.

Let's say you want to fine-tune Healenium to include a score cap or recovery tries. In such scenario, create a file called "healenium.properties" and place it in the test resources ("src/test/resources") directory. The following is the file's content:

recovery-tries = 1
score-cap = 0.5
heal-enabled = true
serverHost = localhost
serverPort = 7878

recovery-tries - The number of times the algorithm will try to discover a matched locator.

score-cap - The minimum matching score required for the detected locator to be accepted (50% is represented by the number 0.5).

heal-enabled - A toggle switch that turns healing on or off. True and false are the accepted values.

serverHost - The URL of the Docker Container server that we established while setting up the backend.

serverPort - The above-mentioned server's port

Run the tests using mvn clean test to generate a new report from the command line. A link to the report generated in the console will appear after a successful test run.

image

When you open the link in a browser, you'll get a list of all the locators that have been fixed, along with screenshots of the page where the locators have been fixed. On the right side, there's a switch to see if the locator has been properly resolved with the correct one.

image

This boilerplate also includes an Allure report as an added feature. After running mvn clean test, run allure serve target/allure-results to generate the Allure report.

By installing the Healenium IDE plugin, you can enable automatic locator updating feature into the IntelliJ IDEA. You can right-click on the locators you want to correct and select Healing Results. You'll see a little window with a list of fixed locators to choose from, along with their corresponding score.

image

healenium-demo's People

Contributors

osandadeshan avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

healenium-demo's Issues

Auto healing not working and healenium web report is empty

Hi @osandadeshan
I have cloned this healenium demo project and followed the steps mentioned in the READ.me I am able to run give script successfully with proper locators for first time. Later I changed locator value for couple of fields and ran the suite again then script failed but healing did not work and healenium web report is also empty what could reason for not healing and empty report.

Please find the attached logs for both success and failure.

`C:\Workspace\Healenium\HealeniumProject\healenium-demo>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] --------< com.healenium.demo:healenium-selenium-maven-example >---------
[INFO] Building healenium-selenium-maven-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ healenium-selenium-maven-example ---
[INFO] Deleting C:\Workspace\Healenium\HealeniumProject\healenium-demo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ healenium-selenium-maven-example ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ healenium-selenium-maven-example ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 4 source files to C:\Workspace\Healenium\HealeniumProject\healenium-demo\target\classes
[INFO]
[INFO] --- hlm-report-mvn:1.1:initReport (hlmReport) @ healenium-selenium-maven-example ---
[INFO] Healenium server Port = 7878
[INFO] Healenium server Host = localhost
Jan 22, 2023 11:31:35 PM com.epam.healenium.client.HealingClient makePost
INFO: External service call completes with success: a20e77b8-4505-4080-858f-383a70653c83
[INFO] sessionKey= a20e77b8-4505-4080-858f-383a70653c83
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ healenium-selenium-maven-example ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ healenium-selenium-maven-example ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to C:\Workspace\Healenium\HealeniumProject\healenium-demo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ healenium-selenium-maven-example ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 109.0.5414.74 (resolved driver for Chrome 109)
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\sangameshwar.balur.cache\selenium\chromedriv
er\win32\109.0.5414.74\chromedriver.exe
Starting ChromeDriver 109.0.5414.74 (e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414@{#1172}) on port 34166
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jan 22, 2023 11:31:42 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.475 s - in TestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- hlm-report-mvn:1.1:buildReport (hlmReportB) @ healenium-selenium-maven-example ---
Jan 22, 2023 11:31:48 PM com.epam.healenium.client.HealingClient makePost
INFO: External service call completes with success: healenium/report/a20e77b8-4505-4080-858f-383a70653c83
[INFO] Report available at http://localhost:7878/healenium/report/a20e77b8-4505-4080-858f-383a70653c83
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.300 s
[INFO] Finished at: 2023-01-22T23:31:48-06:00
[INFO] ------------------------------------------------------------------------

C:\Workspace\Healenium\HealeniumProject\healenium-demo>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] --------< com.healenium.demo:healenium-selenium-maven-example >---------
[INFO] Building healenium-selenium-maven-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ healenium-selenium-maven-example ---
[INFO] Deleting C:\Workspace\Healenium\HealeniumProject\healenium-demo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ healenium-selenium-maven-example ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ healenium-selenium-maven-example ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 4 source files to C:\Workspace\Healenium\HealeniumProject\healenium-demo\target\classes
[INFO]
[INFO] --- hlm-report-mvn:1.1:initReport (hlmReport) @ healenium-selenium-maven-example ---
[INFO] Healenium server Port = 7878
[INFO] Healenium server Host = localhost
Jan 22, 2023 11:33:26 PM com.epam.healenium.client.HealingClient makePost
INFO: External service call completes with success: 2e0e3f14-b45c-4a8e-baf9-858eb8030d03
[INFO] sessionKey= 2e0e3f14-b45c-4a8e-baf9-858eb8030d03
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ healenium-selenium-maven-example ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ healenium-selenium-maven-example ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to C:\Workspace\Healenium\HealeniumProject\healenium-demo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ healenium-selenium-maven-example ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 109.0.5414.74 (resolved driver for Chrome 109)
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\sangameshwar.balur.cache\selenium\chromedriv
er\win32\109.0.5414.74\chromedriver.exe
Starting ChromeDriver 109.0.5414.74 (e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414@{#1172}) on port 19253
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jan 22, 2023 11:33:33 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[main] WARN com.epam.healenium.handlers.proxy.BaseHandler - Failed to find an element using locator By.xpath: //button[text()='Checkout1']
Reason: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()='Checkout1']"}
(Session info: chrome=109.0.5414.75)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'USAU4-38R5453', ip: '10.222.19.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_241'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.75, chrome: {chromedriverVersion: 109.0.5414.74 (e7c57036
04da..., userDataDir: C:\Users\SANGAM1.BAL\AppDa...}, goog:chromeOptions: {debuggerAddress: localhost:4031}, javascriptEnabled: true, networkConne
ctionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractabi
lity: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: tr
ue, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 33653d7d8ef2225c25bb1934e0f6ddcf
*** Element info: {Using=xpath, value=//button[text()='Checkout1']}
Trying to heal...
[main] WARN com.epam.healenium.service.impl.HealingServiceImpl - New element locators have not been found
[main] WARN com.epam.healenium.service.impl.HealingServiceImpl - Score property=0.5 is bigger than healing's locator score
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 9.717 s <<< FAILURE! - in TestSuite
[ERROR] HealeniumTest.testCheckoutWithAllFields Time elapsed: 2.427 s <<< FAILURE!
org.openqa.selenium.NoSuchElementException:
no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()='Checkout1']"}
(Session info: chrome=109.0.5414.75)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'USAU4-38R5453', ip: '10.222.19.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_241'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.75, chrome: {chromedriverVersion: 109.0.5414.74 (e7c57036
04da..., userDataDir: C:\Users\SANGAM
1.BAL\AppDa...}, goog:chromeOptions: {debuggerAddress: localhost:4031}, javascriptEnabled: true, networkConne
ctionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractabi
lity: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: tr
ue, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 33653d7d8ef2225c25bb1934e0f6ddcf
*** Element info: {Using=xpath, value=//button[text()='Checkout1']}
at HealeniumTest.testCheckoutWithAllFields(HealeniumTest.java:33)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] HealeniumTest.testCheckoutWithAllFields:33 » NoSuchElement no such element: Un...
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.836 s
[INFO] Finished at: 2023-01-22T23:33:39-06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project healenium-selenium-maven-exam
ple: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Workspace\Healenium\HealeniumProject\healenium-demo\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

C:\Workspace\Healenium\HealeniumProject\healenium-demo>allure serve target/allure-results
Generating report to temp directory...
Report successfully generated to C:\Users\SANGAM~1.BAL\AppData\Local\Temp\6060326051033404066\allure-report
Starting web server...
2023-01-22 23:36:10.404:INFO::main: Logging initialized @3266ms to org.eclipse.jetty.util.log.StdErrLog
Server started at http://10.222.19.96:4155/. Press <Ctrl+C> to exit
^CTerminate batch job (Y/N)? y
`

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.