I don't understand why the error "non-static method getLoginPage() cannot be referenced from a static context" here!? There is nothing static here! Seems trivial but I am not sure what I'm missing.
EDIT: I understand that by instantiating TestFramework I can get rid of the error but as recommended, I'm trying to avoid instantiating objects in my unit tests and pass the object creation to my framework if needed. On the other hand making getLoginPage() in TestFramework static, creates a whole bunch of similar errors in my TestFramework class!
Class Tests.java:
public class Tests {
@Test
public void User_Can_Login(){
String username = "Jake";
String password = "Jake";
TestFramework.getLoginPage().Login(username, password);
assertTrue(TestFramework.getLoginPage().CheckIfLoggedIn(username));
}
Class TestFramework.Java:
public class TestFramework {
private LoginPage loginPage;
public LoginPage getLoginPage() {
loginPage = new LoginPage();
PageFactory.initElements(Browser.getDriver(), loginPage);
return loginPage;
}
public class LoginPage {
String Url = "http://localhost:8080";
String welcomeMsg = "Welcome";
public void Login(String username, String password) {
Browser.Goto(Url);
Browser.Input(username,password);
Browser.Submit();
}
public boolean CheckIfLoggedIn(String user){
return Browser.getTextByxpath("/html/body/header/div/p").contains(welcomeMsg + " " + user);
}
}
getLoginPage()method is not static. So you cant call likeTestFramework.getLoginPage(). You need to create objectnew TestFramework().getLoginPage();