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.