com.nordstrom.automation.selenium.junit.DriverWatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium3-foundation Show documentation
Show all versions of selenium3-foundation Show documentation
Selenium3 Foundation is an automation framework designed to extend and enhance the capabilities provided by Selenium 3.0 (WebDriver).
package com.nordstrom.automation.selenium.junit;
import java.lang.reflect.Method;
import org.junit.rules.ExternalResource;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import com.nordstrom.automation.junit.MethodWatcher;
import com.nordstrom.automation.selenium.annotations.PageUrl;
import com.nordstrom.automation.selenium.core.DriverManager;
import com.nordstrom.automation.selenium.core.GridUtility;
import com.nordstrom.automation.selenium.core.TestBase;
/**
* This JUnit watcher performs several basic functions related to driver session management:
*
* - Manage Selenium driver lifetime.
* - For local execution, manage a local instance of Selenium Grid.
* - Store and dispense the driver instance created for the test.
* - Manage configured driver timeout intervals.
* - If an initial page class is specified:
*
* - Open the initial page based on its {@link PageUrl} annotation.
* - Store the page object for subsequent dispensing to the test.
*
*
*
*
* @see GridUtility
*/
public class DriverWatcher implements MethodWatcher {
@Override
public void beforeInvocation(Object obj, Method method, Object[] args) {
DriverManager.beforeInvocation(obj, method);
}
@Override
public void afterInvocation(Object obj, Method method, Object[] args) {
DriverManager.afterInvocation(obj, method);
}
/**
* 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);
}
};
}
/**
* Get class watcher to manage local Grid servers.
*
* @return external resource object
*/
public static ExternalResource getClassWatcher() {
return new ExternalResource() {
@Override
protected void after() {
DriverManager.onFinish();
}
};
}
}