You might find that a certain text exists more than once on a page, but only one of the occurrences has to be tested. This requires you to narrow the search to a section of a page. The syntax is simple:
// Reducing the validation to a page region: .restrictedTo(PageRegion) // The following validations are limited to the regions.
The following example shows the definition and the usage of a page region:
@Test public void hasTextOnFirstPageInPageRegion() throws Exception { String filename = "documentUnderTest.pdf"; int leftX = 17; // in millimeter int upperY = 45; int width = 60; int height = 9; PageRegion pageRegion = new PageRegion(leftX, upperY, width, height); AssertThat.document(filename) .restrictedTo(FIRST_PAGE) .restrictedTo(pageRegion) .hasText() .startingWith("Content") .containing("on first") .endingWith("page.") ; }
When comparing text in page areas, all the test methods are available which are available when comparing text on entire pages. These methods are described in section 13.4: “Comparing Text”.
A page region can also be used when testing images.