java - Selenium PageFactory: initelements once per class? -


this more of java question selenium, since new java don't know answer. writing selenium tests using page object model. have pages in 1 class, , tests in another. however, trying execute pagefactory.initelements once per test class don't have add line in each test (in class, anyways, want this:

import com.company.pages.loginpage  public class logintests {      loginpage login = pagefactory.initelements(driver, loginpage.class );      @test     public void test1() {         login.method();     }      @test     public void test2() {         login.methodtwo();     } } 

but keep getting nullpointerexception on object defined in loginpage class. tells me page never initialized. since relatively new java, don't know how initialize it. help!

try this:

loginpage login;  @before public void beforetest() {     login = pagefactory.initelements(driver, loginpage.class ); } 

according this:

annotating public void method @before causes method run before test method.

this in cutting down verbosity of tests.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -