Skip to content

Commit

Permalink
Implementing a rule for RC tests to take into account runOnly and method
Browse files Browse the repository at this point in the history
options
  • Loading branch information
barancev committed Mar 1, 2013
1 parent 019f066 commit b28ccfc
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
import com.google.common.io.Resources;

import org.junit.After;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.ExternalResource;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.openqa.selenium.Build;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
Expand All @@ -49,6 +51,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

Expand Down Expand Up @@ -115,8 +118,7 @@ public static void initializeServer() {
seleniumServerUrl = env.getSeleniumServerUrl();
}

@Rule
public TestRule traceMethodName = new TestWatcher() {
public TestWatcher traceMethodName = new TestWatcher() {
@Override
protected void starting(Description description) {
super.starting(description);
Expand Down Expand Up @@ -206,11 +208,26 @@ protected void before() throws Throwable {
}
};

public TestWatcher filter = new TestWatcher() {
@Override
public Statement apply(Statement base, Description description) {
String onlyRun = System.getProperty("only_run");
Assume.assumeTrue(onlyRun == null ||
Arrays.asList(onlyRun.split(",")).contains(description.getTestClass().getSimpleName()));
String mth = System.getProperty("method");
Assume.assumeTrue(mth == null ||
Arrays.asList(mth.split(",")).contains(description.getMethodName()));
return super.apply(base, description);
}
};

@Rule
public TestRule chain =
RuleChain.outerRule(initializeSelenium)
RuleChain.outerRule(filter)
.around(initializeSelenium)
.around(returnFocusToMainWindow)
.around(addNecessaryJavascriptCommands);
.around(addNecessaryJavascriptCommands)
.around(traceMethodName);

@After
public void checkVerifications() {
Expand Down

0 comments on commit b28ccfc

Please sign in to comment.