How to use JUnitStepListenerBuilder class of net.thucydides.junit.listeners package

Best Serenity JUnit code snippet using net.thucydides.junit.listeners.JUnitStepListenerBuilder

Run Serenity JUnit automation tests on LambdaTest cloud grid

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

copy
1package net.thucydides.junit.listeners;
2
3import com.google.inject.Key;
4import net.thucydides.core.model.DataTable;
5import net.thucydides.core.pages.Pages;
6import net.thucydides.core.steps.BaseStepListener;
7import net.thucydides.core.steps.Listeners;
8import net.thucydides.core.steps.StepListener;
9import net.thucydides.junit.guice.JUnitInjectors;
10import net.thucydides.junit.runners.ParameterizedJUnitStepListener;
11
12import java.io.File;
13
14public class JUnitStepListenerBuilder {
15    private final File outputDirectory;
16    private final Pages pageFactory;
17    private final int parameterSetNumber;
18    private final DataTable parametersTable;
19    private final Class<?> testClass;
20
21    public JUnitStepListenerBuilder(File outputDirectory) {
22        this(outputDirectory, null, -1, null);
23    }
24
25    public JUnitStepListenerBuilder(File outputDirectory,
26                                    Pages pageFactory) {
27        this(outputDirectory, pageFactory, -1, null);
28    }
29
30    public JUnitStepListenerBuilder(File outputDirectory,
31                                    Pages pageFactory,
32                                    int parameterSetNumber) {
33        this(outputDirectory, pageFactory, parameterSetNumber, null);
34    }
35
36    public JUnitStepListenerBuilder(File outputDirectory,
37                                    Pages pageFactory,
38                                    int parameterSetNumber,
39                                    DataTable parametersTable) {
40        this(outputDirectory, pageFactory, parameterSetNumber, parametersTable, null);
41    }
42
43    public JUnitStepListenerBuilder(File outputDirectory,
44                                    Pages pageFactory,
45                                    int parameterSetNumber,
46                                    DataTable parametersTable,
47                                    Class<?> testClass) {
48        this.outputDirectory = outputDirectory;
49        this.pageFactory = pageFactory;
50        this.parameterSetNumber = parameterSetNumber;
51        this.parametersTable = parametersTable;
52        this.testClass = testClass;
53    }
54
55    public JUnitStepListenerBuilder and() {
56        return this;
57    }
58
59    public JUnitStepListenerBuilder withPageFactory(Pages pageFactory) {
60        return new JUnitStepListenerBuilder(outputDirectory, pageFactory);
61    }
62
63    public JUnitStepListenerBuilder withParameterSetNumber(int parameterSetNumber) {
64        return new JUnitStepListenerBuilder(outputDirectory, pageFactory, parameterSetNumber);
65    }
66
67    public JUnitStepListenerBuilder withParametersTable(DataTable parametersTable) {
68        return new JUnitStepListenerBuilder(outputDirectory, pageFactory, parameterSetNumber, parametersTable);
69    }
70
71    public JUnitStepListenerBuilder withTestClass(Class<?> testClass) {
72        return new JUnitStepListenerBuilder(outputDirectory, pageFactory, parameterSetNumber, parametersTable, testClass);
73    }
74
75    public JUnitStepListener build() {
76        if (parameterSetNumber >= 0) {
77            return newParameterizedJUnitStepListener();
78        } else {
79            return newStandardJunitStepListener();
80        }
81    }
82
83    private BaseStepListener buildBaseStepListener() {
84        if (pageFactory != null) {
85            return Listeners.getBaseStepListener()
86                    .withPages(pageFactory)
87                    .and().withOutputDirectory(outputDirectory);
88        } else {
89            return Listeners.getBaseStepListener()
90                    .withOutputDirectory(outputDirectory);
91        }
92    }
93
94    private JUnitStepListener newParameterizedJUnitStepListener() {
95        return new ParameterizedJUnitStepListener(parameterSetNumber,
96                parametersTable,
97                testClass,
98                buildBaseStepListener(),
99                Listeners.getLoggingListener(),
100                newTestCountListener());
101//                Listeners.getStatisticsListener());
102    }
103
104    private StepListener newTestCountListener() {
105        return JUnitInjectors.getInjector().getInstance(Key.get(StepListener.class, TestCounter.class));
106    }
107
108    private JUnitStepListener newStandardJunitStepListener() {
109        return new JUnitStepListener(testClass,
110                buildBaseStepListener(),
111                Listeners.getLoggingListener(),
112                newTestCountListener());
113//                Listeners.getStatisticsListener());
114    }
115
116}
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 popular Stackoverflow questions on JUnitStepListenerBuilder

    No relevant questions found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)