healenium / healenium-appium

Self-healing library for Appium-based tests
Apache License 2.0
26 stars 8 forks source link

DriverWrapper invoking the app two times. #51

Closed anim2k19 closed 1 year ago

anim2k19 commented 2 years ago

Describe the problem

My app is invoking two times after using wrap function like this in beforeTest: -

@BeforeTest(alwaysRun = true)
    public void beforeTest() throws IOException {
        driver = getDriver("emulator-5554", "Android", "11") ;
        driver = DriverWrapper.wrap(driver);
        signIn = new SignInHelper(driver);
    }

getDriver function :-

public static AppiumDriver<MobileElement> getDriver(String deviceName, String platformName,
            String platformVersion) {
        try {
            if (runOnBrowserStack) {
                setBrowserStackAndroidCapabilities(deviceName, platformName, platformVersion);
                driver = new AppiumDriver<MobileElement>(new URL("https://" + browserStackUserName + ":"
                        + browserStackAccessKey + "@hub-cloud.browserstack.com/wd/hub"), cap);
                driver.manage().deleteAllCookies();
                driver.manage().timeouts().implicitlyWait(Time.TIME_OUT_IN_SECONDS, TimeUnit.SECONDS);
            } else {
                setLocalAndroidCapabilities(deviceName, platformName, platformVersion);
                driver = new AppiumDriver<MobileElement>(service.getUrl(), cap);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return driver;
    }

SignInHelper :-

public class SignInHelper extends BaseClass {
    private AppiumDriver<MobileElement> driver;

    public SignInHelper(AppiumDriver<MobileElement> driver) {
        this.driver = driver;
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }
}

Healenium Backend version

3.2.2

Healenium Appium version

1.18.0

Selenium version

No response

Platform

No response

Logs appeared during using Healenium

Jun 22, 2022 5:13:32 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Jun 22, 2022 5:13:42 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C

Additional context

No response

neofreko commented 2 years ago

CMIIW, this is caused by a proxy class healenium use to wrap the driver. Instantiating the proxy means instantiating another Appium driver which of course create another session. Unfortunately, Appium Java client cannot attach itself to existing session. There's two options here:

  1. Re-work the wrapper. But this goes all the way to healenium.
  2. Add "attach to existing session" to Appium Java client.
Alex-Reif commented 1 year ago

Hi @anim2k19 , @neofreko , issue was fixed at rev. 1.4.0