Class AbstractDriver

  • Direct Known Subclasses:
    AbstractChromeDefaultDriver, AbstractEdgeDefaultDriver, AbstractFirefoxDefaultDriver

    public abstract class AbstractDriver
    extends java.lang.Object
    The abstract class for all selenium web drivers.
    Public fields are:
        public Logger logger;
        public final ByteArrayOutputStream driverServiceOutputStream = new ByteArrayOutputStream();
        public WebDriver driver;
        public Map<String, Object> vars;
        public JavascriptExecutor js;
     
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  AbstractDriver.WebBrowserType
      The annotation for the 'WebBrowserType', supported values are 'Chrome', 'Edge', and 'Firefox'
    • Field Summary

      Fields 
      Modifier and Type Field Description
      org.openqa.selenium.WebDriver driver
      The web driver.
      java.io.ByteArrayOutputStream driverServiceOutputStream
      The driver service output stream.
      org.openqa.selenium.JavascriptExecutor js
      The JavaScript executor.
      java.util.logging.Logger logger
      The logger.
      static java.util.HashSet<java.lang.String> VALID_WEB_BROWSER_TYPES_SET
      A set of all valid web browser types.
      java.util.Map<java.lang.String,​java.lang.Object> vars
      The map of variables.
      static java.lang.String WEB_BROWSER_TYPE_CHROME
      Web browser type: Chrome.
      static java.lang.String WEB_BROWSER_TYPE_EDGE
      Web browser type: Edge.
      static java.lang.String WEB_BROWSER_TYPE_FIREFOX
      Web browser type: Firefox.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractDriver()  
    • Field Detail

      • WEB_BROWSER_TYPE_CHROME

        public static final java.lang.String WEB_BROWSER_TYPE_CHROME
        Web browser type: Chrome.
        See Also:
        Constant Field Values
      • WEB_BROWSER_TYPE_EDGE

        public static final java.lang.String WEB_BROWSER_TYPE_EDGE
        Web browser type: Edge.
        See Also:
        Constant Field Values
      • WEB_BROWSER_TYPE_FIREFOX

        public static final java.lang.String WEB_BROWSER_TYPE_FIREFOX
        Web browser type: Firefox.
        See Also:
        Constant Field Values
      • VALID_WEB_BROWSER_TYPES_SET

        public static final java.util.HashSet<java.lang.String> VALID_WEB_BROWSER_TYPES_SET
        A set of all valid web browser types.
      • logger

        public java.util.logging.Logger logger
        The logger. The default log level is INFO, if isArgDebugExecution() == true then the level is FINE.
        See Also:
        isArgDebugExecution()
      • driverServiceOutputStream

        public final java.io.ByteArrayOutputStream driverServiceOutputStream
        The driver service output stream.
      • driver

        public org.openqa.selenium.WebDriver driver
        The web driver.
      • vars

        public java.util.Map<java.lang.String,​java.lang.Object> vars
        The map of variables.
      • js

        public org.openqa.selenium.JavascriptExecutor js
        The JavaScript executor.
    • Constructor Detail

      • AbstractDriver

        public AbstractDriver()
    • Method Detail

      • isArgDebugExecution

        public static boolean isArgDebugExecution()
        Get if debug test execution is enabled.
        Returns:
        true if debug test execution is enabled
      • isArgDebugMeasuring

        public static boolean isArgDebugMeasuring()
        Get if debug data measuring is enabled.
        Returns:
        true if debug data measuring is enabled
      • getArgDataOutputDirectory

        public static java.io.File getArgDataOutputDirectory()
        Get the data output directory.
        Returns:
        the data output directory, or null if no such information is available
      • getUserNumber

        public static int getUserNumber()
        Get the simulated user number.
        Returns:
        the simulated user number, or -1 if no such information is available
      • getUserInputField

        public static java.lang.String getUserInputField​(java.lang.String variableName,
                                                         java.lang.String defaultValue)
        Get the value of a user input field.
        Parameters:
        variableName - the variable name of the user input field
        defaultValue - the default value
        Returns:
        the value of a user input field, or the default value if the user input field is undefined
      • abstractSetUp

        public void abstractSetUp()
        Setup the abstract driver. This method initializes the logger of the driver.
      • abstractTearDown

        public void abstractTearDown()
        Tear down the driver. This method performs:
        • Call: driver.quit()
        • Dump the log of the driver service to stdout (only if isArgDebugExecution() == true)
        • Dump the web browser log to stdout
        See Also:
        isArgDebugExecution()
      • formatDate

        public static java.lang.String formatDate​(long millis)
        Format a Unix-like timestamp to yyyy-MM-dd HH:mm:ss.SSS .
        Parameters:
        millis - the Unix-like timestamp
        Returns:
        the formatted string
      • takeScreenshotAsFile

        public void takeScreenshotAsFile​(java.io.File f)
                                  throws java.io.IOException
        Take a screenshot and save it as file.
        Parameters:
        f - the file (the file name should end with .png)
        Throws:
        java.io.IOException - if the file cannot be written
      • takeScreenshotAsTestJobOutFile

        public java.io.File takeScreenshotAsTestJobOutFile​(java.lang.String fileName)
                                                    throws java.io.IOException
        Take a screenshot and save it as file in the "out" directory of the current measuring agent job.
        Parameters:
        fileName - the file name (should end with .png)
        Returns:
        the saved file
        Throws:
        java.io.IOException - if the file cannot be written
      • takeScreenshotAsBinary

        public byte[] takeScreenshotAsBinary()
        Take a screenshot and get the bytes of the png image.
        Returns:
        the bytes of the png image
      • takeScreenshotAsBase64

        public java.lang.String takeScreenshotAsBase64()
        Take a screenshot and get the data of the png image in base64 format.
        Returns:
        the data of the png image in base64 format