Class ScenarioContext


  • public class ScenarioContext
    extends java.lang.Object
    Represents the context of a Cucumber scenario during test execution. This class holds all the necessary information about a scenario, including its parent rule (if any), the actual scenario or scenario outline node, the associated test case, and references to Report Portal test items.

    The context is used by the ScenarioReporter to track and report the execution of scenarios, steps, and hooks to Report Portal.

    • Constructor Summary

      Constructors 
      Constructor Description
      ScenarioContext​(RuleContext ruleNode, io.cucumber.plugin.event.Node.Scenario scenarioNode)
      Creates a new scenario context for a regular scenario.
      ScenarioContext​(RuleContext ruleNode, io.cucumber.plugin.event.Node.ScenarioOutline scenarioOutlineNode)
      Creates a new scenario context for a scenario outline.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      io.reactivex.Maybe<java.lang.String> getHookId()
      Returns the Report Portal ID for the current hook.
      java.util.Optional<HookSuite> getHookSuite()
      Returns the hook suite for this scenario.
      io.reactivex.Maybe<java.lang.String> getId()
      Returns the Report Portal ID for this scenario.
      int getLine()
      Returns the line number of the scenario or scenario outline in the feature file.
      java.util.Optional<Step> getPreviousStep()
      Returns the previous step that was executed.
      java.util.Optional<RuleContext> getRule()
      Returns the parent rule context, if this scenario is defined within a rule.
      java.util.Optional<Step> getStep()
      Returns the current step.
      java.util.Optional<io.cucumber.plugin.event.TestCase> getTestCase()
      Returns the Cucumber test case associated with this scenario context, if available.
      void setHookId​(io.reactivex.Maybe<java.lang.String> hookStepId)
      Sets the Report Portal ID for the current hook.
      void setHookSuite​(HookSuite hookSuite)
      Sets the hook suite for this scenario.
      void setId​(io.reactivex.Maybe<java.lang.String> id)
      Sets the Report Portal ID for this scenario.
      void setPreviousStep​(Step previousStep)
      Sets the previous step.
      void setStep​(Step step)
      Sets the current step.
      void setTestCase​(io.cucumber.plugin.event.TestCase testCase)
      Sets the Cucumber test case for this scenario context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScenarioContext

        public ScenarioContext​(@Nullable
                               RuleContext ruleNode,
                               @Nonnull
                               io.cucumber.plugin.event.Node.Scenario scenarioNode)
        Creates a new scenario context for a regular scenario.
        Parameters:
        ruleNode - the parent rule context, may be null
        scenarioNode - the Cucumber scenario node
      • ScenarioContext

        public ScenarioContext​(@Nullable
                               RuleContext ruleNode,
                               @Nonnull
                               io.cucumber.plugin.event.Node.ScenarioOutline scenarioOutlineNode)
        Creates a new scenario context for a scenario outline.
        Parameters:
        ruleNode - the parent rule context, may be null
        scenarioOutlineNode - the Cucumber scenario outline node
    • Method Detail

      • getLine

        public int getLine()
        Returns the line number of the scenario or scenario outline in the feature file.
        Returns:
        the line number
      • getTestCase

        @Nonnull
        public java.util.Optional<io.cucumber.plugin.event.TestCase> getTestCase()
        Returns the Cucumber test case associated with this scenario context, if available.
        Returns:
        an Optional containing the test case, or empty if not set
      • setTestCase

        public void setTestCase​(@Nullable
                                io.cucumber.plugin.event.TestCase testCase)
        Sets the Cucumber test case for this scenario context.
        Parameters:
        testCase - the test case to associate with this context
      • getRule

        @Nonnull
        public java.util.Optional<RuleContext> getRule()
        Returns the parent rule context, if this scenario is defined within a rule.
        Returns:
        an Optional containing the rule context, or empty if not within a rule
      • getId

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> getId()
        Returns the Report Portal ID for this scenario.
        Returns:
        the Report Portal ID
      • setId

        public void setId​(@Nonnull
                          io.reactivex.Maybe<java.lang.String> id)
        Sets the Report Portal ID for this scenario.
        Parameters:
        id - the Report Portal ID
      • getHookSuite

        @Nonnull
        public java.util.Optional<HookSuite> getHookSuite()
        Returns the hook suite for this scenario. The hook suite represents a collection of hooks of the same type (before, after, etc.).
        Returns:
        an Optional containing the hook suite, or empty if not set
      • setHookSuite

        public void setHookSuite​(@Nullable
                                 HookSuite hookSuite)
        Sets the hook suite for this scenario.
        Parameters:
        hookSuite - the hook suite to set
      • setHookId

        public void setHookId​(@Nonnull
                              io.reactivex.Maybe<java.lang.String> hookStepId)
        Sets the Report Portal ID for the current hook.
        Parameters:
        hookStepId - the Report Portal ID for the hook
      • getHookId

        @Nonnull
        public io.reactivex.Maybe<java.lang.String> getHookId()
        Returns the Report Portal ID for the current hook.
        Returns:
        the hook ID
      • setStep

        public void setStep​(@Nullable
                            Step step)
        Sets the current step.
        Parameters:
        step - the step object
      • getStep

        @Nonnull
        public java.util.Optional<Step> getStep()
        Returns the current step.
        Returns:
        the current step
      • setPreviousStep

        public void setPreviousStep​(@Nullable
                                    Step previousStep)
        Sets the previous step.
        Parameters:
        previousStep - the step object that was previously executed
      • getPreviousStep

        @Nonnull
        public java.util.Optional<Step> getPreviousStep()
        Returns the previous step that was executed.
        Returns:
        an Optional containing the previous step, or empty if not set