jeudi 10 août 2017

setup page object model pattern logic issue for cucumber with selenium

Following is my setup. I have an abstract page class

public abstract class Page {
protected IOSDriver driver;
 public Page(IOSDriver driver){
     this.driver = driver;
 }

}

There are other pages which extend this page class, so that we can pass the same instance of the driver.

public class ProfilePage extends Page{
public ProfilePage(IOSDriver driver) {
    super(driver);
}

public HomePage clickProfile(String sProfileName) throws InterruptedException {
    driver.findElement(MobileBy.AccessibilityId(sProfileName)).click();
    return new HomePage(driver);
}

So when using cucumber / gherkin and the following method is executed:

@When("^I select profile \"([^\"]*)\"$")
public void i_select_profile(String sProfileName) throws Throwable {
    System.out.println("@When(\"^select profile \\\"([^\\\"]*)\\\"$\")" + sProfileName);
    homePage = profilePage.clickProfile(sProfileName);
}

The object homePage has been initialised and it works fine.

Now the problem is at a scenario which I have a page with multiple tiles E.g Maps, Events, Parks etc. these are all different pages

@Then("^I can click on \"([^\"]*)\"$")
public void i_can_click_on(String sTileName) throws Throwable {
    //parksPage = homePage.clickTile(sTileName);
    //mapsPage  = homePage.clickTile(sTileName);

It is given that I can create:

parksPage = homePage.clickTileParks(sTileName);

and

mapsPage    = homePage.clickTileMaps(sTileName);

But that does not seem the best way to handle this. Any suggestions?

Aucun commentaire:

Enregistrer un commentaire