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.model.tags.Taggable, org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Orderable, org.junit.runner.manipulation.Sortable

public class SerenityRunner extends org.junit.runners.BlockJUnit4ClassRunner implements net.thucydides.model.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(Class<?> klass, net.thucydides.core.webdriver.WebDriverFactory webDriverFactory)
     
    SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebDriverFactory webDriverFactory, net.thucydides.core.webdriver.DriverConfiguration configuration)
     
    SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebDriverFactory webDriverFactory, net.thucydides.core.webdriver.DriverConfiguration configuration, net.thucydides.model.batches.BatchManager batchManager)
     
    SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebdriverManager webDriverManager, net.thucydides.core.webdriver.DriverConfiguration configuration, net.thucydides.model.batches.BatchManager batchManager)
     
    SerenityRunner(Class<?> klass, net.thucydides.model.batches.BatchManager batchManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected org.openqa.selenium.WebDriver
    driverFor(org.junit.runners.model.FrameworkMethod method)
     
    protected void
     
    protected net.thucydides.model.batches.BatchManager
    Batch Manager used for running tests in parallel batches
    protected net.thucydides.core.webdriver.DriverConfiguration
    The Configuration class manages output directories and driver types.
    protected Collection<net.thucydides.model.reports.AcceptanceTestReporter>
     
    protected org.openqa.selenium.WebDriver
     
    protected org.openqa.selenium.WebDriver
    getDriver(String driver, String driverOptions)
     
     
    net.thucydides.core.pages.Pages
     
    The Step Listener observes and records what happens during the execution of the test.
    List<net.thucydides.model.domain.TestOutcome>
    Find the current set of test outcomes produced by the test execution.
     
    initListenersUsing(net.thucydides.core.pages.Pages pageFactory)
     
    protected void
     
    protected void
    Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.
    protected void
    Instantiate the @Managed-annotated WebDriver instance with current WebDriver.
    protected void
     
    protected void
    Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.
    protected org.junit.runners.model.Statement
    methodInvoker(org.junit.runners.model.FrameworkMethod method, Object test)
    Running a unit test, which represents a test scenario.
    protected void
     
    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
     
    void
    subscribeReporter(net.thucydides.model.reports.AcceptanceTestReporter reporter)
    To generate reports, different AcceptanceTestReporter instances need to subscribe to the listener.
    void
    useQualifier(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(Class<?> klass) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
    • SerenityRunner

      public SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebDriverFactory webDriverFactory) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
    • SerenityRunner

      public SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebDriverFactory webDriverFactory, net.thucydides.core.webdriver.DriverConfiguration configuration) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
    • SerenityRunner

      public SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebDriverFactory webDriverFactory, net.thucydides.core.webdriver.DriverConfiguration configuration, net.thucydides.model.batches.BatchManager batchManager) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
    • SerenityRunner

      public SerenityRunner(Class<?> klass, net.thucydides.model.batches.BatchManager batchManager) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
    • SerenityRunner

      public SerenityRunner(Class<?> klass, net.thucydides.core.webdriver.WebdriverManager webDriverManager, net.thucydides.core.webdriver.DriverConfiguration configuration, net.thucydides.model.batches.BatchManager batchManager) throws org.junit.runners.model.InitializationError
      Throws:
      org.junit.runners.model.InitializationError
  • Method Details

    • getPages

      public net.thucydides.core.pages.Pages getPages()
    • getConfiguration

      protected net.thucydides.core.webdriver.DriverConfiguration 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.model.batches.BatchManager getBatchManager()
      Batch Manager used for running tests in parallel batches
      Returns:
      the current batch manager object
    • getOutputDirectory

      public File getOutputDirectory()
    • subscribeReporter

      public void subscribeReporter(net.thucydides.model.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(String qualifier)
    • run

      public void run(org.junit.runner.notification.RunNotifier notifier)
      Runs the tests in the acceptance test case.
      Overrides:
      run in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
    • generateReports

      protected void generateReports()
    • getStepListener

      protected JUnitStepListener 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

      protected void setStepListener(JUnitStepListener stepListener)
    • initStepEventBus

      protected void initStepEventBus()
    • initListenersUsing

      protected JUnitStepListener initListenersUsing(net.thucydides.core.pages.Pages pageFactory)
    • initListeners

      protected JUnitStepListener initListeners()
    • runChild

      protected void runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier)
      Overrides:
      runChild in class org.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, Object test)
      Running a unit test, which represents a test scenario.
      Overrides:
      methodInvoker in class org.junit.runners.BlockJUnit4ClassRunner
    • injectDriverInto

      protected void injectDriverInto(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(Object testCase)
      Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.
      Parameters:
      testCase - A Serenity-annotated test class
    • injectAnnotatedPagesObjectInto

      protected void injectAnnotatedPagesObjectInto(Object testCase)
      Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.
      Parameters:
      testCase - A Serenity-annotated test class
    • injectEnvironmentVariablesInto

      protected void injectEnvironmentVariablesInto(Object testCase)
    • getDriver

      protected org.openqa.selenium.WebDriver getDriver()
    • getDriver

      protected org.openqa.selenium.WebDriver getDriver(String driver, String driverOptions)
    • getTestOutcomes

      public List<net.thucydides.model.domain.TestOutcome> getTestOutcomes()
      Find the current set of test outcomes produced by the test execution.
      Returns:
      the current list of test outcomes
    • getDefaultReporters

      protected Collection<net.thucydides.model.reports.AcceptanceTestReporter> getDefaultReporters()
      Returns:
      The default reporters applicable for standard test runs.