Class ScreenShotLaboratory


  • public class ScreenShotLaboratory
    extends java.lang.Object
    • Field Detail

      • allScreenshots

        protected final java.util.List<java.io.File> allScreenshots
      • screenshotCounter

        protected java.util.concurrent.atomic.AtomicLong screenshotCounter
      • currentContext

        protected java.lang.ThreadLocal<java.lang.String> currentContext
      • currentContextScreenshots

        protected java.lang.ThreadLocal<java.util.List<java.io.File>> currentContextScreenshots
    • Constructor Detail

      • ScreenShotLaboratory

        protected ScreenShotLaboratory()
    • Method Detail

      • takeScreenShot

        public java.lang.String takeScreenShot​(Driver driver,
                                               java.lang.String className,
                                               java.lang.String methodName)
      • getScreenshotFileName

        protected java.lang.String getScreenshotFileName​(java.lang.String className,
                                                         java.lang.String methodName)
      • takeScreenShot

        public java.lang.String takeScreenShot​(Driver driver)
      • takeScreenShot

        public java.lang.String takeScreenShot​(Driver driver,
                                               java.lang.String fileName)
        Takes screenshot of current browser window. Stores 2 files: html of page (if "savePageSource" option is enabled), and (if possible) image in PNG format.
        Parameters:
        fileName - name of file (without extension) to store screenshot to.
        Returns:
        the name of last saved screenshot or null if failed to create screenshot
      • takeScreenshot

        public java.io.File takeScreenshot​(Driver driver,
                                           org.openqa.selenium.WebElement element)
      • takeScreenshotAsImage

        public java.awt.image.BufferedImage takeScreenshotAsImage​(Driver driver,
                                                                  org.openqa.selenium.WebElement element)
      • generateScreenshotFileName

        protected java.lang.String generateScreenshotFileName()
      • ensureFolderExists

        protected void ensureFolderExists​(java.io.File targetFile)
      • timestamp

        protected long timestamp()
      • takeScreenshot

        public java.io.File takeScreenshot​(Driver driver,
                                           org.openqa.selenium.WebElement iframe,
                                           org.openqa.selenium.WebElement element)
      • takeScreenshotAsImage

        public java.awt.image.BufferedImage takeScreenshotAsImage​(Driver driver,
                                                                  org.openqa.selenium.WebElement iframe,
                                                                  org.openqa.selenium.WebElement element)
      • takeScreenShotAsFile

        public java.io.File takeScreenShotAsFile​(Driver driver)
      • getPageImage

        protected java.io.File getPageImage​(org.openqa.selenium.WebDriver webdriver)
      • addToHistory

        protected java.io.File addToHistory​(java.io.File screenshot)
      • takeScreenshotInMemory

        protected java.io.File takeScreenshotInMemory​(org.openqa.selenium.TakesScreenshot driver)
      • savePageImageToFile

        protected java.io.File savePageImageToFile​(Config config,
                                                   java.lang.String fileName,
                                                   org.openqa.selenium.WebDriver webdriver)
      • savePageSourceToFile

        protected java.io.File savePageSourceToFile​(Config config,
                                                    java.lang.String fileName,
                                                    org.openqa.selenium.WebDriver webdriver)
      • takeScreenshotImage

        protected java.io.File takeScreenshotImage​(Config config,
                                                   org.openqa.selenium.TakesScreenshot driver,
                                                   java.lang.String fileName)
      • copyFile

        protected void copyFile​(java.io.File sourceFile,
                                java.io.File targetFile)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • copyFile

        protected void copyFile​(java.io.InputStream in,
                                java.io.File targetFile)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • startContext

        public void startContext​(java.lang.String className,
                                 java.lang.String methodName)
      • startContext

        public void startContext​(java.lang.String context)
      • finishContext

        public java.util.List<java.io.File> finishContext()
      • getScreenshots

        public java.util.List<java.io.File> getScreenshots()
      • getLastScreenshot

        public java.io.File getLastScreenshot()
      • formatScreenShotPath

        public java.lang.String formatScreenShotPath​(Driver driver)