mercredi 22 avril 2015

PageFactory. How to separate page elements and steps

I'm trying to use PageFactory methods and would like to separate classes with elements and methods. For instance I have a class with page elements:

public class LoginPageElements extends AbstractPage  {

@FindBy(id = "rwOAuthUserName")
public WebElement login;

@FindBy(id = "rwOAuthPassword")
public WebElement password;

@FindBy(id = "rwOAuthLogin")
public WebElement submit;


public LoginPageElements (WebDriver driver){
    super(driver);
}

and a class with page methods:

public class LoginPageSteps {

private LoginPageElements elements;

@Step
public void fillLogin(String value){
    elements.login.clear();
    elements.login.sendKeys(value);
}

@Step
public void fillPassword(String value){
    elements.password.clear();
    elements.password.sendKeys(value);
}

@Step
public void submitTheForm(String value) {
    elements.submit.click();
}

On previous page I cause the method for visiting my login page and initializing all the required elements:

    public LoginPageElements clickLoginButton(){
        loginButton.click();
        return PageFactory.initElements(driver, LoginPageElements.class);
}

But the thing is that now I can't write the test like:

@BeforeTest
public void testSetUp(){
    driver = DriverManager.getDriverFor("FF");
    CNBLoginPage onCNBStartPage = PageFactory.
         initElements(driver, CNBLoginPage.class);
    onCNBStartPage.
            clickLoginButton().
            fillLogin(login).

due to the fact that clickLoginButton() returns the LoginPageElements class, but fillLogin() is in LoginPageSteps class.

Could you please tell me how to return elements and classes properly here?

Aucun commentaire:

Enregistrer un commentaire