I am practising POM and Page Object factory. I would like to learn good practices in instantiating the pages.
till now I am Instantiating the pages from test class (e.g. TC_01_Register.java) using the below statement, I am not passing driver object to page class
OCHomePage ochome = PageFactory.initElements(wdriver,OCHomePage.class);
another way I was thinking is, creating the class object where Page class receives the constructor and instantiate the page factory in constructor itself
OCHomePage ochome = new OCHomePage(wdriver);
OCHomePage class (code snippet)
public OCHomePage {
OCHomePage (WebDriver wdriver){
PageFactory.initElements(wdriver,this.class)
}
@findby... // code continues ..
}
please suggest me if any other best ways available or the practices you follow..