Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.54 KB

annotation-post-construct.md

File metadata and controls

58 lines (41 loc) · 1.54 KB

Home

@PostConstruct

This annotation can be added to methods of Page or PageFragment subclasses. Every annotated method will be invoked after an instance of this subclass was initialized. These methods should be used to verify that the correct page is displayed or the fragment has 'working' state. The order in which multiple annotated methods are invoked is not deterministic.

Each method should work on it's own and not depend on another method being invoked!

Since these methods are invoked using reflection, it is not possible to have method arguments!

As an alternative for @PostConstruct the @PostConstructMustBe annotation can be used on page fragment returning methods. For more about that see @PostConstructMustBe.

Example for page:

public interface FooPage extends Page {
 
    @IdentifyUsing("#foo")
    FooWidget widget();
 
    @PostConstruct
    void assertThatWidgetIsVisible () {
        assertThat(widget).is(visible());
    }
 
    ...
 
}

Example for page fragment:

public interface FooWidget extends PageFragment {
 
    @IdentifyUsing("#one")
    TextField fieldOne();
    
    @IdentifyUsing("#two")
    TextField fieldTwo();
 
    @PostConstruct
    void assertThatTextFieldsAreVisible () {
        assertThat(fieldOne).is(visible());
        assertThat(fieldTwo).is(visible());
    }
 
    ...
 
}

Linked Documentation