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); }
/** * 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(Description description) { DriverManager.closeDriver(obj); } }; }
/** * 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."); } }; }
public static TestWatcher newWatcher(final Class clazz, final long seed) { return new TestWatcher() { protected void failed(final Throwable t, final Description description) { System.err.println(clazz.getName() + " failed with random seed: " + seed); } }; }
@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); } }; }
@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); } }; }
@Override public TestRule applyTo(final JenkinsInstance jenkins) { return new TestWatcher() { @Override protected void starting(Description description) { jenkins.client().registerAccount(user.getName(), user.password()); } }; }
@Override public TestRule applyTo(final JenkinsInstance jenkins) { return new TestWatcher() { @Override protected void starting(Description description) { warmUpUpdateCenterCacheFor(jenkins); jenkins.client().installPlugins(requiredPlugins); } }; }
@Test public void hasZeroFields() throws Exception { Field[] fields = TestWatcher.class.getDeclaredFields(); assertThat(fields.length).as("Fields: " + Arrays.asList(fields)).isEqualTo(0); }
@Rule public TestWatcher getSauceLabsTestWatcher() { return setup.getSauceLabsTestWatcher(); }
@Override protected TestWatcher innerRule() { return innerRule; }
/** * Create watcher for JUnit * @return a watcher for use with JUnit */ public static TestWatcher createWatcher() { return provider.createWatcher(); }