-
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests can now manage whether cookies should be cleared between each test
- Loading branch information
Showing
11 changed files
with
199 additions
and
69 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
serenity-core/src/main/java/net/thucydides/core/annotations/ClearCookiesPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.thucydides.core.annotations; | ||
|
||
public enum ClearCookiesPolicy { | ||
Never, BeforeEachTest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
serenity-junit/src/main/java/net/serenitybdd/junit/runners/TestClassAnnotations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.serenitybdd.junit.runners; | ||
|
||
import net.thucydides.core.annotations.TestCaseAnnotations; | ||
import org.junit.runners.model.TestClass; | ||
|
||
/** | ||
* Created by john on 4/02/2016. | ||
*/ | ||
public class TestClassAnnotations { | ||
|
||
|
||
private final TestClass testClass; | ||
|
||
public TestClassAnnotations(Class<?> testClass) { | ||
this.testClass = new TestClass(testClass); | ||
} | ||
|
||
public static TestClassAnnotations forTestClass(Class<?> testClass) { | ||
return new TestClassAnnotations(testClass); | ||
} | ||
|
||
public boolean toUseAUniqueSession() { | ||
return TestCaseAnnotations.isUniqueSession(testClass.getJavaClass()); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
serenity-junit/src/main/java/net/serenitybdd/junit/runners/TestConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package net.serenitybdd.junit.runners; | ||
|
||
import net.thucydides.core.ThucydidesSystemProperty; | ||
import net.thucydides.core.annotations.TestCaseAnnotations; | ||
import net.thucydides.core.guice.Injectors; | ||
import net.thucydides.core.statistics.TestCount; | ||
import net.thucydides.core.webdriver.Configuration; | ||
import org.junit.runners.model.TestClass; | ||
|
||
public class TestConfiguration { | ||
|
||
|
||
private final Class<?> testClass; | ||
private final Configuration configuration; | ||
private final TestCount testCount; | ||
private final TestClassAnnotations theTestIsAnnotated; | ||
|
||
public TestConfiguration(Class<?> testClass, Configuration configuration) { | ||
this.testClass = testClass; | ||
this.configuration = configuration; | ||
this.testCount = Injectors.getInjector().getInstance(TestCount.class); | ||
this.theTestIsAnnotated = TestClassAnnotations.forTestClass(testClass); | ||
} | ||
|
||
public boolean shouldRetryTest() { | ||
return (ThucydidesSystemProperty.JUNIT_RETRY_TESTS.booleanFrom(configuration.getEnvironmentVariables())); | ||
} | ||
|
||
public int getMaxRetries() { | ||
return shouldRetryTest() ? configuration.maxRetries() : 0; | ||
} | ||
|
||
public boolean shouldClearMetadata() { | ||
return (!ThucydidesSystemProperty.THUCYDIDES_MAINTAIN_SESSION.booleanFrom(configuration.getEnvironmentVariables())); | ||
} | ||
|
||
public static TestConfigurationBuilder forClass(Class<?> testClass) { | ||
return new TestConfigurationBuilder(testClass); | ||
} | ||
|
||
public boolean needsToRestartTheBrowser() { | ||
return (isAWebTest() && restartBrowserBeforeTest()); | ||
} | ||
|
||
protected boolean restartBrowserBeforeTest() { | ||
return notAUniqueSession() || dueForPeriodicBrowserReset(); | ||
} | ||
|
||
private boolean dueForPeriodicBrowserReset() { | ||
return shouldRestartEveryNthTest() && (currentTestNumber() % restartFrequency() == 0); | ||
} | ||
|
||
private boolean notAUniqueSession() { | ||
return !isUniqueSession(); | ||
} | ||
|
||
protected boolean isUniqueSession() { | ||
return (theTestIsAnnotated.toUseAUniqueSession() || configuration.shouldUseAUniqueBrowser()); | ||
} | ||
|
||
protected boolean shouldRestartEveryNthTest() { | ||
return (restartFrequency() > 0); | ||
} | ||
|
||
protected int restartFrequency() { | ||
return configuration.getRestartFrequency(); | ||
} | ||
|
||
protected int currentTestNumber() { | ||
return testCount.getCurrentTestNumber(); | ||
} | ||
|
||
public boolean shouldClearTheBrowserSession() { | ||
return (isAWebTest() && TestCaseAnnotations.shouldClearCookiesBeforeEachTestIn(testClass().getJavaClass())); | ||
} | ||
|
||
public static class TestConfigurationBuilder { | ||
|
||
private final Class<?> testClass; | ||
|
||
public TestConfigurationBuilder(Class<?> testClass) { | ||
TestClass t = new TestClass(testClass); | ||
this.testClass = testClass; | ||
} | ||
|
||
public TestConfiguration withSystemConfiguration(Configuration configuration) { | ||
return new TestConfiguration(testClass, configuration); | ||
} | ||
} | ||
|
||
private TestClass testClass() { | ||
return new TestClass(testClass); | ||
} | ||
|
||
public boolean isAWebTest() { | ||
return TestCaseAnnotations.isWebTest(testClass().getJavaClass()); | ||
} | ||
|
||
} |
Oops, something went wrong.