diff --git a/performancetest-demo-framework/pom.xml b/performancetest-demo-framework/pom.xml index a51861d..c85cd02 100644 --- a/performancetest-demo-framework/pom.xml +++ b/performancetest-demo-framework/pom.xml @@ -30,7 +30,7 @@ junit junit - 4.8.2 + 4.10 diff --git a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/AbstractPerformanceTestRunner.java b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/AbstractPerformanceTestRunner.java index 2079180..2ff7272 100644 --- a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/AbstractPerformanceTestRunner.java +++ b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/AbstractPerformanceTestRunner.java @@ -31,7 +31,7 @@ * @author Erich Eichinger * @since 25/01/12 */ -public abstract class AbstractPerformanceTestRunner { +public abstract class AbstractPerformanceTestRunner { final Logger log = LoggerFactory.getLogger(getClass()); @@ -63,15 +63,15 @@ public void run(String[] args) throws Exception { } protected void run() throws Exception { - List browserProfiles = createBrowserProfiles(); + List> browserProfiles = createBrowserProfiles(); usersMax = Math.max(users, usersMax); - log.info(String.format("PerformanceTestBegin{users=%s,sessions=%s,usersMax=%s,usersIncr=%s}", users, sessions,usersMax, usersIncr)); + log.info(String.format("PerformanceTestBegin{users=%s,sessions=%s,usersMax=%s,usersIncr=%s}", users, sessions, usersMax, usersIncr)); boolean hasErrors = false; - for(int usersForIteration=users;usersForIteration<=usersMax;usersForIteration+=usersIncr){ + for(int usersForIteration=users; usersForIteration <= usersMax; usersForIteration += usersIncr){ log.info(String.format("IterationBegin{usersForIteration=%s}", usersForIteration)); hasErrors = hasErrors || runIteration(browserProfiles, usersForIteration); } @@ -79,9 +79,9 @@ protected void run() throws Exception { Assert.assertFalse("Performance Tests had errors", hasErrors); } - abstract protected List createBrowserProfiles(); + abstract protected List> createBrowserProfiles(); - private boolean runIteration(List browserProfiles, int usersForIteration) throws Exception { + private boolean runIteration(List> browserProfiles, int usersForIteration) throws Exception { int totalSessions = usersForIteration * sessions; ExecutorService executor = Executors.newFixedThreadPool(usersForIteration); @@ -90,7 +90,7 @@ private boolean runIteration(List browserProfiles, int us for(int i=0;i profile = browserProfiles.get(0); Callable session = new SessionResultReporter(profile.getProfileClass(), profile.newRunnable()); sessions.add(session); } @@ -107,10 +107,10 @@ private boolean runIteration(List browserProfiles, int us } public class SessionResultReporter implements Callable { - private final Class profileClass; + private final Class profileClass; final Runnable inner; - public SessionResultReporter(Class profileClass, Runnable inner) { + public SessionResultReporter(Class profileClass, Runnable inner) { this.profileClass = profileClass; this.inner = inner; } diff --git a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/BaseWebDriverTest.java b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/BaseWebDriverTest.java index 11e7d73..7145e20 100644 --- a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/BaseWebDriverTest.java +++ b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/BaseWebDriverTest.java @@ -1,7 +1,8 @@ package org.eeichinger.testing.web; import org.junit.Rule; -import org.junit.rules.MethodRule; +import org.junit.rules.RuleChain; +import org.junit.rules.TestRule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,10 +13,14 @@ * @author Neale Upstone/OpenCredo */ public class BaseWebDriverTest { - // note that rules are executed bottom up - hence DriverLifecycle must be last! - @Rule public final TestTracerRule loggerRule = new TestTracerRule(); - @Rule public final MethodRule screenshotRule = new ScreenshotCaptureRule(); - @Rule public final MethodRule driverLifecycle = new DriverLifecycleRule(); + private final TestTracerRule loggerRule = new TestTracerRule(); + private final TestRule screenshotRule = new ScreenshotCaptureRule(); + private final TestRule driverLifecycle = new DriverLifecycleRule(); + + @Rule public final RuleChain chain = RuleChain + .outerRule(driverLifecycle) + .around(screenshotRule) + .around(loggerRule); protected final Logger log = LoggerFactory.getLogger(getClass()); } diff --git a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/DriverLifecycleRule.java b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/DriverLifecycleRule.java index ae1efc0..b40c6c1 100644 --- a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/DriverLifecycleRule.java +++ b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/DriverLifecycleRule.java @@ -1,23 +1,23 @@ -package org.eeichinger.testing.web; - -import org.junit.rules.TestWatchman; -import org.junit.runners.model.FrameworkMethod; - -/** - * Manages the WebDriver lifecycle for plain unit tests - * - * @author Erich Eichinger - * @since 26/01/12 - */ -public class DriverLifecycleRule extends TestWatchman { - - @Override - public void starting(FrameworkMethod method) { - WebDriverFactory.getInstance().initializeWebDriver(); - } - - @Override - public void finished(FrameworkMethod method) { - WebDriverFactory.getInstance().getCurrentWebDriver().quit(); - } -} +package org.eeichinger.testing.web; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +/** + * Manages the WebDriver lifecycle for plain unit tests + * + * @author Erich Eichinger + * @since 26/01/12 + */ +public class DriverLifecycleRule extends TestWatcher { + + @Override + protected void starting(Description description) { + WebDriverFactory.getInstance().initializeWebDriver(); + } + + @Override + protected void finished(Description description) { + WebDriverFactory.getInstance().getCurrentWebDriver().quit(); + } +} diff --git a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/ScreenshotCaptureRule.java b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/ScreenshotCaptureRule.java index d3806f0..50d599f 100644 --- a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/ScreenshotCaptureRule.java +++ b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/ScreenshotCaptureRule.java @@ -1,8 +1,8 @@ package org.eeichinger.testing.web; import org.apache.commons.io.FileUtils; -import org.junit.rules.TestWatchman; -import org.junit.runners.model.FrameworkMethod; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; @@ -19,7 +19,7 @@ * @author Neale Upstone/OpenCredo * @author Erich Eichinger/OpenCredo */ -public final class ScreenshotCaptureRule extends TestWatchman { +public final class ScreenshotCaptureRule extends TestWatcher { protected final Logger log = LoggerFactory.getLogger(getClass()); @@ -33,9 +33,10 @@ public ScreenshotCaptureRule(String screenshotPath) { this.screenshotPath = screenshotPath; } - public void failed(Throwable e, FrameworkMethod method) { - String methodName = method.getMethod().getName(); - log.error(String.format("Failure in %s.%s", method.getMethod().getDeclaringClass().getName(), methodName), e); + @Override + public void failed(Throwable e, Description description) { + String methodName = description.getMethodName(); + log.error(String.format("Failure in %s.%s", description.getClassName(), methodName), e); if (Settings.TAKE_ERROR_SCREENSHOTS) { captureScreen(screenshotPath, methodName); } @@ -50,6 +51,11 @@ public void captureEntirePageScreenshot(String fileName) { return; WebDriver driver = WebDriverFactory.getInstance().getCurrentWebDriver(); + if (!(driver instanceof TakesScreenshot)) { + log.warn("Driver {} doesn't support screenshots - page source was:\n {}", driver.getClass().getName(), driver.getPageSource()); + return; + } + File screenshotAs; try { screenshotAs = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); diff --git a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TestTracerRule.java b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TestTracerRule.java index 8a8f83f..41013f0 100644 --- a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TestTracerRule.java +++ b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TestTracerRule.java @@ -1,7 +1,7 @@ package org.eeichinger.testing.web; -import org.junit.rules.TestWatchman; -import org.junit.runners.model.FrameworkMethod; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,22 +10,22 @@ * * @author Neale Upstone/OpenCredo */ -public class TestTracerRule extends TestWatchman { +public class TestTracerRule extends TestWatcher { protected final Logger log = LoggerFactory.getLogger(getClass()); @Override - public void starting(FrameworkMethod method) { - log.info("Starting: {}", method.getName()); + public void starting(Description description) { + log.info("Starting: {}", description.getMethodName()); } @Override - public void failed(Throwable e, FrameworkMethod method) { - log.error("Failed: {}", method.getName(), e); + public void failed(Throwable e, Description description) { + log.error("Failed: {}", description.getMethodName(), e); } @Override - public void succeeded(FrameworkMethod method) { - log.info("Success: {}", method.getName()); + public void succeeded(Description description) { + log.info("Success: {}", description.getMethodName()); } } diff --git a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TimeoutThresholdException.java b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TimeoutThresholdException.java index 1a4bb06..48fb456 100644 --- a/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TimeoutThresholdException.java +++ b/performancetest-demo-framework/src/main/java/org/eeichinger/testing/web/TimeoutThresholdException.java @@ -6,7 +6,9 @@ */ public class TimeoutThresholdException extends RuntimeException { - public TimeoutThresholdException(String msg) { + private static final long serialVersionUID = 1L; + + public TimeoutThresholdException(String msg) { super(msg); } } diff --git a/performancetest-demo-tests/src/test/java/org/eeichinger/performancetestdemo/performance/PerformanceTestRunner.java b/performancetest-demo-tests/src/test/java/org/eeichinger/performancetestdemo/performance/PerformanceTestRunner.java index b0f736a..192c991 100644 --- a/performancetest-demo-tests/src/test/java/org/eeichinger/performancetestdemo/performance/PerformanceTestRunner.java +++ b/performancetest-demo-tests/src/test/java/org/eeichinger/performancetestdemo/performance/PerformanceTestRunner.java @@ -10,15 +10,15 @@ * @author: Erich Eichinger/OpenCredo * @date: 26/01/12 */ -public class PerformanceTestRunner extends AbstractPerformanceTestRunner { +public class PerformanceTestRunner extends AbstractPerformanceTestRunner { public static void main(String[] args) throws Exception { new PerformanceTestRunner().run(args); } @Override - protected List createBrowserProfiles() { - List browserProfiles = new ArrayList(); + protected List> createBrowserProfiles() { + List> browserProfiles = new ArrayList>(); browserProfiles.add(new BrowserSessionFactory(StandardUserSession.class, 100, 20000)); return browserProfiles; } diff --git a/pom.xml b/pom.xml index de2354e..214106f 100644 --- a/pom.xml +++ b/pom.xml @@ -15,4 +15,21 @@ performancetest-demo-web performancetest-demo-tests + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + +