Package net.thucydides.core.steps
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBaseStepListener.ScreenshotTypeclassBaseStepListener.StepMergerclassBaseStepListener.StepMutator -
Constructor Summary
Constructors Constructor Description BaseStepListener(java.io.File outputDirectory)BaseStepListener(java.io.File outputDirectory, com.google.inject.Injector injector)BaseStepListener(java.io.File outputDirectory, Pages pages)Create a step listener using the driver from a given page factory.BaseStepListener(java.io.File outputDirectory, WebdriverManager webdriverManager)BaseStepListener(java.lang.Class<? extends org.openqa.selenium.WebDriver> driverClass, java.io.File outputDirectory)Create a step listener with a given web driver type.BaseStepListener(java.lang.Class<? extends org.openqa.selenium.WebDriver> driverClass, java.io.File outputDirectory, Configuration configuration) -
Method Summary
Modifier and Type Method Description voidaddChildStepsFrom(java.util.List<TestStep> newSteps)voidaddIssuesToCurrentStory(java.util.List<java.lang.String> issues)voidaddNewExamplesFrom(DataTable table)voidaddStepsFrom(java.util.List<TestStep> newSteps)voidaddTagsToCurrentStory(java.util.List<TestTag> tags)voidassumptionViolated(java.lang.String message)booleanaStepHasFailed()Should return true if a step failure has been logged.booleanaStepHasFailedInTheCurrentExample()voidcancelPreviousTest()BaseStepListenerchildListenerFor(StepEventBus eventBus)voidclearForcedResult()java.util.Optional<TestStep>cloneCurrentStep()voidcurrentStepIsAPrecondition()voidexampleFinished()voidexampleStarted(java.util.Map<java.lang.String,java.lang.String> data)voidexampleStarted(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String exampleName)voidexceptionExpected(java.lang.Class<? extends java.lang.Throwable> expected)java.util.Map<java.lang.String,org.openqa.selenium.WebDriver>getActiveDrivers()java.util.Optional<TestResult>getAnnotatedResult()protected SystemClockgetClock()intgetCurrentLevel()java.util.Optional<java.lang.reflect.Method>getCurrentStepMethod()TestOutcomegetCurrentTestOutcome()org.openqa.selenium.WebDrivergetDriver()The currently-used WebDriver instance for these tests.StepEventBusgetEventBus()java.util.Optional<TestResult>getForcedResult()PhotographergetPhotographer()protected WebdriverProxyFactorygetProxyFactory()intgetRunningStepCount()intgetStepCount()FailureCausegetTestFailureCause()If a test failed, what was the error.java.util.List<TestOutcome>getTestOutcomes()A step listener should be able to return a set of test results at the end of the test run.booleanisAvailable()voidlastStepFailed(StepFailure failure)voidlastTestPassedAfterRetries(int attemptNum, java.util.List<java.lang.String> failureMessages, TestFailureCause testfailureCause)java.util.Optional<TestOutcome>latestTestOutcome()BaseStepListener.StepMergermergeLast(int maxStepsToMerge)voidnotifyScreenChange()voidoverrideResultTo(TestResult result)voidrecordManualTestResult(TestResult result, java.util.Optional<java.lang.String> lastTestedVersion, java.lang.Boolean isUpToDate, java.util.Optional<java.lang.String> testEvidence)voidrecordRestQuery(RestQuery restQuery)protected ScreenshotPermissionscreenshots()voidsetAllStepsTo(TestResult result)voidsetDriver(org.openqa.selenium.WebDriver driver)Used to update the webdriver driver for screenshots if a listener is reused between scenarios.voidsetEventBus(StepEventBus eventBus)voidskippedStepStarted(ExecutedStepDescription description)BaseStepListenerspawn(java.lang.String outcomeName)Creates a new base step listener withvoidstepFailed(StepFailure failure)voidstepFailedWithException(java.lang.Throwable failure)voidstepFinished()voidstepIgnored()voidstepPending()voidstepPending(java.lang.String message)voidstepStarted(ExecutedStepDescription description)A step within a test is called.voidtakeScreenshot()Take a screenshot now.voidtestFailed(TestOutcome testOutcome, java.lang.Throwable cause)voidtestFinished(TestOutcome outcome)voidtestFinished(TestOutcome outcome, boolean inDataDrivenTest)A test has finished.voidtestIgnored()voidtestIsManual()voidtestPending()voidtestRetried()voidtestRunFinished()voidtestSkipped()voidtestStarted(java.lang.String testMethod)An individual test starts.voidtestStarted(java.lang.String testMethod, java.lang.String id)voidtestSuiteFinished()booleantestSuiteRunning()voidtestSuiteStarted(java.lang.Class<?> startedTestSuite)A test suite (containing a series of tests) starts.voidtestSuiteStarted(Story story)voidupdateCurrentStepFailureCause(java.lang.Throwable failure)BaseStepListener.StepMutatorupdateCurrentStepTitle(java.lang.String updatedStepTitle)voidupdateExampleLineNumber(int lineNumber)voidupdateOverallResults()voiduseExamplesFrom(DataTable table)The current scenario is a data-driven scenario using test data from the specified table.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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 usedoutputDirectory- 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
-
BaseStepListener
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 herepages- a pages factory.
-
-
Method Details
-
setEventBus
-
getEventBus
-
cloneCurrentStep
-
getAnnotatedResult
-
setAllStepsTo
-
overrideResultTo
-
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
-
getStepCount
public int getStepCount() -
getRunningStepCount
public int getRunningStepCount() -
updateOverallResults
public void updateOverallResults() -
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) -
addStepsFrom
-
addChildStepsFrom
-
childListenerFor
-
spawn
Creates a new base step listener with- Parameters:
outcomeName-- Returns:
-
screenshots
-
getProxyFactory
-
getCurrentTestOutcome
-
isAvailable
public boolean isAvailable() -
latestTestOutcome
-
getClock
-
testSuiteStarted
public void testSuiteStarted(java.lang.Class<?> startedTestSuite)A test suite (containing a series of tests) starts.- Specified by:
testSuiteStartedin interfaceStepListener- Parameters:
startedTestSuite- the class implementing the test suite (e.g. a JUnit test case)
-
testSuiteStarted
- Specified by:
testSuiteStartedin interfaceStepListener
-
testSuiteRunning
public boolean testSuiteRunning() -
addIssuesToCurrentStory
public void addIssuesToCurrentStory(java.util.List<java.lang.String> issues) -
addTagsToCurrentStory
-
testSuiteFinished
public void testSuiteFinished()- Specified by:
testSuiteFinishedin interfaceStepListener
-
testStarted
public void testStarted(java.lang.String testMethod)An individual test starts.- Specified by:
testStartedin interfaceStepListener- 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:
testStartedin interfaceStepListener
-
updateCurrentStepTitle
-
updateCurrentStepFailureCause
public void updateCurrentStepFailureCause(java.lang.Throwable failure) -
testFinished
- Specified by:
testFinishedin interfaceStepListener
-
testFinished
A test has finished.- Specified by:
testFinishedin interfaceStepListener- Parameters:
outcome- the result of the test that just finished.
-
testRetried
public void testRetried()- Specified by:
testRetriedin interfaceStepListener
-
stepStarted
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:
stepStartedin interfaceStepListener- Parameters:
description- the description of the test that is about to be run
-
skippedStepStarted
- Specified by:
skippedStepStartedin interfaceStepListener
-
getCurrentStepMethod
public java.util.Optional<java.lang.reflect.Method> getCurrentStepMethod() -
stepFinished
public void stepFinished()- Specified by:
stepFinishedin interfaceStepListener
-
stepFailed
- Specified by:
stepFailedin interfaceStepListener
-
stepFailedWithException
public void stepFailedWithException(java.lang.Throwable failure) -
lastStepFailed
- Specified by:
lastStepFailedin interfaceStepListener
-
stepIgnored
public void stepIgnored()- Specified by:
stepIgnoredin interfaceStepListener
-
stepPending
public void stepPending()- Specified by:
stepPendingin interfaceStepListener
-
stepPending
public void stepPending(java.lang.String message)- Specified by:
stepPendingin interfaceStepListener
-
assumptionViolated
public void assumptionViolated(java.lang.String message)- Specified by:
assumptionViolatedin interfaceStepListener
-
testRunFinished
public void testRunFinished()- Specified by:
testRunFinishedin interfaceStepListener
-
getCurrentLevel
public int getCurrentLevel() -
getForcedResult
-
clearForcedResult
public void clearForcedResult() -
getActiveDrivers
public java.util.Map<java.lang.String,org.openqa.selenium.WebDriver> getActiveDrivers() -
getTestOutcomes
Description copied from interface:StepPublisherA step listener should be able to return a set of test results at the end of the test run.- Specified by:
getTestOutcomesin interfaceStepPublisher
-
setDriver
public void setDriver(org.openqa.selenium.WebDriver driver)Description copied from interface:StepPublisherUsed to update the webdriver driver for screenshots if a listener is reused between scenarios.- Specified by:
setDriverin interfaceStepPublisher
-
getDriver
public org.openqa.selenium.WebDriver getDriver()Description copied from interface:StepPublisherThe currently-used WebDriver instance for these tests.- Specified by:
getDriverin interfaceStepPublisher
-
aStepHasFailed
public boolean aStepHasFailed()Description copied from interface:StepPublisherShould return true if a step failure has been logged. We need to share this information if multiple step libraries are used.- Specified by:
aStepHasFailedin interfaceStepPublisher
-
aStepHasFailedInTheCurrentExample
public boolean aStepHasFailedInTheCurrentExample() -
getTestFailureCause
Description copied from interface:StepPublisherIf a test failed, what was the error.- Specified by:
getTestFailureCausein interfaceStepPublisher
-
testFailed
- Specified by:
testFailedin interfaceStepListener
-
testIgnored
public void testIgnored()- Specified by:
testIgnoredin interfaceStepListener
-
testSkipped
public void testSkipped()- Specified by:
testSkippedin interfaceStepListener
-
testPending
public void testPending()- Specified by:
testPendingin interfaceStepListener
-
testIsManual
public void testIsManual()- Specified by:
testIsManualin interfaceStepListener
-
notifyScreenChange
public void notifyScreenChange()- Specified by:
notifyScreenChangein interfaceStepListener
-
takeScreenshot
public void takeScreenshot()Take a screenshot now. -
useExamplesFrom
The current scenario is a data-driven scenario using test data from the specified table.- Specified by:
useExamplesFromin interfaceStepListener
-
addNewExamplesFrom
- Specified by:
addNewExamplesFromin interfaceStepListener
-
exampleStarted
public void exampleStarted(java.util.Map<java.lang.String,java.lang.String> data)- Specified by:
exampleStartedin interfaceStepListener
-
exampleStarted
public void exampleStarted(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String exampleName)- Specified by:
exampleStartedin interfaceStepListener
-
exampleFinished
public void exampleFinished()- Specified by:
exampleFinishedin interfaceStepListener
-
recordRestQuery
-