Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SharedDriver extends EventFiringWebDriver {
- private static final WebDriver REAL_DRIVER = WebDriverFactory.create();
- private static final Thread CLOSE_THREAD = new Thread() {
- @Override
- public void run() {
- REAL_DRIVER.quit();
- }
- };
- static {
- Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
- }
- public SharedDriver() {
- super(REAL_DRIVER);
- }
- @Override
- public void quit() {
- if (Thread.currentThread() != CLOSE_THREAD) {
- throw new UnsupportedOperationException("You shouldn't quit this WebDriver. It's shared and will quit when the JVM exits.");
- }
- super.quit();
- }
- @Before
- public void deleteAllCookies() {
- manage().deleteAllCookies();
- }
- @After
- public void embedScreenshot(Scenario scenario) {
- try {
- byte[] screenshot = getScreenshotAs(OutputType.BYTES);
- scenario.embed(screenshot, "image/png");
- } catch (WebDriverException somePlatformsDontSupportScreenshots) {
- System.err.println(somePlatformsDontSupportScreenshots.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment