0

In my application, a record page has a 'Back' button. The page can be accessed from either a home page or a list of records page; and the back button should return to the previous page. What should the back method return?

One way is to pass a parameter to RecordPageObject so that it tracks what it should return when back is pressed. class RecordPageObject {

  T back(Class<T> returnPageObjecType) {
    click("Back"); // some function to click on Back button.
    if (comingFromHome) { 
      return (T) PageObjectFactory.createHomePageObject();
    } else {
      return (T) PageObjectFactory.createListPageObject();
    }
  }

}

In this case, the calling code will be:

// calling code
HomePageObject currentPage =  RecordPageObject.back(HomePageObject.class);

Option 2 is to only do click("Back") in back() function and write calling code as follows:

RecordPageObject rec = .... // something to land on RecordPage
rec.back();
HomePageObject currentPage =  PageObjectFactory.createHomePageObject();

I guess, yet another option will be to pass the PageObject's type as a generic parameter to the RecordPageObject<T> and store it as a member. This will save us from passing that value in back() function.

Asad Iqbal
  • 3,241
  • 4
  • 32
  • 52
  • 1
    The simple answer is: make the calling function keep track of it. The more complicated answer lies in inheritance and `interface`. – SiKing Oct 16 '14 at 21:06

1 Answers1

4

I would suggest you to use the first approach that you have used.

HomePageObject currentPage =  RecordPageObject.back(HomePageObject.class);

This clearly explains the flow of your application and this is exactly you should be doing. The second approach that you have followed has one drawback. Your creating the page object, however the back should be doing that task! (As that is supposed to be functioning such in your UI)

Ant's
  • 13,545
  • 27
  • 98
  • 148