How to use testStarted method of net.thucydides.junit.listeners.JUnitStepListener class

Best Serenity JUnit code snippet using net.thucydides.junit.listeners.JUnitStepListener.testStarted

Source:SerenityRunner.java Github

copy

Full Screen

...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) {...

Full Screen

Full Screen

Source:ThucydidesRunner.java Github

copy

Full Screen

...373    private boolean shouldSkipTest(FrameworkMethod method) {374        return !tagScanner.shouldRunMethod(getTestClass().getJavaClass(), method.getName());375    }376    private void markAsPending(FrameworkMethod method) {377        stepListener.testStarted(Description.createTestDescription(method.getMethod().getDeclaringClass(), testName(method)));378        StepEventBus.getEventBus().testPending();379        StepEventBus.getEventBus().testFinished();380    }381    /**382     * Process any Thucydides annotations in the test class.383     * Ignored tests will just be skipped by JUnit - we need to ensure384     * that they are included in the Thucydides reports385     * If a test method is pending, all the steps should be skipped.386     */387    private void processTestMethodAnnotationsFor(FrameworkMethod method) {388        if (isIgnored(method)) {389            stepListener.testStarted(Description.createTestDescription(method.getMethod().getDeclaringClass(), testName(method)));390            StepEventBus.getEventBus().testIgnored();391        }392    }393    private boolean isPending(FrameworkMethod method) {394        return method.getAnnotation(Pending.class) != null;395    }396    private boolean isIgnored(FrameworkMethod method) {397        return method.getAnnotation(Ignore.class) != null;398    }399    protected boolean restartBrowserBeforeTest() {400        return notAUniqueSession() || dueForPeriodicBrowserReset();401    }402    private boolean dueForPeriodicBrowserReset() {403        return shouldRestartEveryNthTest() && (currentTestNumber() % restartFrequency() == 0);...

Full Screen

Full Screen

Source:WhenListeningForTestEvents.java Github

copy

Full Screen

...63                                    .and().withTestClass(MyTestCase.class)64                                    .and().build();65        stepFactory = new StepFactory(pages);66        listener.testRunStarted(Description.createSuiteDescription(MyTestCase.class));67        listener.testStarted(Description.createTestDescription(MyTestCase.class,"app_should_work"));68    }69    private void setupFailureListener() throws Exception {70        failureTestListener = JUnitStepListener.withOutputDirectory(outputDirectory)71                .and().withPageFactory(pages)72                .and().withTestClass(ScenarioWithSomeFailingTests.class)73                .and().build();74        stepFactory = new StepFactory(pages);75        failureTestListener.testRunStarted(Description.createSuiteDescription(ScenarioWithSomeFailingTests.class));76        failureTestListener.testStarted(Description.createTestDescription(ScenarioWithSomeFailingTests.class,"app_should_work"));77    }78    @Test79    public void there_should_be_no_failing_steps_at_the_start_of_the_test() throws Exception {80        assertThat(listener.hasRecordedFailures(), is(false));81    }82    @Test83    public void a_junit_listener_should_record_test_results() throws Exception {84        Failure failure = new Failure(failureDescription, new AssertionError("Test failed."));85        failureTestListener.testRunStarted(Description.createSuiteDescription(ScenarioWithSomeFailingTests.class));86        failureTestListener.testStarted(Description.createTestDescription(ScenarioWithSomeFailingTests.class, "failingTest"));87        failureTestListener.testFailure(failure);88        assertThat(failureTestListener.hasRecordedFailures(), is(true));89        assertThat(failureTestListener.getError().getMessage(), is("Test failed."));90    }91    @Test92    public void a_junit_listener_should_keep_track_of_failed_test_steps() throws Exception {93        MyTestSteps steps =  stepFactory.getStepLibraryFor(MyTestSteps.class);94        steps.step1();95        steps.failingStep();96        assertThat(failureTestListener.hasRecordedFailures(), is(true));97        assertThat(failureTestListener.getError().getMessage(), is("Step failed"));98    }99    @Test100    public void a_junit_listener_should_keep_track_of_failed_non_step_methods() throws Exception {101        MyTestSteps steps =  stepFactory.getStepLibraryFor(MyTestSteps.class);102        steps.failingNormalMethod();103        assertThat(failureTestListener.hasRecordedFailures(), is(true));104        assertThat(failureTestListener.getError().getMessage(), endsWith("Method failed"));105    }106    @Test107    public void a_junit_listener_should_keep_track_of_failure_exceptions() throws Exception {108        Throwable cause = new AssertionError("Test failed");109        Failure failure = new Failure(failureDescription, cause);110        failureTestListener.testFailure(failure);111        assertThat(failureTestListener.getError().getMessage(), is("Test failed"));112    }113    @Test114    public void any_failing_test_steps_should_be_cleared_at_the_start_of_each_new_test() throws Exception {115        Failure failure = new Failure(failureDescription, new AssertionError("Test failed"));116        failureTestListener.testFailure(failure);117        assertThat(failureTestListener.hasRecordedFailures(), is(true));118        failureTestListener.testStarted(Description.createTestDescription(ScenarioWithSomeFailingTests.class,"app_should_still_work"));119        assertThat(failureTestListener.hasRecordedFailures(), is(false));120    }121    @Test122    public void any_failing_exceptions_should_be_cleared_at_the_start_of_each_new_test() throws Exception {123        Failure failure = new Failure(failureDescription, new AssertionError("Test failed"));124        failureTestListener.testFailure(failure);125        assertThat(failureTestListener.getError(), is(not(nullValue())));126        failureTestListener.testStarted(Description.createTestDescription(ScenarioWithSomeFailingTests.class,"app_should_still_work"));127        assertThat(failureTestListener.getError(), is(nullValue()));128    }129}...

