healenium / healenium-web

Self-healing library for Selenium Web-based tests
Apache License 2.0
170 stars 40 forks source link

[BUG]: Class cast Exception #210

Closed raghunadh10 closed 1 year ago

raghunadh10 commented 2 years ago

Describe the bug

Hi team, we have tried to implement healenium in our custom framework for maven project .In this custom framework , we have implemented our own driver class which implements the original WebDriver class . the issue we have come across is , on the method which involves the execute javascript method (executeScript(args)) is not working after converting the normal webdriver to healenium web driver . The error it is throwing is " class cast exception "

How to reproduce the issue

Example ---

public class customDriver implements WebDriver{

    public void createDriver(){ 

    //creating the driver and sets the webdriver  
}
   public Object executeJS(String script, Object... args) {
        return ((RemoteWebDriver)getDriver()).executeScript(script, args);
    } 

   public void useHealenium() {
        WebDriver healDriver=SelfHealingDriver.create(getCurrentWebDriver());
        drivers.set(getCurrentIndex(),healDriver);
    }
}

customDriver driver = new customDriver() 

driver.createDriver()    //creating one webdriver 
driver.useHealenium()    //calling this method to convert current driver to healdriver
driver.executeJs("console.log("hello"))  //getting class cast exception at this line

Logs appeared during using Healenium

java.lang.ClassCastException: class jdk.proxy2.$Proxy12 cannot be cast to class org.openqa.selenium.remote.RemoteWebDriver (jdk.proxy2.$Proxy12 
is in module jdk.proxy2 of loader 'app'; org.openqa.selenium.remote.RemoteWebDriver is in unnamed module of loader 'app')

Expected behavior

No response

Actual behavior

No response

Healenium Web version

3.3.0

Healenium Backend version

3.2.3

Selenium version

4.1.1

Platform

Java

Properties file

recovery-tries = 1 score-cap = 0.5 heal-enabled = true hlm.server.url = http://localhost:7878 hlm.imitator.url = http://localhost:8000 reportPath=build/reports screenshotPath=build/screenshots/

Additional context

No response

Alex-Reif commented 2 years ago

Hi @raghunadh10 , First off, Healenium doesn't handle js scripts (executeScript method), it means there is no healing during call this one. So, if you want to use executeScript method of SelfHealing instance anyway, you should get delegate driver: ((RemoteWebDriver) hlmDriver.getDelegate()).executeScript()

raghunadh10 commented 1 year ago

Hi @Alex-Reif . its fine now . thanks for the help .