Class Steps

  • All Implemented Interfaces:
    CandidateSteps

    public class Steps
    extends AbstractCandidateSteps

    Default implementation of CandidateSteps which provides the step candidates that match the steps being run.

    To provide your step candidate methods, you can:

    • pass in the steps instance type and the steps factory used to instantiate the instance if any candidate steps are matched (lazy "has-a" relationship)
    • pass in the steps instance, instantiated regardless of whether the candidate steps are matched (eager "has-a" relationship)
    • extend the Steps class, in which case the instance is the extended Steps class itself ("is-a" relationship)
    The "has-a" design model, in which the steps instance is passed in, is strongly recommended over the "is-a" model as it does not have tie-ins in the Steps class implementation.

    You can define the methods that should be run by annotating them with @Given, @When or @Then, and providing as a value for each annotation a pattern matches the textual step. The value is interpreted by the StepPatternParser, which by default is a RegexPrefixCapturingPatternParser that interprets the words starting with '$' as parameters.

    For instance, you could define a method as:

     @When("I log in as $username with password: $password")
     public void logIn(String username, String password) { //... }
     
     
    and this would match the step:
     When I log in as Liz with password: Pa55word
     

    When the step is performed, the parameters matched will be passed to the method, so in this case the effect will be to invoke:

     logIn("Liz", "Pa55word");
     

    The Configuration can be used to provide customize the StepCandidates that are created, e.g. providing a step monitor or creating them in "dry run" mode.

    • Constructor Detail

      • Steps

        public Steps()
        Creates Steps with default configuration for a class extending this instance and containing the candidate step methods
      • Steps

        public Steps​(Configuration configuration)
        Creates Steps with given custom configuration for a class extending this instance and containing the candidate step methods
        Parameters:
        configuration - the Configuration
      • Steps

        public Steps​(Configuration configuration,
                     Object instance)
        Creates Steps with given custom configuration and a steps instance containing the candidate step methods
        Parameters:
        configuration - the Configuration
        instance - the steps instance
      • Steps

        public Steps​(Configuration configuration,
                     Class<?> type,
                     InjectableStepsFactory stepsFactory)
        Creates Steps with given custom configuration and a steps instance type containing the candidate step methods. The steps instance is created using the steps instance factory provided.
        Parameters:
        configuration - the Configuration
        type - the steps instance type
        stepsFactory - the InjectableStepsFactory
    • Method Detail

      • type

        public Class<?> type()
      • instance

        public Object instance()
      • listCandidates

        public List<StepCandidate> listCandidates()
        Description copied from interface: CandidateSteps
        Returns the step candidates that can be matched
        Returns:
        The list of step candidates
      • listBeforeStories

        public List<BeforeOrAfterStep> listBeforeStories()
        Description copied from interface: CandidateSteps
        Returns the before stories steps
        Returns:
        The list of the before stories steps
      • listAfterStories

        public List<BeforeOrAfterStep> listAfterStories()
        Description copied from interface: CandidateSteps
        Returns the after stories steps
        Returns:
        The list of the after stories steps
      • listBeforeStory

        public List<BeforeOrAfterStep> listBeforeStory​(boolean givenStory)
        Description copied from interface: CandidateSteps
        Returns the before story steps, based on the given story status
        Parameters:
        givenStory - the boolean flag denoting if it's a given story
        Returns:
        The list of the before story steps
      • listAfterStory

        public List<BeforeOrAfterStep> listAfterStory​(boolean givenStory)
        Description copied from interface: CandidateSteps
        Returns the after story steps, based on the given story status
        Parameters:
        givenStory - the boolean flag denoting if it's a given story
        Returns:
        The list of the after story steps