-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/PageUrlAnnotation
- Loading branch information
Showing
39 changed files
with
598 additions
and
435 deletions.
There are no files selected for viewing
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
95 changes: 6 additions & 89 deletions
95
fluentlenium-core/src/main/java/org/fluentlenium/adapter/FluentTest.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 |
---|---|---|
@@ -1,125 +1,42 @@ | ||
package org.fluentlenium.adapter; | ||
|
||
import org.fluentlenium.adapter.util.ShutdownHook; | ||
import org.fluentlenium.core.FluentAdapter; | ||
import org.fluentlenium.core.FluentPage; | ||
import org.junit.AfterClass; | ||
import org.junit.Rule; | ||
import org.junit.rules.TestName; | ||
import org.junit.rules.TestRule; | ||
import org.junit.rules.TestWatcher; | ||
import org.junit.runner.Description; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
import static org.fluentlenium.adapter.util.SharedDriverHelper.*; | ||
|
||
/** | ||
* All Junit Test should extends this class. It provides default parameters. | ||
*/ | ||
public abstract class FluentTest extends FluentAdapter { | ||
private static WebDriver sharedDriver; | ||
private static boolean isSharedDriverPerClass; | ||
|
||
public abstract class FluentTest extends FluentTestRunnerAdapter { | ||
@Rule | ||
public TestName name = new TestName(); | ||
@Rule | ||
public TestRule watchman = new TestWatcher() { | ||
@Override | ||
public void starting(Description description) { | ||
super.starting(description); | ||
//TODO Refactor | ||
if (isSharedDriverOnce(description.getTestClass())) { | ||
synchronized (this) { | ||
if (sharedDriver == null) { | ||
initFluentFromDefaultDriver(); | ||
sharedDriver = getDriver(); | ||
killTheBrowserOnShutdown(); | ||
} else { | ||
initFluentWithExistingDriver(); | ||
} | ||
} | ||
} else if (isSharedDriverPerClass(description.getTestClass())) { | ||
synchronized (this) { | ||
if (!isSharedDriverPerClass) { | ||
initFluentFromDefaultDriver(); | ||
sharedDriver = getDriver(); | ||
isSharedDriverPerClass = true; | ||
} else { | ||
initFluentWithExistingDriver(); | ||
} | ||
} | ||
} else { | ||
initFluentFromDefaultDriver(); | ||
} | ||
|
||
initTest(); | ||
setDefaultConfig(); | ||
FluentTest.this.starting(description.getTestClass(), description.getDisplayName()); | ||
} | ||
|
||
|
||
@Override | ||
public void finished(Description description) { | ||
super.finished(description); | ||
if (isSharedDriverPerMethod(description.getTestClass()) || | ||
isDefaultSharedDriver(description.getTestClass())) { | ||
quit(); | ||
} else if (isDeleteCookies(description.getTestClass())) { | ||
if (sharedDriver != null) { | ||
sharedDriver.manage().deleteAllCookies(); | ||
} | ||
} | ||
FluentTest.this.finished(description.getTestClass(), description.getDisplayName()); | ||
} | ||
|
||
@Override | ||
public void failed(Throwable e, Description description) { | ||
if (screenshotMode == TriggerMode.ON_FAIL) { | ||
takeScreenShot(description.getTestClass().getSimpleName() + "_" + | ||
description.getMethodName() + ".png"); | ||
} | ||
if (htmlDumpMode == TriggerMode.ON_FAIL) { | ||
takeHtmlDump(description.getTestClass().getSimpleName() + "_" | ||
+ description.getMethodName() + ".html"); | ||
} | ||
super.failed(e, description); | ||
FluentTest.this.failed(e, description.getTestClass(), description.getDisplayName()); | ||
} | ||
|
||
}; | ||
|
||
private void killTheBrowserOnShutdown() { | ||
Runtime.getRuntime().addShutdownHook(new ShutdownHook("fluentlenium", this)); | ||
} | ||
|
||
private void initFluentWithExistingDriver() { | ||
initFluent(sharedDriver).withDefaultUrl(getDefaultBaseUrl()); | ||
} | ||
|
||
private void initFluentFromDefaultDriver() { | ||
initFluent(getDefaultDriver()).withDefaultUrl(getDefaultBaseUrl()); | ||
} | ||
|
||
|
||
public FluentTest() { | ||
super(); | ||
} | ||
|
||
|
||
@AfterClass | ||
public static void afterClass() { | ||
if (isSharedDriverPerClass) { | ||
sharedDriver.quit(); | ||
sharedDriver = null; | ||
isSharedDriverPerClass = false; | ||
} | ||
FluentTestRunnerAdapter.releaseSharedDriver(); | ||
} | ||
|
||
/** | ||
* Override this method to change the default time to wait for a page to be loaded | ||
*/ | ||
public void setDefaultConfig() { | ||
} | ||
|
||
public static void assertAt(FluentPage fluent) { | ||
fluent.isAt(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.