0
\$\begingroup\$

I am trying to implement page objects with Page factory using TestNg and selenium. Please advice improvements in it.

Classes:

LoginPageObjects extends LoginPageLocators {
   private WebDriver driver;

   public LoginPageObjects(WebDriver driver)
   this.driver=driver;

   public HomePageObjects loginFunction(){
      // some code here
      return PageFactory.initElements(HomePageObjects.class);
   }
}


HomePageObjects extends HomePageLocators{
   private WebDriver driver;

   public HomePageObjects(WebDriver driver)
   this.driver=driver;

   public void verifyTitle(){
       // some code here
   }
}

public class LoginPageTest{

   LoginPageObjects loginPage=new LoginPageObjects();

   public void LoginPageTest(){
      HomePageObjects homepage=loginPage.loginFunction();
      Assert.assertTrue("HomePageTitle",homepage.verifyTitle());
   }
}

TestNGTests.class

public void firstTest() {
   LoginPageTest test=new LoginPageTest();
   test.loginPageTest;
   //other test code
}

`Testng.xml` calls the `TestngTests.class`
`Locators` class contains the `PageFactory` objects
\$\endgroup\$
  • 2
    \$\begingroup\$ In order to get a proper review, you should consider posting all your code (if it is not huge, which does not seem the case). \$\endgroup\$ – Alexei Feb 20 '16 at 14:43
2
\$\begingroup\$

Is LoginPageObjects also a LoginPageLocators?

LoginPageObjects extends LoginPageLocators

seems unlikely. Hence I would not make page object class extend locator class. I usually keep locator on the same page object class for sake of better cohesion. You may come across locators which are applicable for multiple page object classed but in any case page object class is not a page locator class.

public void verifyTitle(){

By and large convention has been to not keep verification/assertion in the page class. Only exception is the page object constructor which can be used to check is control is on write page.

Adding on to what Alexei already mentioned. Adding complete code example would help others to help you. Not everyone works with selenium/TestNG and would find it difficult to get context without complete code example.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.