Harsh Nigam
Harsh Nigam

Reputation: 495

While implementing the page object modelling using page factory with selenium webdriver, which is the good approach out of the two?

  1. Calling public static <T> T initElements(WebDriver driver, java.lang.Class<T> pageClassToProxy) within each method which navigates to the target webpage class page ?

Or

  1. Calling public static <T> T initElements(WebDriver driver, java.lang.Class<T> pageClassToProxy) in the constructor of the webpage class?

Upvotes: 0

Views: 157

Answers (1)

Kim Homann
Kim Homann

Reputation: 3248

The way it's intended to be is to place your call to PageFactory.InitElements() in the constructor of the class representing the web page. If you have classes representing a certain object on the page (like header or footer, that occur on several pages), you can call it there, too. The object doesn't have to be a webpage.

Upvotes: 1

Related Questions