java - Which is the better way to create instance of PageObject? -


i know below better option creating instance of pageobject class(ex: loginpage):-

1) create instance of pageobject class in tests , steps (wherever required)?

loginpage loginpage = pagefactory.initelements(webdriver, loginpage.class); 

(or)

2) create class static method return instance requested pageobject class. in method, check if instance null before creating new instance requested class?

loginpage loginpage = pageutil.getpageobject("login"); 

please advise.

there multiple ways it. create baseclass() , instantiate pagefactory.initelements(driver, this); there. see gist. also, public repository here

import org.openqa.selenium.webdriver; import org.openqa.selenium.support.pagefactory;  /** * created saifur on 2/14/2015. */ public class baseclass {  //global driver instance. webdriver driver;  //super constructor public baseclass(webdriver _driver)  {    //assigning driver instance globally.    driver = _driver;     /*instantiating elements since super class    , inherited each , every page object */     pagefactory.initelements(driver, this);  } } 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

amazon web services - Installing MobileFirst 7.0 server on AWS -

Non Unique Username with ASP.Net Identity 2.0 -