How to use forClass method of net.serenitybdd.junit.runners.TestConfiguration class

Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.TestConfiguration.forClass

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.ThucydidesSystemProperty;
4import net.thucydides.core.annotations.TestCaseAnnotations;
5import net.thucydides.core.webdriver.Configuration;
6import org.junit.runners.model.TestClass;
7
8public class TestConfiguration {
9
10
11    private final Class<?> testClass;
12    private final Configuration configuration;
13    private final TestClassAnnotations theTestIsAnnotated;
14
15    public TestConfiguration(Class<?> testClass, Configuration configuration) {
16        this.testClass = testClass;
17        this.configuration = configuration;
18        this.theTestIsAnnotated = TestClassAnnotations.forTestClass(testClass);
19    }
20
21    public boolean shouldClearMetadata() {
22        return (!ThucydidesSystemProperty.THUCYDIDES_MAINTAIN_SESSION.booleanFrom(configuration.getEnvironmentVariables()));
23    }
24
25    public static TestConfigurationBuilder forClass(Class<?> testClass) {
26        return new TestConfigurationBuilder(testClass);
27    }
28
29    protected boolean isUniqueSession() {
30        return (theTestIsAnnotated.toUseAUniqueSession() || configuration.shouldUseAUniqueBrowser());
31    }
32
33    public boolean shouldClearTheBrowserSession() {
34        return (isAWebTest() && TestCaseAnnotations.shouldClearCookiesBeforeEachTestIn(testClass().getJavaClass()));
35    }
36
37    public boolean shouldResetStepLibraries() {
38        return !TestCaseAnnotations.shouldUsePersistantStepLibraries(testClass);
39    }
40
41    public static class TestConfigurationBuilder {
42
43        private final Class<?> testClass;
44
45        public TestConfigurationBuilder(Class<?> testClass) {
46            this.testClass = testClass;
47        }
48
49        public TestConfiguration withSystemConfiguration(Configuration configuration) {
50            return new TestConfiguration(testClass, configuration);
51        }
52    }
53
54    private TestClass testClass() {
55        return new TestClass(testClass);
56    }
57
58    public boolean isAWebTest() {
59        return TestCaseAnnotations.isWebTest(testClass().getJavaClass());
60    }
61
62}
63
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

Trigger forClass code on LambdaTest Cloud Grid

Execute automation tests with forClass 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)