Class OsUtils


  • public class OsUtils
    extends java.lang.Object
    Utility class providing methods that should exhibit a different behavior depending on the Operating System the program is running in, like setting and getting a WebDriver session for scraping or the OS detection itself.
    Author:
    Matteo Collica
    See Also:
    UnsupportedOsException, NoSupportedBrowsersException
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private OsUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyFile​(java.io.InputStream source, java.lang.String destination)
      Write input data to a specific destination file and set it as executable
      static org.openqa.selenium.WebDriver getWebDriver()
      Create and get a new WebDriver instance based on the user's first supported browser found, with a Firefox > Chrome > Edge > (Safari / IE) priority;

      Set the drivers' path if they're needed and were not already set.
      static void initializeOs()
      Detect and store the user's Operating System type needed for the OsUtils class' methods
      static boolean isMac()  
      static boolean isUnix()  
      static boolean isWindows()  
      static void setWebDriverSystemPath​(OsUtils.SupportedBrowser TARGET_BROWSER)
      Given a browser, set the corresponding driver path System Property (required by Selenium to get the WebDriver's instances working) differently based on the user's Operating System
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OsUtils

        private OsUtils()
    • Method Detail

      • getWebDriver

        public static org.openqa.selenium.WebDriver getWebDriver()
                                                          throws NoSupportedBrowsersException
        Create and get a new WebDriver instance based on the user's first supported browser found, with a Firefox > Chrome > Edge > (Safari / IE) priority;

        Set the drivers' path if they're needed and were not already set.
        Returns:
        the newly created WebDriver instance.
        Throws:
        NoSupportedBrowsersException - if no supported browser is installed or functioning with Selenium in the user's operating system.
      • setWebDriverSystemPath

        public static void setWebDriverSystemPath​(OsUtils.SupportedBrowser TARGET_BROWSER)
        Given a browser, set the corresponding driver path System Property (required by Selenium to get the WebDriver's instances working) differently based on the user's Operating System
        Parameters:
        TARGET_BROWSER - the browser the driver path should be set for
      • copyFile

        public static void copyFile​(java.io.InputStream source,
                                    java.lang.String destination)
        Write input data to a specific destination file and set it as executable
        Parameters:
        source - the input data
        destination - the destination path of the file the input data should be written into
      • initializeOs

        public static void initializeOs()
                                 throws UnsupportedOsException
        Detect and store the user's Operating System type needed for the OsUtils class' methods
        Throws:
        UnsupportedOsException - if the Operating System the user is running this program in isn't Windows, macOS or Unix-based.
      • isWindows

        public static boolean isWindows()
        Returns:
        true if the Operating System name stored in the OS class field implies a Windows-based one, false otherwise
      • isMac

        public static boolean isMac()
        Returns:
        true if the Operating System name stored in the OS class field implies a macOS-based one, false otherwise
      • isUnix

        public static boolean isUnix()
        Returns:
        true if the Operating System name stored in the OS class field implies a Unix-based one, false otherwise