Package romanemperorsscraper.run
Class OsUtils
- java.lang.Object
-
- romanemperorsscraper.run.OsUtils
-
public class OsUtils extends java.lang.ObjectUtility 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOsUtils.SupportedBrowserstatic classOsUtils.SupportedOs
-
Field Summary
Fields Modifier and Type Field Description private static OsUtils.SupportedBrowserBROWSERprivate static java.lang.StringDRIVERS_BASE_PATHprivate static java.lang.StringOSprivate static OsUtils.SupportedOsOSTYPEprivate static java.lang.StringTEMP_FILES_PATH
-
Constructor Summary
Constructors Modifier Constructor Description privateOsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyFile(java.io.InputStream source, java.lang.String destination)Write input data to a specific destination file and set it as executablestatic org.openqa.selenium.WebDrivergetWebDriver()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 voidinitializeOs()Detect and store the user's Operating System type needed for the OsUtils class' methodsstatic booleanisMac()static booleanisUnix()static booleanisWindows()static voidsetWebDriverSystemPath(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
-
-
-
Field Detail
-
TEMP_FILES_PATH
private static final java.lang.String TEMP_FILES_PATH
-
DRIVERS_BASE_PATH
private static final java.lang.String DRIVERS_BASE_PATH
- See Also:
- Constant Field Values
-
OS
private static final java.lang.String OS
-
OSTYPE
private static OsUtils.SupportedOs OSTYPE
-
BROWSER
private static OsUtils.SupportedBrowser BROWSER
-
-
Method Detail
-
getWebDriver
public static org.openqa.selenium.WebDriver getWebDriver() throws NoSupportedBrowsersExceptionCreate 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 datadestination- the destination path of the file the input data should be written into
-
initializeOs
public static void initializeOs() throws UnsupportedOsExceptionDetect 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
-
-