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 class
BaseStepListener.ScreenshotType
class
BaseStepListener.StepMerger
class
BaseStepListener.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 void
addIssuesToCurrentStory(java.util.List<java.lang.String> issues)
void
addNewExamplesFrom(DataTable table)
void
addTagsToCurrentStory(java.util.List<TestTag> tags)
void
assumptionViolated(java.lang.String message)
boolean
aStepHasFailed()
Should return true if a step failure has been logged.boolean
aStepHasFailedInTheCurrentExample()
void
cancelPreviousTest()
void
clearForcedResult()
java.util.Optional<TestStep>
cloneCurrentStep()
void
currentStepIsAPrecondition()
void
exampleFinished()
void
exampleStarted(java.util.Map<java.lang.String,java.lang.String> data)
void
exampleStarted(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String exampleName)
void
exceptionExpected(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 SystemClock
getClock()
int
getCurrentLevel()
java.util.Optional<java.lang.reflect.Method>
getCurrentStepMethod()
TestOutcome
getCurrentTestOutcome()
org.openqa.selenium.WebDriver
getDriver()
The currently-used WebDriver instance for these tests.StepEventBus
getEventBus()
java.util.Optional<TestResult>
getForcedResult()
Photographer
getPhotographer()
protected WebdriverProxyFactory
getProxyFactory()
int
getRunningStepCount()
int
getStepCount()
FailureCause
getTestFailureCause()
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.boolean
isAvailable()
void
lastStepFailed(StepFailure failure)
void
lastTestPassedAfterRetries(int attemptNum, java.util.List<java.lang.String> failureMessages, TestFailureCause testfailureCause)
java.util.Optional<TestOutcome>
latestTestOutcome()
BaseStepListener.StepMerger
mergeLast(int maxStepsToMerge)
void
notifyScreenChange()
void
overrideResultTo(TestResult result)
void
recordManualTestResult(TestResult result, java.util.Optional<java.lang.String> lastTestedVersion, java.lang.Boolean isUpToDate, java.util.Optional<java.lang.String> testEvidence)
void
recordRestQuery(RestQuery restQuery)
protected ScreenshotPermission
screenshots()
void
setAllStepsTo(TestResult result)
void
setDriver(org.openqa.selenium.WebDriver driver)
Used to update the webdriver driver for screenshots if a listener is reused between scenarios.void
setEventBus(StepEventBus eventBus)
void
skippedStepStarted(ExecutedStepDescription description)
void
stepFailed(StepFailure failure)
void
stepFailedWithException(java.lang.Throwable failure)
void
stepFinished()
void
stepIgnored()
void
stepPending()
void
stepPending(java.lang.String message)
void
stepStarted(ExecutedStepDescription description)
A step within a test is called.void
takeScreenshot()
Take a screenshot now.void
testFailed(TestOutcome testOutcome, java.lang.Throwable cause)
void
testFinished(TestOutcome outcome)
void
testFinished(TestOutcome outcome, boolean inDataDrivenTest)
A test has finished.void
testIgnored()
void
testIsManual()
void
testPending()
void
testRetried()
void
testRunFinished()
void
testSkipped()
void
testStarted(java.lang.String testMethod)
An individual test starts.void
testStarted(java.lang.String testMethod, java.lang.String id)
void
testSuiteFinished()
boolean
testSuiteRunning()
void
testSuiteStarted(java.lang.Class<?> startedTestSuite)
A test suite (containing a series of tests) starts.void
testSuiteStarted(Story story)
void
updateCurrentStepFailureCause(java.lang.Throwable failure)
BaseStepListener.StepMutator
updateCurrentStepTitle(java.lang.String updatedStepTitle)
void
updateExampleLineNumber(int lineNumber)
void
updateOverallResults()
void
useExamplesFrom(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) -
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:
testSuiteStarted
in interfaceStepListener
- Parameters:
startedTestSuite
- the class implementing the test suite (e.g. a JUnit test case)
-
testSuiteStarted
- Specified by:
testSuiteStarted
in interfaceStepListener
-
testSuiteRunning
public boolean testSuiteRunning() -
addIssuesToCurrentStory
public void addIssuesToCurrentStory(java.util.List<java.lang.String> issues) -
addTagsToCurrentStory
-
testSuiteFinished
public void testSuiteFinished()- Specified by:
testSuiteFinished
in interfaceStepListener
-
testStarted
public void testStarted(java.lang.String testMethod)An individual test starts.- Specified by:
testStarted
in 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:
testStarted
in interfaceStepListener
-
updateCurrentStepTitle
-
updateCurrentStepFailureCause
public void updateCurrentStepFailureCause(java.lang.Throwable failure) -
testFinished
- Specified by:
testFinished
in interfaceStepListener
-
testFinished
A test has finished.- Specified by:
testFinished
in interfaceStepListener
- Parameters:
outcome
- the result of the test that just finished.
-
testRetried
public void testRetried()- Specified by:
testRetried
in 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:
stepStarted
in interfaceStepListener
- Parameters:
description
- the description of the test that is about to be run
-
skippedStepStarted
- Specified by:
skippedStepStarted
in interfaceStepListener
-
getCurrentStepMethod
public java.util.Optional<java.lang.reflect.Method> getCurrentStepMethod() -
stepFinished
public void stepFinished()- Specified by:
stepFinished
in interfaceStepListener
-
stepFailed
- Specified by:
stepFailed
in interfaceStepListener
-
stepFailedWithException
public void stepFailedWithException(java.lang.Throwable failure) -
lastStepFailed
- Specified by:
lastStepFailed
in interfaceStepListener
-
stepIgnored
public void stepIgnored()- Specified by:
stepIgnored
in interfaceStepListener
-
stepPending
public void stepPending()- Specified by:
stepPending
in interfaceStepListener
-
stepPending
public void stepPending(java.lang.String message)- Specified by:
stepPending
in interfaceStepListener
-
assumptionViolated
public void assumptionViolated(java.lang.String message)- Specified by:
assumptionViolated
in interfaceStepListener
-
testRunFinished
public void testRunFinished()- Specified by:
testRunFinished
in 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: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 interfaceStepPublisher
-
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 interfaceStepPublisher
-
getDriver
public org.openqa.selenium.WebDriver getDriver()Description copied from interface:StepPublisher
The currently-used WebDriver instance for these tests.- Specified by:
getDriver
in interfaceStepPublisher
-
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 interfaceStepPublisher
-
aStepHasFailedInTheCurrentExample
public boolean aStepHasFailedInTheCurrentExample() -
getTestFailureCause
Description copied from interface:StepPublisher
If a test failed, what was the error.- Specified by:
getTestFailureCause
in interfaceStepPublisher
-
testFailed
- Specified by:
testFailed
in interfaceStepListener
-
testIgnored
public void testIgnored()- Specified by:
testIgnored
in interfaceStepListener
-
testSkipped
public void testSkipped()- Specified by:
testSkipped
in interfaceStepListener
-
testPending
public void testPending()- Specified by:
testPending
in interfaceStepListener
-
testIsManual
public void testIsManual()- Specified by:
testIsManual
in interfaceStepListener
-
notifyScreenChange
public void notifyScreenChange()- Specified by:
notifyScreenChange
in 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:
useExamplesFrom
in interfaceStepListener
-
addNewExamplesFrom
- Specified by:
addNewExamplesFrom
in interfaceStepListener
-
exampleStarted
public void exampleStarted(java.util.Map<java.lang.String,java.lang.String> data)- Specified by:
exampleStarted
in interfaceStepListener
-
exampleStarted
public void exampleStarted(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String exampleName)- Specified by:
exampleStarted
in interfaceStepListener
-
exampleFinished
public void exampleFinished()- Specified by:
exampleFinished
in interfaceStepListener
-
recordRestQuery
-