How to use testRunStarted method of net.serenitybdd.junit.runners.ParameterizedJUnitStepListener class

Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.ParameterizedJUnitStepListener.testRunStarted

Run Serenity JUnit automation tests on LambdaTest cloud grid

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

copy
1package net.serenitybdd.junit.runners;
2
3import net.thucydides.core.annotations.TestAnnotations;
4import net.thucydides.core.model.DataTable;
5import net.thucydides.core.steps.BaseStepListener;
6import net.thucydides.core.steps.StepEventBus;
7import net.thucydides.core.steps.StepListener;
8import net.thucydides.junit.listeners.JUnitStepListener;
9import org.junit.runner.Description;
10import org.junit.runner.notification.Failure;
11
12public class ParameterizedJUnitStepListener extends JUnitStepListener {
13
14    final int parameterSetNumber;
15    private final DataTable parametersTable;
16
17    public ParameterizedJUnitStepListener(final int parameterSetNumber, final DataTable parametersTable,
18                                          final Class<?> testClass, BaseStepListener baseStepListener,
19                                          StepListener... listeners) {
20        super(testClass, baseStepListener, listeners);
21        this.parameterSetNumber = parameterSetNumber;
22        this.parametersTable = parametersTable;
23    }
24
25    @Override
26    public void testRunStarted(Description description) throws Exception {
27
28        super.testRunStarted(description);
29    }
30
31
32    @Override
33    public void testStarted(final Description description) {
34        if (testingThisDataSet(description)) {
35            super.testStarted(description);
36            StepEventBus.getEventBus().useExamplesFrom(dataTableRow());
37            if (!ignoredOrPending(description))
38                StepEventBus.getEventBus().exampleStarted(parametersTable.row(parameterSetNumber).toStringMap());
39        }
40    }
41
42    private boolean isPending(Description description) {
43        return  TestAnnotations.forClass(description.getTestClass()).isPending(description.getMethodName());
44    }
45
46    private boolean isIgnored(Description description) {
47        return  TestAnnotations.forClass(description.getTestClass()).isIgnored(description.getMethodName());
48    }
49
50    private boolean ignoredOrPending(Description description) {
51        return isIgnored(description) || isPending(description);
52    }
53
54    private DataTable dataTableRow() {
55        return DataTable.withHeaders(parametersTable.getHeaders()).andCopyRowDataFrom(parametersTable.getRows().get(parameterSetNumber)).build();
56    }
57
58    private DataTable dataTable() {
59        return DataTable.withHeaders(parametersTable.getHeaders()).andRowData (parametersTable.getRows()).build();
60    }
61
62    private boolean testingThisDataSet(Description description) {
63        return ((description.getTestClass().equals(getTestClass())) &&
64                (description.getMethodName().endsWith("[" + parameterSetNumber + "]")));
65    }
66
67    @Override
68    public void testFinished(final Description description) throws Exception {
69        if (testingThisDataSet(description)) {
70            super.testFinished(description);
71            StepEventBus.getEventBus().exampleFinished();
72        }
73    }
74
75    @Override
76    public void testFailure(final Failure failure) throws Exception {
77        if (testingThisDataSet(failure.getDescription())) {
78            super.testFailure(failure);
79            StepEventBus.getEventBus().exampleFinished();
80        }
81    }
82
83    @Override
84    public void testIgnored(final Description description) throws Exception {
85        if (testingThisDataSet(description))
86        {
87            super.testIgnored(description);
88            if (!ignoredOrPending(description)){
89                StepEventBus.getEventBus().exampleFinished();
90            }
91        }
92    }
93
94}
95
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in ParameterizedJUnitStepListener

Trigger testRunStarted code on LambdaTest Cloud Grid

Execute automation tests with testRunStarted on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)