Before writing your functional tests using PageObjects you surely want to test your PageObjects itself, so you are sure to have a solid base for your functional tests. Writing such tests is quite simple. All you have to do is

So your test would look something like this:

@Test
public void testSomePagePo {
  SomePage somePage = factory.createPage(SomePage.class);
  somePage.open();
  somePage.header(); // no assert needed, cause locator throw Exceptions if element is not found
  somePage.header().homeLink();
  somePage.header().naviLink1();
  // ...
  somePage.someElement();
  somePage.someElement().someInnerElement();
  // ...
  somePage.elementWithParameter("a", 42);
  somePage.elementWithParameter("a", 42).myLink();
  somePage.elementWithParameter("a", 42).someButton();
  // ...
}

Here comes Pockito

Writing all this code is nasty. There should be an automated way of creating that tests. And ... here it is:

@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  Pockito
     .conf()
     .runTest(somePage);
}

What pockito does is

Using parameters

When using parameters in your locator-methods Pockito doesn't know how to call that methods and needs some helpo from you

@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  Pockito
     .conf()
     .parameter(somePage.elementWithParameter("a", 42))
     .runTest(somePage);
}

parameter(somePage.elementWithParameter("a", 42)) tells Pockito to use the parameters "a" and 42 to call the method elementWithParameter. All the children of that methods will be iterated and tested automatically again.

Ignoring locators

In some cases you may want Pockito not to test all the elements in a PageObject cause you know that not all elements are visible he page (f.e. a Header which shows exclusive a login- or logout-link)

@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  Pockito
     .conf()
     .ignore(somePage.header().logout())
     .runTest(somePage);
}
ignore(somePage.header().logout()) tells Pockito not to test the method somePage.header().logout() and all of its children.

Open a page

Pockito needs a PageAccessor with no parameters to open a page. If you can't provide that, you have to open that page on your own

@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  somePage.open("Username", "Password");
  Pockito
     .conf()
     .runTest(somePage);
}
@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  Pockito.open(somePage, "/somePage.jsp?here=follow&some=parameters");
  Pockito
     .conf()
     .runTest(somePage);
}

Assertions

Pockito will only check if your locators match to any element on the page, but it won't (and can't) check if the right element is reached. To test that, you may want to write some custom assertions to assure the right element reached.

@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  Pockito
     .conf()
     .runTest(somePage);

  Assert.assertEquals("42", somePage.someElement().text());
}

After running runTest(somePage) you may use your Pockito-created PageObject to access your page and do some assertions

WATCH OUT
@Test public void testSomePagePo {
  SomePage somePage = Pockito.pock(SomePage.class);
  Assert.assertEquals("42", somePage.someElement().text());
  Pockito
     .conf()
     .runTest(somePage);
}

This will fail because before runTest your Page-Object is in configuration-mode and can't be used to access locators.