jeudi 26 octobre 2017

Method that returns two classes in java

I have two classes:

public class UnoLoginPageUi {
    public final Input username = new Input("id=username");
    public final Input password = new Input("id=password");
    public final Button loginButton = new Button("name=login");
}

and

public class DuoLoginPageUi {
    public final Input username = new Input("id=usernameField");
    public final Input password = new Input("id=passwordField");
    public final Button loginButton = new Button("id=submitButton");
}

and in one common class I want to make something like that:

public void loginUsingUsernameAndPassword(String username, String password, String pageType) {
    getUi(pageType).username.waitForToBeDisplayed();
    getUi(pageType).username.setValue(username);
    getUi(pageType).password.setValue(password);
    getUi(pageType).loginButton.click();
}

where getUi() is a method that gas argument pageType (which is UNO or DUO).

private Class getUi(String pageType) {
    if (pageType.equals("UNO")) {
        return new DuoLoginPageUi();
    }
    else if (pageType.equals("DUO")) {
        return new UnoLoginPageUi;
    }
    return null;
}

However it doesn't work as this method need to in type of this two pages with selectors - how to deal with that ?

Aucun commentaire:

Enregistrer un commentaire