org.junit.rules.TestWatcher Java Examples

The following examples show how to use org.junit.rules.TestWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebDriverSetup.java    From glowroot with Apache License 2.0 6 votes vote down vote up
public TestWatcher getSauceLabsTestWatcher() {
    if (!SauceLabs.useSauceLabs()) {
        return new TestWatcher() {};
    }
    String sauceUsername = System.getenv("SAUCE_USERNAME");
    String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY");
    SauceOnDemandAuthentication authentication =
            new SauceOnDemandAuthentication(sauceUsername, sauceAccessKey);
    SauceOnDemandSessionIdProvider sessionIdProvider = new SauceOnDemandSessionIdProvider() {
        @Override
        public String getSessionId() {
            return remoteWebDriverSessionId;
        }
    };
    return new SauceOnDemandTestWatcher(sessionIdProvider, authentication);
}
 
Example #2
Source File: DriverWatcher.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Get test watcher to manage driver instances.
 * 
 * @param obj test class instance extending {@link TestBase}
 * @return test watcher object
 */
public static TestWatcher getTestWatcher(final TestBase obj) {
    return new TestWatcher() {
        @Override
        protected void finished(final Description description) {
            DriverManager.closeDriver(obj);
        }
    };
}
 
Example #3
Source File: Utils.java    From january with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This function create a TestWatcher writing on screen the names of called
 * classes and methods.
 * 
 * @return the TestWatcher created
 */
public static TestWatcher testWatcherCreator() {
	return new TestWatcher() {
		protected void starting(Description description) {
			System.out.println("\nStarting example : " + description.getMethodName() + " from : "
					+ description.getClassName() + " class.");
		}
	};
}
 
Example #4
Source File: FindFreePort.java    From jenkins-build-monitor-plugin with MIT License 5 votes vote down vote up
@Override
public TestRule applyTo(final JenkinsInstance instance) {
    return new TestWatcher() {
        @Override
        protected void starting(Description description) {
            int portNumber = anyFreeLocalPortInRange(rangeStart, rangeEnd);

            Log.info("Found a free port: {}", portNumber);

            instance.setPort(portNumber);
        }
    };
}
 
Example #5
Source File: SandboxJenkinsHome.java    From jenkins-build-monitor-plugin with MIT License 5 votes vote down vote up
@Override
public TestRule applyTo(final JenkinsInstance jenkins) {
    return new TestWatcher() {
        @Override
        protected void starting(Description test) {

            Path jenkinsHome = temporaryJenkinsHomeFor(test);

            Log.info("Setting jenkins home to {}", jenkinsHome);

            jenkins.setHome(jenkinsHome);
        }
    };
}
 
Example #6
Source File: RegisterUserAccount.java    From jenkins-build-monitor-plugin with MIT License 5 votes vote down vote up
@Override
public TestRule applyTo(final JenkinsInstance jenkins) {
    return new TestWatcher() {
        @Override
        protected void starting(Description description) {
            jenkins.client().registerAccount(user.getName(), user.password());
        }
    };
}
 
Example #7
Source File: InstallPluginsFromUpdateCenter.java    From jenkins-build-monitor-plugin with MIT License 5 votes vote down vote up
@Override
public TestRule applyTo(final JenkinsInstance jenkins) {
    return new TestWatcher() {
        @Override protected void starting(Description description) {

            warmUpUpdateCenterCacheFor(jenkins);

            jenkins.client().installPlugins(requiredPlugins);
        }
    };
}
 
Example #8
Source File: WebDriverIT.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Rule
public TestWatcher getSauceLabsTestWatcher() {
    return setup.getSauceLabsTestWatcher();
}