Guest User

Untitled

a guest
Dec 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class SharedDriver extends EventFiringWebDriver {
  2. private static final WebDriver REAL_DRIVER = WebDriverFactory.create();
  3.  
  4. private static final Thread CLOSE_THREAD = new Thread() {
  5. @Override
  6. public void run() {
  7. REAL_DRIVER.quit();
  8. }
  9. };
  10.  
  11. static {
  12. Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
  13. }
  14.  
  15. public SharedDriver() {
  16. super(REAL_DRIVER);
  17. }
  18.  
  19. @Override
  20. public void quit() {
  21. if (Thread.currentThread() != CLOSE_THREAD) {
  22. throw new UnsupportedOperationException("You shouldn't quit this WebDriver. It's shared and will quit when the JVM exits.");
  23. }
  24. super.quit();
  25. }
  26.  
  27. @Before
  28. public void deleteAllCookies() {
  29. manage().deleteAllCookies();
  30. }
  31.  
  32. @After
  33. public void embedScreenshot(Scenario scenario) {
  34. try {
  35. byte[] screenshot = getScreenshotAs(OutputType.BYTES);
  36. scenario.embed(screenshot, "image/png");
  37. } catch (WebDriverException somePlatformsDontSupportScreenshots) {
  38. System.err.println(somePlatformsDontSupportScreenshots.getMessage());
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment