Your problem is that when you create a HomePage
it creates a new LoginPage
and whenever you create a LoginPage
you create a HomePage
. This will clearly result in a never ending (until the stack overflows) cycle.
To solve the problem, do not create the pages during construction. Make setter
s for them
private static class AppiumBasePage {
public AppiumBasePage() {
}
}
public class HomePage extends AppiumBasePage {
LoginPage loginPage;
public void setLoginPage(LoginPage loginPage) {
this.loginPage = loginPage;
}
}
public class LoginPage extends AppiumBasePage {
HomePage homePage;
public void setHomePage(HomePage homePage) {
this.homePage = homePage;
}
}
public void test() {
LoginPage login = new LoginPage();
HomePage home = new HomePage();
login.setHomePage(home);
home.setLoginPage(login);
}
Alternatively you could remove the interdependency entirely by introducing a new class to maintain that.
public class HomePage extends AppiumBasePage {
}
public class LoginPage extends AppiumBasePage {
}
class Pages {
AppiumBasePage login = new LoginPage();
AppiumBasePage home = new HomePage();
}
It all depends on what you need to achieve.
1
solved Circular Dependency in classes and StackOverflow Error