Implement PageObjects using TestNg in selenium 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
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.