Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.Interface FailureRerunner
Source:SerenityRunner.java  
1package net.serenitybdd.junit.runners;2import com.google.inject.Injector;3import com.google.inject.Module;4import net.serenitybdd.core.Serenity;5import net.serenitybdd.core.environment.WebDriverConfiguredEnvironment;6import net.serenitybdd.core.injectors.EnvironmentDependencyInjector;7import net.thucydides.core.annotations.ManagedWebDriverAnnotatedField;8import net.thucydides.core.annotations.ManualTestMarkedAsError;9import net.thucydides.core.annotations.ManualTestMarkedAsFailure;10import net.thucydides.core.annotations.TestCaseAnnotations;11import net.thucydides.core.batches.BatchManager;12import net.thucydides.core.batches.BatchManagerProvider;13import net.thucydides.core.guice.Injectors;14import net.thucydides.core.guice.webdriver.WebDriverModule;15import net.thucydides.core.model.TestOutcome;16import net.thucydides.core.pages.Pages;17import net.thucydides.core.reports.AcceptanceTestReporter;18import net.thucydides.core.reports.ReportService;19import net.thucydides.core.steps.PageObjectDependencyInjector;20import net.thucydides.core.steps.StepAnnotations;21import net.thucydides.core.steps.StepEventBus;22import net.thucydides.core.steps.StepFactory;23import net.thucydides.core.steps.stepdata.StepData;24import net.thucydides.core.tags.TagScanner;25import net.thucydides.core.tags.Taggable;26import net.thucydides.core.webdriver.*;27import net.thucydides.junit.listeners.JUnitStepListener;28import org.junit.runner.Description;29import org.junit.runner.notification.Failure;30import org.junit.runner.notification.RunNotifier;31import org.junit.runners.BlockJUnit4ClassRunner;32import org.junit.runners.model.FrameworkMethod;33import org.junit.runners.model.InitializationError;34import org.junit.runners.model.Statement;35import org.openqa.selenium.WebDriver;36import org.slf4j.Logger;37import org.slf4j.LoggerFactory;38import java.io.File;39import java.util.Collection;40import java.util.List;41import java.util.Map;42import java.util.Optional;43import java.util.function.Consumer;44import static net.serenitybdd.core.Serenity.initializeTestSession;45import static net.thucydides.core.ThucydidesSystemProperty.TEST_RETRY_COUNT;46import static org.apache.commons.lang3.StringUtils.isEmpty;47/**48 * A test runner for WebDriver-based web tests. This test runner initializes a49 * WebDriver instance before running the tests in their order of appearance. At50 * the end of the tests, it closes and quits the WebDriver instance.51 * The test runner will by default produce output in XML and HTML. This52 * can extended by subscribing more reporter implementations to the test runner.53 *54 * @author johnsmart55 */56public class SerenityRunner extends BlockJUnit4ClassRunner implements Taggable {57    /**58     * Provides a proxy of the ScenarioSteps object used to invoke the test steps.59     * This proxy notifies the test runner about individual step outcomes.60     */61    private StepFactory stepFactory;62    private Pages pages;63    private final WebdriverManager webdriverManager;64    private String requestedDriver;65    private ReportService reportService;66    private final TestConfiguration theTest;67    private FailureRerunner failureRerunner;68    /**69     * Special listener that keeps track of test step execution and results.70     */71    private JUnitStepListener stepListener;72    private PageObjectDependencyInjector dependencyInjector;73    private FailureDetectingStepListener failureDetectingStepListener;74    /**75     * Retrieve the runner getConfiguration().from an external source.76     */77    private DriverConfiguration configuration;78    private TagScanner tagScanner;79    private BatchManager batchManager;80    private final Logger logger = LoggerFactory.getLogger(SerenityRunner.class);81    public Pages getPages() {82        return pages;83    }84    /**85     * Creates a new test runner for WebDriver web tests.86     *87     * @param klass the class under test88     * @throws InitializationError if some JUnit-related initialization problem occurred89     */90    public SerenityRunner(final Class<?> klass) throws InitializationError {91        this(klass, Injectors.getInjector(new WebDriverModule()));92    }93    /**94     * Creates a new test runner for WebDriver web tests.95     *96     * @param klass the class under test97     * @param module used to inject a custom Guice module98     * @throws InitializationError if some JUnit-related initialization problem occurred99     */100    public SerenityRunner(Class<?> klass, Module module) throws InitializationError {101        this(klass, Injectors.getInjector(module));102    }103    public SerenityRunner(final Class<?> klass,104                          final Injector injector) throws InitializationError {105        this(klass,106                ThucydidesWebDriverSupport.getWebdriverManager(),107                injector.getInstance(DriverConfiguration.class),108                injector.getInstance(BatchManager.class)109        );110    }111    public SerenityRunner(final Class<?> klass,112                          final WebDriverFactory webDriverFactory) throws InitializationError {113        this(klass, webDriverFactory, WebDriverConfiguredEnvironment.getDriverConfiguration());114    }115    public SerenityRunner(final Class<?> klass,116                          final WebDriverFactory webDriverFactory,117                          final DriverConfiguration configuration) throws InitializationError {118        this(klass,119                webDriverFactory,120                configuration,121                new BatchManagerProvider(configuration).get()122        );123    }124    public SerenityRunner(final Class<?> klass,125                          final WebDriverFactory webDriverFactory,126                          final DriverConfiguration configuration,127                          final BatchManager batchManager) throws InitializationError {128        this(klass,129                ThucydidesWebDriverSupport.getWebdriverManager(webDriverFactory, configuration),130                configuration,131                batchManager132        );133    }134    public SerenityRunner(final Class<?> klass, final BatchManager batchManager) throws InitializationError {135        this(klass,136                ThucydidesWebDriverSupport.getWebdriverManager(),137                WebDriverConfiguredEnvironment.getDriverConfiguration(),138                batchManager);139    }140    public SerenityRunner(final Class<?> klass,141                          final WebdriverManager webDriverManager,142                          final DriverConfiguration configuration,143                          final BatchManager batchManager) throws InitializationError {144        super(klass);145        this.theTest = TestConfiguration.forClass(klass).withSystemConfiguration(configuration);146        this.webdriverManager = webDriverManager;147        this.configuration = configuration;148        this.requestedDriver = getSpecifiedDriver(klass);149        this.tagScanner = new TagScanner(configuration.getEnvironmentVariables());150        this.failureDetectingStepListener = new FailureDetectingStepListener();151        this.failureRerunner = new FailureRerunnerXml(configuration);152        if (TestCaseAnnotations.supportsWebTests(klass)) {153            checkRequestedDriverType();154        }155        this.batchManager = batchManager;156        batchManager.registerTestCase(klass);157    }158    private String getSpecifiedDriver(Class<?> klass) {159        if (ManagedWebDriverAnnotatedField.hasManagedWebdriverField(klass)) {160            return ManagedWebDriverAnnotatedField.findFirstAnnotatedField(klass).getDriver();161        } else {162            return null;163        }164    }165    /**166     * The Configuration class manages output directories and driver types.167     * They can be defined as system values, or have sensible defaults.168     * @return the current configuration169     */170    protected DriverConfiguration getConfiguration() {171        return configuration;172    }173    /**174     * Batch Manager used for running tests in parallel batches175     * @return the current batch manager object176     */177    protected BatchManager getBatchManager() {178        return batchManager;179    }180    /**181     * Ensure that the requested driver type is valid before we start the tests.182     * Otherwise, throw an InitializationError.183     */184    private void checkRequestedDriverType() {185        if (requestedDriverSpecified()) {186            SupportedWebDriver.getDriverTypeFor(requestedDriver);187        } else {188            getConfiguration().getDriverType();189        }190    }191    private boolean requestedDriverSpecified() {192        return !isEmpty(this.requestedDriver);193    }194    public File getOutputDirectory() {195        return getConfiguration().getOutputDirectory();196    }197    /**198     * To generate reports, different AcceptanceTestReporter instances need to199     * subscribe to the listener. The listener will tell them when the test is200     * done, and the reporter can decide what to do.201     * @param reporter an implementation of the AcceptanceTestReporter interface.202     */203    public void subscribeReporter(final AcceptanceTestReporter reporter) {204        getReportService().subscribe(reporter);205    }206    public void useQualifier(final String qualifier) {207        getReportService().useQualifier(qualifier);208    }209    /**210     * Runs the tests in the acceptance test case.211     */212    @Override213    public void run(final RunNotifier notifier) {214        if (skipThisTest()) { return; }215        try {216            RunNotifier localNotifier = initializeRunNotifier(notifier);217            StepEventBus.getEventBus().registerListener(failureDetectingStepListener);218            super.run(localNotifier);219            fireNotificationsBasedOnTestResultsTo(notifier);220        } catch (Throwable someFailure) {221            someFailure.printStackTrace();222            throw someFailure;223        } finally {224            notifyTestSuiteFinished();225            generateReports();226            Map<String, List<String>> failedTests = stepListener.getFailedTests();227            failureRerunner.recordFailedTests(failedTests);228            dropListeners(notifier);229            StepEventBus.getEventBus().dropAllListeners();230        }231    }232    private Optional<TestOutcome> latestOutcome() {233        if (StepEventBus.getEventBus().getBaseStepListener().getTestOutcomes().isEmpty()) {234            return Optional.empty();235        }236        return Optional.of(StepEventBus.getEventBus().getBaseStepListener().getTestOutcomes().get(0));237    }238    private void fireNotificationsBasedOnTestResultsTo(RunNotifier notifier) {239        if (!latestOutcome().isPresent()) {240            return;241        }242    }243    private void notifyTestSuiteFinished() {244        try {245            if (dataDrivenTest()) {246                StepEventBus.getEventBus().exampleFinished();247            } else {248                StepEventBus.getEventBus().testSuiteFinished();249            }250        } catch (Throwable listenerException) {251            // We report and ignore listener exceptions so as not to mess up the rest of the test mechanics.252            logger.error("Test event bus error: " + listenerException.getMessage(), listenerException);253        }254    }255    private boolean dataDrivenTest() {256        return this instanceof TestClassRunnerForParameters;257    }258    private void dropListeners(final RunNotifier notifier) {259        JUnitStepListener listener = getStepListener();260        notifier.removeListener(listener);261        getStepListener().dropListeners();262    }263    protected void generateReports() {264        generateReportsFor(getTestOutcomes());265    }266    private boolean skipThisTest() {267        return testNotInCurrentBatch();268    }269    private boolean testNotInCurrentBatch() {270        return (batchManager != null) && (!batchManager.shouldExecuteThisTest(getDescription().testCount()));271    }272    /**273     * The Step Listener observes and records what happens during the execution of the test.274     * Once the test is over, the Step Listener can provide the acceptance test outcome in the275     * form of an TestOutcome object.276     * @return the current step listener277     */278    protected JUnitStepListener getStepListener() {279        if (stepListener == null) {280            buildAndConfigureListeners();281        }282        return stepListener;283    }284    protected void setStepListener(JUnitStepListener stepListener) {285        this.stepListener = stepListener;286    }287    private void buildAndConfigureListeners() {288        initStepEventBus();289        if (webtestsAreSupported()) {290            ThucydidesWebDriverSupport.initialize(requestedDriver);291            WebDriver driver = ThucydidesWebDriverSupport.getWebdriverManager().getWebdriver();292            initPagesObjectUsing(driver);293            setStepListener(initListenersUsing(getPages()));294            initStepFactoryUsing(getPages());295        } else {296            setStepListener(initListeners());297            initStepFactory();298        }299    }300    private RunNotifier initializeRunNotifier(RunNotifier notifier) {301        notifier.addListener(getStepListener());302        return notifier;303    }304    private int maxRetries() {305        return TEST_RETRY_COUNT.integerFrom(configuration.getEnvironmentVariables(), 0);306    }307    protected void initStepEventBus() {308        StepEventBus.getEventBus().clear();309    }310    private void initPagesObjectUsing(final WebDriver driver) {311        pages = new Pages(driver, getConfiguration());312        dependencyInjector = new PageObjectDependencyInjector(pages);313    }314    protected JUnitStepListener initListenersUsing(final Pages pageFactory) {315        return JUnitStepListener.withOutputDirectory(getConfiguration().getOutputDirectory())316                .and().withPageFactory(pageFactory)317                .and().withTestClass(getTestClass().getJavaClass())318                .and().build();319    }320    protected JUnitStepListener initListeners() {321        return JUnitStepListener.withOutputDirectory(getConfiguration().getOutputDirectory())322                .and().withTestClass(getTestClass().getJavaClass())323                .and().build();324    }325    private boolean webtestsAreSupported() {326        return TestCaseAnnotations.supportsWebTests(this.getTestClass().getJavaClass());327    }328    private void initStepFactoryUsing(final Pages pagesObject) {329        stepFactory = StepFactory.getFactory().usingPages(pagesObject);330    }331    private void initStepFactory() {332        stepFactory = StepFactory.getFactory();333    }334    private ReportService getReportService() {335        if (reportService == null) {336            reportService = new ReportService(getOutputDirectory(), getDefaultReporters());337        }338        return reportService;339    }340    /**341     * A test runner can generate reports via Reporter instances that subscribe342     * to the test runner. The test runner tells the reporter what directory to343     * place the reports in. Then, at the end of the test, the test runner344     * notifies these reporters of the test outcomes. The reporter's job is to345     * process each test run outcome and do whatever is appropriate.346     *347     * @param testOutcomeResults the test results from the previous test run.348     */349    private void generateReportsFor(final List<TestOutcome> testOutcomeResults) {350        getReportService().generateReportsFor(testOutcomeResults);351        getReportService().generateConfigurationsReport();352    }353    @Override354    protected void runChild(FrameworkMethod method, RunNotifier notifier) {355        TestMethodConfiguration theMethod = TestMethodConfiguration.forMethod(method);356        clearMetadataIfRequired();357        resetStepLibrariesIfRequired();358        if(!failureRerunner.hasToRunTest(method.getDeclaringClass().getCanonicalName(),method.getMethod().getName()))359        {360            return;361        }362        if (shouldSkipTest(method)) {363            return;364        }365        if (theMethod.isManual()) {366            markAsManual(method).accept(notifier);367            return;368        } else if (theMethod.isPending()) {369            markAsPending(method);370            notifier.fireTestIgnored(describeChild(method));371            return;372        } else {373            processTestMethodAnnotationsFor(method);374        }375        initializeTestSession();376        prepareBrowserForTest();377        additionalBrowserCleanup();378        performRunChild(method, notifier);379        if (failureDetectingStepListener.lastTestFailed() && maxRetries() > 0) {380            retryAtMost(maxRetries(), new RerunSerenityTest(method, notifier));381        }382    }383    private void retryAtMost(int remainingTries,384                             RerunTest rerunTest) {385        if (remainingTries <= 0) { return; }386        logger.info(rerunTest.toString() + ": attempt " + (maxRetries() - remainingTries));387        StepEventBus.getEventBus().cancelPreviousTest();388        rerunTest.perform();389        if (failureDetectingStepListener.lastTestFailed()) {390            retryAtMost(remainingTries - 1, rerunTest);391        } else {392            StepEventBus.getEventBus().lastTestPassedAfterRetries(remainingTries,393                                                                  failureDetectingStepListener.getFailureMessages(),failureDetectingStepListener.getTestFailureCause());394        }395    }396    private void performRunChild(FrameworkMethod method, RunNotifier notifier) {397        super.runChild(method, notifier);398    }399    interface RerunTest {400        void perform();401    }402    class RerunSerenityTest implements RerunTest {403        private final FrameworkMethod method;404        private final RunNotifier notifier;405        RerunSerenityTest(FrameworkMethod method, RunNotifier notifier) {406            this.method = method;407            this.notifier = notifier;408        }409        @Override410        public void perform() {411            performRunChild(method, notifier);412        }413        @Override414        public String toString() {415            return "Retrying " + method.getDeclaringClass() + " " + method.getMethod().getName();416        }417    }418    private void clearMetadataIfRequired() {419        if (theTest.shouldClearMetadata()) {420            Serenity.getCurrentSession().clearMetaData();421        }422    }423    private void resetStepLibrariesIfRequired() {424        if (theTest.shouldResetStepLibraries()) {425            stepFactory.reset();426        }427    }428    protected void additionalBrowserCleanup() {429        // Template method. Override this to do additional cleanup e.g. killing IE processes.430    }431    private boolean shouldSkipTest(FrameworkMethod method) {432        return !tagScanner.shouldRunMethod(getTestClass().getJavaClass(), method.getName());433    }434    private void markAsPending(FrameworkMethod method) {435        testStarted(method);436        StepEventBus.getEventBus().testPending();437        StepEventBus.getEventBus().testFinished();438    }439    private Consumer<RunNotifier> markAsManual(FrameworkMethod method) {440        TestMethodConfiguration theMethod = TestMethodConfiguration.forMethod(method);441        testStarted(method);442        StepEventBus.getEventBus().testIsManual();443        StepEventBus.getEventBus().getBaseStepListener().latestTestOutcome().ifPresent(444                outcome -> outcome.setResult(theMethod.getManualResult())445        );446        switch(theMethod.getManualResult()) {447            case SUCCESS:448                StepEventBus.getEventBus().testFinished();449                return (notifier -> notifier.fireTestFinished(Description.EMPTY));450            case FAILURE:451                Throwable failure = new ManualTestMarkedAsFailure(theMethod.getManualResultReason());452                StepEventBus.getEventBus().testFailed(failure);453                return (notifier -> notifier.fireTestFailure(454                        new Failure(Description.createTestDescription(method.getDeclaringClass(), method.getName()),failure)));455            case ERROR:456            case COMPROMISED:457            case UNSUCCESSFUL:458                Throwable error = new ManualTestMarkedAsError(theMethod.getManualResultReason());459                StepEventBus.getEventBus().testFailed(error);460                return (notifier -> notifier.fireTestFailure(461                        new Failure(Description.createTestDescription(method.getDeclaringClass(), method.getName()),error)));462            case IGNORED:463                StepEventBus.getEventBus().testIgnored();464                return (notifier -> notifier.fireTestIgnored(Description.createTestDescription(method.getDeclaringClass(), method.getName())));465            case SKIPPED:466                StepEventBus.getEventBus().testSkipped();467                return (notifier -> notifier.fireTestIgnored(Description.createTestDescription(method.getDeclaringClass(), method.getName())));468            default:469                StepEventBus.getEventBus().testPending();470                return (notifier -> notifier.fireTestIgnored(Description.createTestDescription(method.getDeclaringClass(), method.getName())));471        }472    }473    private void testStarted(FrameworkMethod method) {474        getStepListener().testStarted(Description.createTestDescription(method.getMethod().getDeclaringClass(), testName(method)));475    }476    /**477     * Process any Serenity annotations in the test class.478     * Ignored tests will just be skipped by JUnit - we need to ensure479     * that they are included in the Serenity reports480     * If a test method is pending, all the steps should be skipped.481     */482    private void processTestMethodAnnotationsFor(FrameworkMethod method) {483        if (isIgnored(method)) {484            testStarted(method);485            StepEventBus.getEventBus().testIgnored();486            StepEventBus.getEventBus().testFinished();487        }488    }489    protected void prepareBrowserForTest() {490        if (theTest.shouldClearTheBrowserSession()) {491            WebdriverProxyFactory.clearBrowserSession(getDriver());492        }493    }494    /**495     * Running a unit test, which represents a test scenario.496     */497    @Override498    protected Statement methodInvoker(final FrameworkMethod method, final Object test) {499        if (webtestsAreSupported()) {500            injectDriverInto(test);501            initPagesObjectUsing(driverFor(method));502            injectAnnotatedPagesObjectInto(test);503            initStepFactoryUsing(getPages());504        }505        injectScenarioStepsInto(test);506        injectEnvironmentVariablesInto(test);507        useStepFactoryForDataDrivenSteps();508        Statement baseStatement = super.methodInvoker(method, test);509        return new SerenityStatement(baseStatement, stepListener.getBaseStepListener());510    }511    private void useStepFactoryForDataDrivenSteps() {512        StepData.setDefaultStepFactory(stepFactory);513    }514    /**515     * Instantiate the @Managed-annotated WebDriver instance with current WebDriver.516     * @param testCase A Serenity-annotated test class517     */518    protected void injectDriverInto(final Object testCase) {519        TestCaseAnnotations.forTestCase(testCase).injectDrivers(ThucydidesWebDriverSupport.getDriver(),520                                                                ThucydidesWebDriverSupport.getWebdriverManager());521        dependencyInjector.injectDependenciesInto(testCase);522    }523    protected WebDriver driverFor(final FrameworkMethod method) {524        if (TestMethodAnnotations.forTest(method).isDriverSpecified()) {525            String testSpecificDriver = TestMethodAnnotations.forTest(method).specifiedDriver();526            return getDriver(testSpecificDriver);527        } else {528            return getDriver();529        }530    }531    /**532     * Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.533     * @param testCase A Serenity-annotated test class534     */535    protected void injectScenarioStepsInto(final Object testCase) {536        StepAnnotations.injector().injectScenarioStepsInto(testCase, stepFactory);537    }538    /**539     * Instantiates the @ManagedPages-annotated Pages instance using current WebDriver.540     * @param testCase A Serenity-annotated test class541         */542    protected void injectAnnotatedPagesObjectInto(final Object testCase) {543        StepAnnotations.injector().injectAnnotatedPagesObjectInto(testCase, pages);544    }545    protected void injectEnvironmentVariablesInto(final Object testCase) {546        EnvironmentDependencyInjector environmentDependencyInjector = new EnvironmentDependencyInjector();547        environmentDependencyInjector.injectDependenciesInto(testCase);548    }549    protected WebDriver getDriver() {550        return (isEmpty(requestedDriver)) ? ThucydidesWebDriverSupport.getWebdriverManager().getWebdriver()551                : ThucydidesWebDriverSupport.getWebdriverManager().getWebdriver(requestedDriver);552    }553    protected WebDriver getDriver(final String driver) {554        return (isEmpty(driver)) ? ThucydidesWebDriverSupport.getWebdriverManager().getWebdriver()555                                 : ThucydidesWebDriverSupport.getWebdriverManager().getWebdriver(driver);556    }557    /**558     * Find the current set of test outcomes produced by the test execution.559     * @return the current list of test outcomes560     */561    public List<TestOutcome> getTestOutcomes() {562        return getStepListener().getTestOutcomes();563    }564    /**565     *  @return The default reporters applicable for standard test runs.566     */567    protected Collection<AcceptanceTestReporter> getDefaultReporters() {568        return ReportService.getDefaultReporters();569    }570}...Source:FailureRerunner.java  
1package net.serenitybdd.junit.runners;2import java.util.List;3import java.util.Map;4public interface FailureRerunner {5    /**6     * Stores failed tests.7     *8     * @param failedTests map keys are class names, values lists with failed method names9     */10    public void recordFailedTests(Map<String, List<String>> failedTests);11    /**12     * Returns true if a test given by className and method name has to be run.13     * @param className14     * @param methodName15     */16    public boolean hasToRunTest(String className, String methodName);17}...Interface FailureRerunner
Using AI Code Generation
1import net.serenitybdd.junit.runners.SerenityRunner;2import net.serenitybdd.junit.runners.SerenityRunner.FailureRerunner;3import org.junit.runner.Description;4import org.junit.runner.notification.Failure;5import org.junit.runner.notification.RunNotifier;6import org.junit.runners.model.InitializationError;7public class CustomSerenityRunner extends SerenityRunner {8  public CustomSerenityRunner(Class<?> klass) throws InitializationError {9    super(klass);10  }11  public void run(RunNotifier notifier) {12    super.run(new RunNotifier() {13      public void fireTestFailure(Failure failure) {14        if (isFailureOfInterest(failure)) {15          FailureRerunner rerunner = new FailureRerunner(failure.getDescription(), CustomSerenityRunner.this);16          rerunner.run(this);17        } else {18          super.fireTestFailure(failure);19        }20      }21    });22  }23  private boolean isFailureOfInterest(Failure failure) {24    Description description = failure.getDescription();25    return description.getTestClass().equals(YourTest.class) && description.getMethodName().equals("yourTest");26  }27}28package net.serenitybdd.junit.runners;29import org.junit.runner.Description;30import org.junit.runner.notification.Failure;31import org.junit.runner.notification.RunNotifier;32public interface FailureRerunner {33  void run(RunNotifier notifier);34  class FailureRerunnerFactory {35    public static FailureRerunner create(Failure failure, SerenityRunner runner) {36      Description description = failure.getDescription();37      return new DefaultFailureRerunner(description, runner);38    }39  }40  class DefaultFailureRerunner implements FailureRerunner {41    private final Description description;42    private final SerenityRunner runner;43    public DefaultFailureRerunner(Description description, SerenityRunner runner) {44      this.description = description;45      this.runner = runner;46    }47    public void run(RunNotifier notifier) {48      runner.runChild(description, notifier);49    }50  }51}52package net.serenitybdd.junit.runners;53import org.junit.runner.Description;54import org.junit.runner.notification.Failure;55import org.junit.runner.notification.RunNotifier;56public interface FailureRerunner {57  void run(RunNotifier notifier);58  class FailureRerunnerFactory {59    public static FailureRerunner create(Failure failureInterface FailureRerunner
Using AI Code Generation
1import net.serenitybdd.junit.runners.SerenityRunner;2import net.serenitybdd.junit.runners.SerenityRunner.FailureRerunner;3@RunWith(SerenityRunner.class)4public class SampleTest {5    public void test() {6        assertThat(true, is(false));7    }8}9import org.junit.runner.RunWith;10import org.junit.runners.Suite;11import org.junit.runners.model.InitializationError;12@RunWith(Suite.class)13@Suite.SuiteClasses({SampleTest.class})14public class SampleTest extends Suite {15    public SampleTest(Class<?> klass) throws InitializationError {16        super(klass, new FailureRerunner());17    }18}19    public void test() {20        assertThat(true, is(false));21    }22import org.junit.runner.RunWith;23import org.junit.runners.Suite;24import org.junit.runners.model.InitializationError;25@RunWith(Suite.class)26@Suite.SuiteClasses({SampleTest.class})27public class SampleTest extends Suite {28    public SampleTest(Class<?> klass) throws InitializationError {29        super(klass, new FailureRerunner());30    }31}32    public void test() {33        assertThat(true, is(false));34    }35import net.serenitybdd.junit.runners.SerenityRunner;36import net.serenitybdd.junit.runners.SerenityRunner.FailureRerunner;37@RunWith(SerenityRunner.class)38public class SampleTest {39    public void test() {40        assertThat(true, is(false));41    }42}43import org.junit.runner.RunWith;44import org.junit.runners.Suite;45import org.junit.runners.model.InitializationError;46@RunWith(Suite.class)47@Suite.SuiteClasses({SampleTest.class})48public class SampleTest extends Suite {49    public SampleTest(Class<?> klass) throws InitializationError {50        super(klass, new FailureRerunner());51    }52}53    public void test() {54        assertThat(true, is(false));55    }56import net.serenitybdd.junit.runners.SerenityRunner;57import net.serenitybdd.junit.runners.SerenityRunner.FailureRerunner;58@RunWith(SerenityRunner.class)59public class SampleTest {60    public void test() {61        assertThat(true, is(false));62    }63}64import org.junit.runner.RunWith;65import org.junit.runners.SInterface FailureRerunner
Using AI Code Generation
1@RunWith(FailureRerunner.class) 2public class MyTest {3}4@RunWith(FailureRerunner.class) 5public class MyTest {6}7@RunWith(FailureRerunner.class) 8public class MyTest {9}10@RunWith(FailureRerunner.class) 11public class MyTest {12}13@RunWith(FailureRerunner.class) 14public class MyTest {15}16@RunWith(FailureRerunner.class) 17public class MyTest {18}19@RunWith(FailureRerunner.class) 20public class MyTest {21}22@RunWith(FailureRerunner.class) 23public class MyTest {24}25@RunWith(FailureRerunner.class) 26public class MyTest {27}28@RunWith(FailureRerunner.class) 29public class MyTest {30}31@RunWith(FailureRerunner.class) 32public class MyTest {33}34@RunWith(FailureRerunner.class) 35public class MyTest {36}37@RunWith(FailureRerunner.class) 38public class MyTest {39}40@RunWith(FailureRerunner.class) 41public class MyTest {42}Interface FailureRerunner
Using AI Code Generation
1public class MyTest {2    public void should_fail() {3        assertThat(true, is(false));4    }5}6public class MyTest {7    public void should_fail() {8        assertThat(true, is(false));9    }10}11public class MyTest {12    public void should_fail() {13        assertThat(true, is(false));14    }15}16public class MyTest {17    public void should_fail() {18        assertThat(true, is(false));19    }20}21public class MyTest {22    public void should_fail() {23        assertThat(true, is(false));24    }25}26public class MyTest {27    public void should_fail() {28        assertThat(true, is(false));29    }30}31public class MyTest {32    public void should_fail() {33        assertThat(true, is(false));34    }35}36public class MyTest {37    public void should_fail() {38        assertThat(true, is(false));39    }40}41public class MyTest {42    public void should_fail() {43        assertThat(true, is(false));44    }45}46public class MyTest {47    public void should_fail() {48        assertThat(true, is(false));49    }50}51public class MyTest {52    public void should_fail() {53        assertThat(true, is(false));54    }55}Interface FailureRerunner
Using AI Code Generation
1public class RerunFailedTests implements FailureRerunner {2    public void rerun(RunNotifier notifier) {3        notifier.fireTestFailure(new Failure(Description.createTestDescription("Test", "Test"), new Throwable()));4    }5}6@RunWith(RerunFailedTestsRunner.class)7public class RerunFailedTestsRunnerTest {8    public void test() {9        System.out.println("Test");10    }11}12@Tags({@Tag("tag1"), @Tag("tag2")})13public class TestClass {14    public void test() {15        System.out.println("test");16    }17}18@Tags({@Tag("tag1"), @Tag("tag2")})19public class TestClass {20    public void test() {21        System.out.println("test");22    }23}24@Tags({@Tag("tag1"), @Tag("tag2")})25public class TestClass {26    public void test() {27        System.out.println("test");28    }29}Interface FailureRerunner
Using AI Code Generation
1@WithFailureRerunner(InterfaceFailureRerunner.class)2public class TestWithFailureRerunner {3    public void shouldAlwaysFail() {4        assertThat(true, is(false));5    }6}7@WithFailureRerunner(ClassFailureRerunner.class)8public class TestWithFailureRerunner {9    public void shouldAlwaysFail() {10        assertThat(true, is(false));11    }12}13@WithFailureRerunner(CustomFailureRerunner.class)14public class TestWithFailureRerunner {15    public void shouldAlwaysFail() {16        assertThat(true, is(false));17    }18}19@WithFailureRerunner(CustomFailureRerunner.class)20public class TestWithFailureRerunner {21    public void shouldAlwaysFail() {22        assertThat(true, is(false));23    }24}25@WithFailureRerunner(CustomFailureRerunner.class)26public class TestWithFailureRerunner {27    public void shouldAlwaysFail() {28        assertThat(true, is(false));29    }30}31@WithFailureRerunner(CustomFailureRerunner.class)32public class TestWithFailureRerunner {33    public void shouldAlwaysFail() {34        assertThat(true, is(false));35    }36}37@WithFailureRerunner(CustomFailureRerunner.class)38public class TestWithFailureRerunner {39    public void shouldAlwaysFail() {40        assertThat(true, is(false));41    }42}43@WithFailureRerunner(CustomFailureRerunner.class)44public class TestWithFailureRerunner {45    public void shouldAlwaysFail() {46        assertThat(true, is(false));47    }Interface FailureRerunner
Using AI Code Generation
1@Named("rerunFailedTests")2public class RerunFailedTests implements Interface FailureRerunner {3    public boolean rerunFailedTests() {4        return true;5    }6}7@Named("rerunFailedTests")8public class RerunFailedTests implements Interface FailureRerunner {9    public boolean rerunFailedTests() {10        return true;11    }12}13@Named("rerunFailedTests")14public class RerunFailedTests implements Interface FailureRerunner {15    public boolean rerunFailedTests() {16        return true;17    }18}19@Named("rerunFailedTests")20public class RerunFailedTests implements Interface FailureRerunner {21    public boolean rerunFailedTests() {22        return true;23    }24}25@Named("rerunFailedTests")26public class RerunFailedTests implements Interface FailureRerunner {27    public boolean rerunFailedTests() {28        return true;29    }30}31@Named("rerunFailedTests")32public class RerunFailedTests implements Interface FailureRerunner {33    public boolean rerunFailedTests() {34        return true;35    }36}37@Named("rerunFailedTests")38public class RerunFailedTests implements Interface FailureRerunner {39    public boolean rerunFailedTests() {40        return true;41    }42}Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
