Class BaseStepListener

java.lang.Object
net.thucydides.core.steps.BaseStepListener
All Implemented Interfaces:
StepListener, StepPublisher

public class BaseStepListener
extends java.lang.Object
implements StepListener, StepPublisher
Observes the test run and stores test run details for later reporting. Observations are recorded in an TestOutcome object. This includes recording the names and results of each test, and taking and storing screenshots at strategic points during the tests.
  • Constructor Details

    • BaseStepListener

      public BaseStepListener​(java.io.File outputDirectory)
    • BaseStepListener

      public BaseStepListener​(java.io.File outputDirectory, com.google.inject.Injector injector)
    • BaseStepListener

      public BaseStepListener​(java.lang.Class<? extends org.openqa.selenium.WebDriver> driverClass, java.io.File outputDirectory)
      Create a step listener with a given web driver type.
      Parameters:
      driverClass - a driver of this type will be used
      outputDirectory - reports and screenshots are generated here
    • BaseStepListener

      public BaseStepListener​(java.lang.Class<? extends org.openqa.selenium.WebDriver> driverClass, java.io.File outputDirectory, Configuration configuration)
    • BaseStepListener

      public BaseStepListener​(java.io.File outputDirectory, WebdriverManager webdriverManager)
    • BaseStepListener

      public BaseStepListener​(java.io.File outputDirectory, Pages pages)
      Create a step listener using the driver from a given page factory. If the pages factory is null, a new driver will be created based on the default system values.
      Parameters:
      outputDirectory - reports and screenshots are generated here
      pages - a pages factory.
  • Method Details

    • setEventBus

      public void setEventBus​(StepEventBus eventBus)
    • getEventBus

      public StepEventBus getEventBus()
    • cloneCurrentStep

      public java.util.Optional<TestStep> cloneCurrentStep()
    • getAnnotatedResult

      public java.util.Optional<TestResult> getAnnotatedResult()
    • setAllStepsTo

      public void setAllStepsTo​(TestResult result)
    • overrideResultTo

      public void overrideResultTo​(TestResult result)
    • recordManualTestResult

      public void recordManualTestResult​(TestResult result, java.util.Optional<java.lang.String> lastTestedVersion, java.lang.Boolean isUpToDate, java.util.Optional<java.lang.String> testEvidence)
    • exceptionExpected

      public void exceptionExpected​(java.lang.Class<? extends java.lang.Throwable> expected)
    • mergeLast

      public BaseStepListener.StepMerger mergeLast​(int maxStepsToMerge)
    • getStepCount

      public int getStepCount()
    • getRunningStepCount

      public int getRunningStepCount()
    • updateOverallResults

      public void updateOverallResults()
    • getPhotographer

      public Photographer getPhotographer()
    • cancelPreviousTest

      public void cancelPreviousTest()
    • lastTestPassedAfterRetries

      public void lastTestPassedAfterRetries​(int attemptNum, java.util.List<java.lang.String> failureMessages, TestFailureCause testfailureCause)
    • currentStepIsAPrecondition

      public void currentStepIsAPrecondition()
    • updateExampleLineNumber

      public void updateExampleLineNumber​(int lineNumber)
    • screenshots

      protected ScreenshotPermission screenshots()
    • getProxyFactory

      protected WebdriverProxyFactory getProxyFactory()
    • getCurrentTestOutcome

      public TestOutcome getCurrentTestOutcome()
    • isAvailable

      public boolean isAvailable()
    • latestTestOutcome

      public java.util.Optional<TestOutcome> latestTestOutcome()
    • getClock

      protected SystemClock getClock()
    • testSuiteStarted

      public void testSuiteStarted​(java.lang.Class<?> startedTestSuite)
      A test suite (containing a series of tests) starts.
      Specified by:
      testSuiteStarted in interface StepListener
      Parameters:
      startedTestSuite - the class implementing the test suite (e.g. a JUnit test case)
    • testSuiteStarted

      public void testSuiteStarted​(Story story)
      Specified by:
      testSuiteStarted in interface StepListener
    • testSuiteRunning

      public boolean testSuiteRunning()
    • addIssuesToCurrentStory

      public void addIssuesToCurrentStory​(java.util.List<java.lang.String> issues)
    • addTagsToCurrentStory

      public void addTagsToCurrentStory​(java.util.List<TestTag> tags)
    • testSuiteFinished

      public void testSuiteFinished()
      Specified by:
      testSuiteFinished in interface StepListener
    • testStarted

      public void testStarted​(java.lang.String testMethod)
      An individual test starts.
      Specified by:
      testStarted in interface StepListener
      Parameters:
      testMethod - the name of the test method in the test suite class.
    • testStarted

      public void testStarted​(java.lang.String testMethod, java.lang.String id)
      Specified by:
      testStarted in interface StepListener
    • updateCurrentStepTitle

      public BaseStepListener.StepMutator updateCurrentStepTitle​(java.lang.String updatedStepTitle)
    • updateCurrentStepFailureCause

      public void updateCurrentStepFailureCause​(java.lang.Throwable failure)
    • testFinished

      public void testFinished​(TestOutcome outcome)
      Specified by:
      testFinished in interface StepListener
    • testFinished

      public void testFinished​(TestOutcome outcome, boolean inDataDrivenTest)
      A test has finished.
      Specified by:
      testFinished in interface StepListener
      Parameters:
      outcome - the result of the test that just finished.
    • testRetried

      public void testRetried()
      Specified by:
      testRetried in interface StepListener
    • stepStarted

      public void stepStarted​(ExecutedStepDescription description)
      A step within a test is called. This step might be nested in another step, in which case the original step becomes a group of steps.
      Specified by:
      stepStarted in interface StepListener
      Parameters:
      description - the description of the test that is about to be run
    • skippedStepStarted

      public void skippedStepStarted​(ExecutedStepDescription description)
      Specified by:
      skippedStepStarted in interface StepListener
    • getCurrentStepMethod

      public java.util.Optional<java.lang.reflect.Method> getCurrentStepMethod()
    • stepFinished

      public void stepFinished()
      Specified by:
      stepFinished in interface StepListener
    • stepFailed

      public void stepFailed​(StepFailure failure)
      Specified by:
      stepFailed in interface StepListener
    • stepFailedWithException

      public void stepFailedWithException​(java.lang.Throwable failure)
    • lastStepFailed

      public void lastStepFailed​(StepFailure failure)
      Specified by:
      lastStepFailed in interface StepListener
    • stepIgnored

      public void stepIgnored()
      Specified by:
      stepIgnored in interface StepListener
    • stepPending

      public void stepPending()
      Specified by:
      stepPending in interface StepListener
    • stepPending

      public void stepPending​(java.lang.String message)
      Specified by:
      stepPending in interface StepListener
    • assumptionViolated

      public void assumptionViolated​(java.lang.String message)
      Specified by:
      assumptionViolated in interface StepListener
    • testRunFinished

      public void testRunFinished()
      Specified by:
      testRunFinished in interface StepListener
    • getCurrentLevel

      public int getCurrentLevel()
    • getForcedResult

      public java.util.Optional<TestResult> getForcedResult()
    • clearForcedResult

      public void clearForcedResult()
    • getActiveDrivers

      public java.util.Map<java.lang.String,​org.openqa.selenium.WebDriver> getActiveDrivers()
    • getTestOutcomes

      public java.util.List<TestOutcome> getTestOutcomes()
      Description copied from interface: StepPublisher
      A step listener should be able to return a set of test results at the end of the test run.
      Specified by:
      getTestOutcomes in interface StepPublisher
    • setDriver

      public void setDriver​(org.openqa.selenium.WebDriver driver)
      Description copied from interface: StepPublisher
      Used to update the webdriver driver for screenshots if a listener is reused between scenarios.
      Specified by:
      setDriver in interface StepPublisher
    • getDriver

      public org.openqa.selenium.WebDriver getDriver()
      Description copied from interface: StepPublisher
      The currently-used WebDriver instance for these tests.
      Specified by:
      getDriver in interface StepPublisher
    • aStepHasFailed

      public boolean aStepHasFailed()
      Description copied from interface: StepPublisher
      Should return true if a step failure has been logged. We need to share this information if multiple step libraries are used.
      Specified by:
      aStepHasFailed in interface StepPublisher
    • aStepHasFailedInTheCurrentExample

      public boolean aStepHasFailedInTheCurrentExample()
    • getTestFailureCause

      public FailureCause getTestFailureCause()
      Description copied from interface: StepPublisher
      If a test failed, what was the error.
      Specified by:
      getTestFailureCause in interface StepPublisher
    • testFailed

      public void testFailed​(TestOutcome testOutcome, java.lang.Throwable cause)
      Specified by:
      testFailed in interface StepListener
    • testIgnored

      public void testIgnored()
      Specified by:
      testIgnored in interface StepListener
    • testSkipped

      public void testSkipped()
      Specified by:
      testSkipped in interface StepListener
    • testPending

      public void testPending()
      Specified by:
      testPending in interface StepListener
    • testIsManual

      public void testIsManual()
      Specified by:
      testIsManual in interface StepListener
    • notifyScreenChange

      public void notifyScreenChange()
      Specified by:
      notifyScreenChange in interface StepListener
    • takeScreenshot

      public void takeScreenshot()
      Take a screenshot now.
    • useExamplesFrom

      public void useExamplesFrom​(DataTable table)
      The current scenario is a data-driven scenario using test data from the specified table.
      Specified by:
      useExamplesFrom in interface StepListener
    • addNewExamplesFrom

      public void addNewExamplesFrom​(DataTable table)
      Specified by:
      addNewExamplesFrom in interface StepListener
    • exampleStarted

      public void exampleStarted​(java.util.Map<java.lang.String,​java.lang.String> data)
      Specified by:
      exampleStarted in interface StepListener
    • exampleStarted

      public void exampleStarted​(java.util.Map<java.lang.String,​java.lang.String> data, java.lang.String exampleName)
      Specified by:
      exampleStarted in interface StepListener
    • exampleFinished

      public void exampleFinished()
      Specified by:
      exampleFinished in interface StepListener
    • recordRestQuery

      public void recordRestQuery​(RestQuery restQuery)