Package net.serenitybdd.junit.runners
Class SerenityRunner
java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
net.serenitybdd.junit.runners.SerenityRunner
- All Implemented Interfaces:
net.thucydides.core.tags.Taggable
,org.junit.runner.Describable
,org.junit.runner.manipulation.Filterable
,org.junit.runner.manipulation.Orderable
,org.junit.runner.manipulation.Sortable
- Direct Known Subclasses:
ThucydidesRunner
public class SerenityRunner
extends org.junit.runners.BlockJUnit4ClassRunner
implements net.thucydides.core.tags.Taggable
A test runner for WebDriver-based web tests. This test runner initializes a
WebDriver instance before running the tests in their order of appearance. At
the end of the tests, it closes and quits the WebDriver instance.
The test runner will by default produce output in XML and HTML. This
can extended by subscribing more reporter implementations to the test runner.
- Author:
- johnsmart
-
Constructor Summary
Constructors Constructor Description SerenityRunner(java.lang.Class<?> klass)
Creates a new test runner for WebDriver web tests.SerenityRunner(java.lang.Class<?> klass, com.google.inject.Injector injector)
SerenityRunner(java.lang.Class<?> klass, com.google.inject.Module module)
Creates a new test runner for WebDriver web tests.SerenityRunner(java.lang.Class<?> klass, net.thucydides.core.batches.BatchManager batchManager)
SerenityRunner(java.lang.Class<?> klass, WebDriverFactory webDriverFactory)
SerenityRunner(java.lang.Class<?> klass, WebDriverFactory webDriverFactory, DriverConfiguration configuration)
SerenityRunner(java.lang.Class<?> klass, WebDriverFactory webDriverFactory, DriverConfiguration configuration, net.thucydides.core.batches.BatchManager batchManager)
SerenityRunner(java.lang.Class<?> klass, WebdriverManager webDriverManager, DriverConfiguration configuration, net.thucydides.core.batches.BatchManager batchManager)
-
Method Summary
Modifier and Type Method Description protected void
additionalBrowserCleanup()
protected org.openqa.selenium.WebDriver
driverFor(org.junit.runners.model.FrameworkMethod method)
protected void
generateReports()
protected net.thucydides.core.batches.BatchManager
getBatchManager()
Batch Manager used for running tests in parallel batchesprotected DriverConfiguration
getConfiguration()
The Configuration class manages output directories and driver types.protected java.util.Collection<net.thucydides.core.reports.AcceptanceTestReporter>
getDefaultReporters()
protected org.openqa.selenium.WebDriver
getDriver()
protected org.openqa.selenium.WebDriver
getDriver(java.lang.String driver, java.lang.String driverOptions)
java.io.File
getOutputDirectory()
Pages
getPages()
protected JUnitStepListener
getStepListener()
The Step Listener observes and records what happens during the execution of the test.java.util.List<net.thucydides.core.model.TestOutcome>
getTestOutcomes()
Find the current set of test outcomes produced by the test execution.protected JUnitStepListener
initListeners()
protected JUnitStepListener
initListenersUsing(Pages pageFactory)
protected void
initStepEventBus()
protected void
injectAnnotatedPagesObjectInto(java.lang.Object testCase)
Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.protected void
injectDriverInto(java.lang.Object testCase)
Instantiate the @Managed-annotated WebDriver instance with current WebDriver.protected void
injectEnvironmentVariablesInto(java.lang.Object testCase)
protected void
injectScenarioStepsInto(java.lang.Object testCase)
Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.protected org.junit.runners.model.Statement
methodInvoker(org.junit.runners.model.FrameworkMethod method, java.lang.Object test)
Running a unit test, which represents a test scenario.protected void
prepareBrowserForTest()
void
run(org.junit.runner.notification.RunNotifier notifier)
Runs the tests in the acceptance test case.protected void
runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier)
protected void
setStepListener(JUnitStepListener stepListener)
void
subscribeReporter(net.thucydides.core.reports.AcceptanceTestReporter reporter)
To generate reports, different AcceptanceTestReporter instances need to subscribe to the listener.void
useQualifier(java.lang.String qualifier)
Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, computeTestMethods, createTest, createTest, describeChild, getChildren, getTestRules, isIgnored, methodBlock, possiblyExpectingExceptions, rules, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores, withPotentialTimeout
Methods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classBlock, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolation
Methods inherited from class org.junit.runner.Runner
testCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass) throws org.junit.runners.model.InitializationErrorCreates a new test runner for WebDriver web tests.- Parameters:
klass
- the class under test- Throws:
org.junit.runners.model.InitializationError
- if some JUnit-related initialization problem occurred
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, com.google.inject.Module module) throws org.junit.runners.model.InitializationErrorCreates a new test runner for WebDriver web tests.- Parameters:
klass
- the class under testmodule
- used to inject a custom Guice module- Throws:
org.junit.runners.model.InitializationError
- if some JUnit-related initialization problem occurred
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, com.google.inject.Injector injector) throws org.junit.runners.model.InitializationError- Throws:
org.junit.runners.model.InitializationError
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, WebDriverFactory webDriverFactory) throws org.junit.runners.model.InitializationError- Throws:
org.junit.runners.model.InitializationError
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, WebDriverFactory webDriverFactory, DriverConfiguration configuration) throws org.junit.runners.model.InitializationError- Throws:
org.junit.runners.model.InitializationError
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, WebDriverFactory webDriverFactory, DriverConfiguration configuration, net.thucydides.core.batches.BatchManager batchManager) throws org.junit.runners.model.InitializationError- Throws:
org.junit.runners.model.InitializationError
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, net.thucydides.core.batches.BatchManager batchManager) throws org.junit.runners.model.InitializationError- Throws:
org.junit.runners.model.InitializationError
-
SerenityRunner
public SerenityRunner(java.lang.Class<?> klass, WebdriverManager webDriverManager, DriverConfiguration configuration, net.thucydides.core.batches.BatchManager batchManager) throws org.junit.runners.model.InitializationError- Throws:
org.junit.runners.model.InitializationError
-
-
Method Details
-
getPages
-
getConfiguration
The Configuration class manages output directories and driver types. They can be defined as system values, or have sensible defaults.- Returns:
- the current configuration
-
getBatchManager
protected net.thucydides.core.batches.BatchManager getBatchManager()Batch Manager used for running tests in parallel batches- Returns:
- the current batch manager object
-
getOutputDirectory
public java.io.File getOutputDirectory() -
subscribeReporter
public void subscribeReporter(net.thucydides.core.reports.AcceptanceTestReporter reporter)To generate reports, different AcceptanceTestReporter instances need to subscribe to the listener. The listener will tell them when the test is done, and the reporter can decide what to do.- Parameters:
reporter
- an implementation of the AcceptanceTestReporter interface.
-
useQualifier
public void useQualifier(java.lang.String qualifier) -
run
public void run(org.junit.runner.notification.RunNotifier notifier)Runs the tests in the acceptance test case.- Overrides:
run
in classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
generateReports
protected void generateReports() -
getStepListener
The Step Listener observes and records what happens during the execution of the test. Once the test is over, the Step Listener can provide the acceptance test outcome in the form of an TestOutcome object.- Returns:
- the current step listener
-
setStepListener
-
initStepEventBus
protected void initStepEventBus() -
initListenersUsing
-
initListeners
-
runChild
protected void runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier)- Overrides:
runChild
in classorg.junit.runners.BlockJUnit4ClassRunner
-
additionalBrowserCleanup
protected void additionalBrowserCleanup() -
prepareBrowserForTest
protected void prepareBrowserForTest() -
methodInvoker
protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method, java.lang.Object test)Running a unit test, which represents a test scenario.- Overrides:
methodInvoker
in classorg.junit.runners.BlockJUnit4ClassRunner
-
injectDriverInto
protected void injectDriverInto(java.lang.Object testCase)Instantiate the @Managed-annotated WebDriver instance with current WebDriver.- Parameters:
testCase
- A Serenity-annotated test class
-
driverFor
protected org.openqa.selenium.WebDriver driverFor(org.junit.runners.model.FrameworkMethod method) -
injectScenarioStepsInto
protected void injectScenarioStepsInto(java.lang.Object testCase)Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.- Parameters:
testCase
- A Serenity-annotated test class
-
injectAnnotatedPagesObjectInto
protected void injectAnnotatedPagesObjectInto(java.lang.Object testCase)Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.- Parameters:
testCase
- A Serenity-annotated test class
-
injectEnvironmentVariablesInto
protected void injectEnvironmentVariablesInto(java.lang.Object testCase) -
getDriver
protected org.openqa.selenium.WebDriver getDriver() -
getDriver
protected org.openqa.selenium.WebDriver getDriver(java.lang.String driver, java.lang.String driverOptions) -
getTestOutcomes
public java.util.List<net.thucydides.core.model.TestOutcome> getTestOutcomes()Find the current set of test outcomes produced by the test execution.- Returns:
- the current list of test outcomes
-
getDefaultReporters
protected java.util.Collection<net.thucydides.core.reports.AcceptanceTestReporter> getDefaultReporters()- Returns:
- The default reporters applicable for standard test runs.
-