Full Screen

Full Screen

Source:SerenityJUnitLifecycleAdapterExtension.java Github

copy

Full Screen

...70    private void notifyTestStarted(final ExtensionContext extensionContext, final String name) {71        startTestSuiteForFirstTest(extensionContext);72        getEventBus().clear();73        getEventBus().setTestSource(TEST_SOURCE_JUNIT.getValue());74        getEventBus().testStarted(name, extensionContext.getRequiredTestClass());75        getEventBus().addTagsToCurrentTest(extensionContext.getTags().stream().map(TestTag::withValue).collect(toList()));76    }77    private void startTestSuiteForFirstTest(ExtensionContext extensionContext) {78        if (!getEventBus().testSuiteHasStarted()) {79            getEventBus().testSuiteStarted(extensionContext.getRequiredTestClass());80        }81    }82    private void handleTestClassLevelLifecycleFailure(final ExtensionContext extensionContext, final Throwable throwable, final String scenario) throws Throwable {83        notifyTestStarted(extensionContext, scenario);84        testFailed(extensionContext, throwable);85        throw throwable;86    }87    private void notifyTestFinished() {88        getEventBus().testFinished();...

Full Screen

Full Screen

Source:JUnitStepListener.java Github

copy

Full Screen

...16public class JUnitStepListener extends RunListener {17    private BaseStepListener baseStepListener;18    private StepListener[] extraListeners;19    private Class<?> testClass;20    private boolean testStarted;21    public static JUnitStepListenerBuilder withOutputDirectory(File outputDirectory) {22        return new JUnitStepListenerBuilder(outputDirectory);     23    }24    25    protected JUnitStepListener(Class<?> testClass, BaseStepListener baseStepListener, StepListener... listeners) {26        testStarted = false;27        this.baseStepListener = baseStepListener;28        this.extraListeners = listeners;29        this.testClass = testClass;30        registerThucydidesListeners();31    }32    public void registerThucydidesListeners() {33        StepEventBus.getEventBus().registerListener(baseStepListener);34        for(StepListener listener : extraListeners) {35            StepEventBus.getEventBus().registerListener(listener);36        }37    }38    public BaseStepListener getBaseStepListener() {39        return baseStepListener;40    }41    @Override42    public void testRunStarted(Description description) throws Exception {43        super.testRunStarted(description);44    }45    @Override46    public void testRunFinished(Result result) throws Exception {47        StepEventBus.getEventBus().testRunFinished();48        super.testRunFinished(result);49    }50    /**51     * Called when a test starts. We also need to start the test suite the first52     * time, as the testRunStarted() method is not invoked for some reason.53     */54    @Override55    public void testStarted(final Description description) {56        if (testingThisTest(description)) {57            startTestSuiteForFirstTest(description);58            StepEventBus.getEventBus().clear();59            StepEventBus.getEventBus().testStarted(description.getMethodName(),60                                                   description.getTestClass());61            startTest();62        }63    }64    private void startTestSuiteForFirstTest(Description description) {65        if (!getBaseStepListener().testSuiteRunning()) {66            StepEventBus.getEventBus().testSuiteStarted(description.getTestClass());67        }68    }69    @Override70    public void testFinished(final Description description) throws Exception {71        if (testingThisTest(description)) {72            StepEventBus.getEventBus().testFinished();73            endTest();74        }75    }76    @Override77    public void testFailure(final Failure failure) throws Exception {78        if (testingThisTest(failure.getDescription())) {79            startTestIfNotYetStarted(failure.getDescription());80            StepEventBus.getEventBus().testFailed(failure.getException());81            endTest();82        }83    }84    private void startTestIfNotYetStarted(Description description) {85        if (!testStarted) {86           testStarted(description);87        }88    }89    @Override90    public void testIgnored(final Description description) throws Exception {91        if (testingThisTest(description)) {92            StepEventBus.getEventBus().testIgnored();93            endTest();94        }95    }96    public List<TestOutcome> getTestOutcomes() {97        return baseStepListener.getTestOutcomes();98    }99    public FailureCause getError() {100        return baseStepListener.getTestFailureCause();101    }102    public boolean hasRecordedFailures() {103        return baseStepListener.aStepHasFailed();104    }105    public void dropListeners() {106        StepEventBus.getEventBus().dropListener(baseStepListener);107        for(StepListener listener : extraListeners) {108            StepEventBus.getEventBus().dropListener(listener);109        }110    }111    private void startTest() {112        testStarted = true;113    }114    private void endTest() {115        testStarted = false;116    }117    private boolean testingThisTest(Description description) {118        return description.getTestClass().equals(testClass);119    }120    protected Class<?> getTestClass() {121        return testClass;122    }123}...

Full Screen

Full Screen

Source:ParameterizedJUnitStepListener.java Github

copy

Full Screen

...21    public void testRunStarted(Description description) throws Exception {22        super.testRunStarted(description);23    }24    @Override25    public void testStarted(final Description description) {26        if (testingThisDataSet(description)) {27            super.testStarted(description);28            StepEventBus.getEventBus().useExamplesFrom(dataTableRow());29            //StepEventBus.getEventBus().useExamplesFrom(dataTable());30            if (!ignoredOrPending(description))31                StepEventBus.getEventBus().exampleStarted(parametersTable.row(parameterSetNumber).toStringMap());32        }33    }34    private boolean isPending(Description description) {35        return  TestAnnotations.forClass(description.getTestClass()).isPending(description.getMethodName());36    }37    private boolean isIgnored(Description description) {38        return  TestAnnotations.forClass(description.getTestClass()).isIgnored(description.getMethodName());39    }40    private boolean ignoredOrPending(Description description) {41        return isIgnored(description) || isPending(description);...

Full Screen

Full Screen

testStarted

Using AI Code Generation

copy

Full Screen

1import net.thucydides.junit.listeners.JUnitStepListener;2import net.thucydides.core.steps.StepEventBus;3import net.thucydides.core.steps.StepListener;4StepListener stepListener = new JUnitStepListener();5StepEventBus.getEventBus().registerListener(stepListener);6import net.thucydides.junit.listeners.JUnitStepListener;7import net.thucydides.core.steps.StepEventBus;8import net.thucydides.core.steps.StepListener;9StepListener stepListener = new JUnitStepListener();10StepEventBus.getEventBus().registerListener(stepListener);11import net.thucydides.core.steps.StepEventBus;12import net.thucydides.core.steps.StepListener;13StepListener stepListener = new JUnitStepListener();14StepEventBus.getEventBus().registerListener(stepListener);15import net.thucydides.core.steps.StepEventBus;16import net.thucydides.core.steps.StepListener;17StepListener stepListener = new JUnitStepListener();18StepEventBus.getEventBus().registerListener(stepListener);19import net.thucydides.core.steps.StepEventBus;20import net.thucydides.core.steps.StepListener;21StepListener stepListener = new JUnitStepListener();22StepEventBus.getEventBus().registerListener(stepListener);23import net.thucydides.core.steps.StepEventBus;24import net.thucydides.core.steps.StepListener;25StepListener stepListener = new JUnitStepListener();26StepEventBus.getEventBus().registerListener(stepListener);27import net.thucydides.core.steps.StepEventBus;28import net.thucydides.core.steps.StepListener;29StepListener stepListener = new JUnitStepListener();30StepEventBus.getEventBus().registerListener(stepListener);

Full Screen

Full Screen

testStarted

Using AI Code Generation

copy

Full Screen

1public class TestListener extends JUnitStepListener {2    public void testStarted(Description description) throws Exception {3        super.testStarted(description);4        System.out.println("testStarted method is called");5    }6}7public class TestListener extends JUnitStepListener {8    public void testFinished(Description description) throws Exception {9        super.testFinished(description);10        System.out.println("testFinished method is called");11    }12}13public class TestListener extends JUnitStepListener {14    public void testFailure(Failure failure) throws Exception {15        super.testFailure(failure);16        System.out.println("testFailure method is called");17    }18}19public class TestListener extends JUnitStepListener {20    public void testIgnored(Description description) throws Exception {21        super.testIgnored(description);22        System.out.println("testIgnored method is called");23    }24}25public class TestListener extends JUnitStepListener {26    public void testRunStarted(Description description) throws Exception {27        super.testRunStarted(description);28        System.out.println("testRunStarted method is called");29    }30}31public class TestListener extends JUnitStepListener {32    public void testRunFinished(Result result) throws Exception {33        super.testRunFinished(result);34        System.out.println("testRunFinished method is called");35    }36}37public class TestListener extends JUnitStepListener {38    public void testAssumptionFailure(Failure failure) {39        super.testAssumptionFailure(failure);40        System.out.println("testAssumptionFailure method is called");41    }42}

Full Screen

Full Screen

testStarted

Using AI Code Generation

copy

Full Screen

1import net.thucydides.core.steps.StepEventBus;2import net.thucydides.junit.listeners.JUnitStepListener;3import org.junit.runner.Description;4import org.junit.runner.notification.RunListener;5public class MyListener extends RunListener {6    public void testStarted(Description description) throws Exception {7        String testName = description.getMethodName();8        String testName2 = StepEventBus.getEventBus().getCurrentStep();9        String testName3 = JUnitStepListener.getCurrentTestName();10    }11}

Full Screen

Full Screen

testStarted

Using AI Code Generation

copy

Full Screen

1import net.thucydides.core.annotations.*;2import net.thucydides.core.steps.*;3import net.thucydides.junit.listeners.JUnitStepListener;4import net.thucydides.junit.runners.*;5import net.thucydides.junit.annotations.*;6import net.thucydides.junit.annotations.Concurrent;7import net.thucydides.junit.annotations.Concurrent.Mode;8import net.thucydides.junit.annotations.Qualifier;9import net.thucydides.junit.annotations.Qualifier.Mode;10import net.thucydides.junit.annotations.Qualifiers;11import net.thucydides.junit.annotations.Qualifiers.Mode;12import net.thucydides.junit.annotations.TestData;13import net.thucydides.junit.annotations.UseTestDataFrom;14import net.thucydides.junit.annotations.UseTestDataFrom;15import net.thucydides.junit.annotations.UseTestDataFrom;16import net.thucydides.junit.annotations.UseTestDataFrom;17import net.thucydides.junit.annotations.UseTestDataFrom;18import net.thucydides.junit.annotations.UseTestDataFrom;19import net.thucydides.junit.annotations.UseTestDataFrom;20import net.thucydides.junit.annotations.UseTestDataFrom;21import net.thucydides.junit.annotations.UseTestDataFrom;22import net.thucydides.junit.annotations.UseTestDataFrom;23import net.thucydides.junit.annotations.UseTestDataFrom;24import net.thucydides.junit.annotations.UseTestDataFrom;25import org.junit.*;26import org.junit.runner.RunWith;27import org.junit.runner.notification.RunNotifier;28import org.junit.runners.model.InitializationError;29import org.junit.runners.model.TestClass;30import java.lang.annotation.*;31import java.lang.reflect.Method;32import java.util.*;33import static org.junit.Assert.*;34import static org.hamcrest.MatcherAssert.*;35import static org.hamcrest.Matchers.*;36import static org.hamcrest.Matchers.*;37import static org.hamcrest.Matchers.*;38import static org.hamcrest.Matchers.*;39import static org.hamcrest.Matchers.*;40import static org.hamcrest.Matchers.*;41import static org.hamcrest.Matchers.*;42import static org.hamcrest.Matchers.*;43import static org.hamcrest.Matchers.*;44import org.junit.Test;45import org.junit.runner.RunWith;46import org.junit.runners.Parameterized;47import org.junit.runners.Parameterized.Parameters;48import org.junit.runners.Parameterized.Parameter;49import java.util.Arrays;50import java

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Serenity JUnit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful