Assume I'm in page: I clicked on "Create book" link, takes me to Book Creator page and when I click on start Book creator, it returns me Main page
Assume I'm in some search result page: I clicked on "Create book" link, takes me to Book Creator page and when I click on start Book creator, it returns me search result page
you can test this scenario in link Wikipedia page
Same in code:
public class CommonItem {
Class<?> Calle
CommonItem(Class<?> Calle) {
this.calle = calle;
}
public PageX clickLink() {
return new PageX(Class<?> Calle);
}
}
public class PageA {
// WebDriver driver;
CommonItem ci;
PageA() {
ci = new CommonItem(PageA.class);
}
public PageX commonItemClick() {
PageX axp = ci.clickLink();
return axp;
}
}
public class PageB {
CommonItem ci;
PageB() {
ci = new CommonItem(PageB.class);
}
public PageX commonItemClick() {
PageX bxp = ci.clickLink();
return bxp;
}
}
public class PageX {
Class<?> calle;
PageX(Class<?> calle){
this.calle = calle;
}
public void someLink() {
// Click some Link here
// return pageA or PageB (depends on which page called this method, How to determine? )
return calle;
}
}
Update-1: I've implemented suggestion above. Now I've a test method which calls pageX.someLink() method, returns PageA or PageB,syntax would be
PageX xp = pageA.commonItemClick();
Class<?> caller = xp.someLink();
// how to access method of page A via caller variable ?
From web point of view you may try executing script "window.history.go(-1)" on click of any link or button.
Regarding the java code, the class CommonItem can have a constructor that takes a parameter as to who created it, which can later be used to determine the back-page.