public class UtilityHelper extends Object
| Constructor and Description |
|---|
UtilityHelper() |
| Modifier and Type | Method and Description |
|---|---|
protected static void |
addFileToZip(String path,
String srcFile,
ZipOutputStream zip) |
protected static void |
appendToFile(String value,
String absolutePath)
appends to existing file
|
protected static void |
appendToFile(String value,
String directory,
String filename,
String type)
appends to existing file
|
static File |
captureElementPicture(EnhancedBy element)
Gets a picture of specific element displayed on the page
|
static File |
captureElementPicture(EnhancedBy element,
int index)
Gets a picture of specific element displayed on the page
|
protected static void |
captureReportScreenshot()
captures screenshot And attaches to extent test report
|
protected static String |
convertListToString(ArrayList<String> list) |
protected static String |
convertListToString(ArrayList<String> list,
String separator) |
protected static URL |
convertToUrl(String url)
converts url string to url object
|
protected static void |
copyDirectory(String dirFrom,
String dirTo)
Copies directory And all content from dirFrom to dirTo overwrites the content
|
protected static File |
createFileFromPath(String absolutePath)
create directories and files based on absolute path set permissions to
rw-r--r-- set executable to true
|
protected static ZipOutputStream |
createZip(String destZipFile) |
protected static void |
deleteFile(String absolutePath)
delete file or directory
|
protected static ArrayList<String> |
excuteCommand(String command)
run command and return results as array list will run bash on linux or mac
will run batch command on windows
|
protected static ArrayList<String> |
excuteCommandFromFile(String filePath)
run script file and return results as array list will run bash on linux or
mac will run batch command on windows
|
protected static void |
executeJavascript(String script) |
protected static Object |
executeJs(String script,
Object... args)
execute javascript
|
protected static List<String> |
executeJsWithListReturn(String script,
Object... args)
execute javascript
|
protected static String |
executeJsWithStringReturn(String script,
Object... args)
execute javascript
|
protected static String |
generateRandomInteger(int len)
generates random int of length len
|
protected static int |
generateRandomNumber(int min,
int max)
generates random number between two numbers, min, max
|
protected static String |
generateRandomString(int len)
generates random string of length len
|
protected static String |
generateUUID()
generate uuid
|
protected static String |
generateUUID(boolean includeDash)
generate uuid
|
protected static String |
generateUUID(int length)
generate uuid
|
protected static String |
generateUUID(int length,
boolean includeDash)
generate uuid
|
protected static List<String> |
getAllValuesStartringWith(String source,
String value)
gets a list of string from 'source' starting with 'value'
|
protected static double |
getDoubleFromString(String value,
boolean isFailOnNoInt)
get numeric value from string
|
protected static File |
getFile(String directoryPath)
get file from file path
|
protected static File |
getFileByName(String path,
String filename)
get file by name
|
protected static File |
getFileByName(String path,
String filename,
boolean includeSubDir)
get file by name
|
protected static String |
getFileContent(String absolutePath)
gets file content as String
|
protected static String |
getFileContent(String absolutePath,
boolean verifyFileExists)
gets file content as String
|
protected static ArrayList<File> |
getFileList(String directoryPath)
returns the list of files in directory
|
protected static ArrayList<File> |
getFileList(String directoryPath,
ArrayList<File> files)
returns the list of files in directory
|
protected static ArrayList<File> |
getFileList(String directoryPath,
boolean includeSubDir)
returns the list of files in directory
|
protected static ArrayList<File> |
getFileListByType(String directoryPath,
String type)
gets the list of files tye: file type.
|
protected static ArrayList<File> |
getFileListByType(String directoryPath,
String type,
boolean includeSubDir)
gets the list of files tye: file type.
|
protected static List<File> |
getFileListWithSubfolders(String directoryName,
List<File> files) |
protected static List<File> |
getFileListWithSubfolders(String directoryName,
String type,
List<File> files)
gets list of files including from sub folder based on type.
|
protected static int |
getFirstNumber(String value) |
protected static String |
getFullPath(String path)
gets full path from relative path
relative path is from root directory ( where pom.xml file is located )
|
protected static int |
getIntFromString(String value,
boolean isFailOnNoInt)
get numeric value from string
|
protected static List<String> |
getLinesInFileContainingWith(String value,
File file)
get line in file containing string
|
protected static List<String> |
getLinesInFileStartingWith(String value,
File file)
get line in file starting with string
|
static String |
getMavenArtifactId() |
static String |
getMavenDependencyVersion(String dependency) |
protected static String |
getPageSource()
gets page source
|
protected static String |
getRootDir()
get current project root directory, where pom.xml is
|
static String |
getValueBetweenStrings(String source,
String value1,
String value2,
int position)
get value between 2 strings.
|
protected static String |
getValueFromPattern(String str,
String pattern) |
protected static List<String> |
getValuesFromPattern(String str,
String pattern) |
protected static void |
highLightWebElement(EnhancedBy by,
int index)
highlights the web element use on clicks and send key elements applicable to
web driver
|
protected static boolean |
isBoolean(String value)
returns if string is boolean
|
protected static boolean |
isFileContainString(String value,
File file)
does file contain the given text value
|
protected static boolean |
isFilenameInDir(File dir,
String name) |
protected static boolean |
isLineInFileStartWithString(String value,
File file)
is line in file start with string
|
protected static boolean |
isMac()
returns true if OS is mac
|
protected static boolean |
isNumeric(String str)
return if string is a number
|
protected static boolean |
isProcessRunning(String serviceName)
returns true if process is running
|
static boolean |
isProxyRequired(URL url)
get proxy state from proxy enabled config
values: true, false, auto
if auto is set, then through proxy detection, we set value to true or false
|
protected static boolean |
isStringContainNumber(String value)
does string have int value
|
protected static boolean |
isStringContainOnlyNumber(String value)
does string have only numeric value
|
protected static boolean |
isUnix()
returns true if OS is unix or linux
|
static boolean |
isUrlAbleToConnect(URL source,
Proxy proxy)
check if able to connect to source url
|
protected static boolean |
isUUID(String value)
is the string value UDID
|
protected static boolean |
isWindows()
returns true if OS is windows
|
protected static void |
killMacProcess(String serviceName) |
protected static void |
killWindowsProcess(String serviceName)
returns kills the process if running
|
protected static void |
printPageSource()
prints page source to console
|
protected static String |
readFileContent(String absolutePath)
gets file content as String
|
protected static String |
removeSurroundingQuotes(String value)
remove surrounding double quotes from the string
|
static boolean |
setProxyAutoDetection(URL source)
checks if proxy is required first attempt without proxy, second with proxy,
checking the validity of the proxy connection
|
static void |
slackNotificationWithFile(String title,
String comment,
String filePath)
TODO: replace slack api with newer library
sends slack notification token: generate at:
https://api.slack.com/custom-integrations/legacy-tokens for channel id: right
click And channel And copy link.
|
protected static String |
stringNormalize(String value)
normalizes string removes space, new line chars, quotes
|
protected static String |
stringRemoveLines(String value)
normalizes string removes space, new line chars
|
protected static void |
writeFile(String value,
String absolutePath)
Create file (where pom.xml is) and write to it
|
protected static void |
writeFile(String value,
String directory,
String filename,
String type)
Create file with path starting from root directory (where pom.xml is) and
write to it.
|
static String |
zipDir(String sourceDir,
String destFilePath)
zips directory path starts from root pom directory
|
protected static ZipOutputStream |
zipFolder(String srcFolder,
String destZipFile)
zip folder
|
protected static String generateRandomString(int len)
len - protected static String generateRandomInteger(int len)
len - protected static int generateRandomNumber(int min,
int max)
min - max - protected static String generateUUID()
protected static String generateUUID(boolean includeDash)
includeDash - protected static String generateUUID(int length)
length - protected static String generateUUID(int length, boolean includeDash)
length - protected static String stringNormalize(String value)
value - protected static String stringRemoveLines(String value)
value - protected static boolean isProcessRunning(String serviceName) throws Exception
serviceName - Exceptionprotected static void killWindowsProcess(String serviceName)
serviceName - Exceptionprotected static void killMacProcess(String serviceName)
protected static ArrayList<String> excuteCommand(String command)
command - IOExceptionprotected static ArrayList<String> excuteCommandFromFile(String filePath)
filePath - path from the root directory ( where pom.xml is )protected static void copyDirectory(String dirFrom, String dirTo)
dirFrom - dirTo - protected static void executeJavascript(String script)
protected static ZipOutputStream zipFolder(String srcFolder, String destZipFile) throws Exception
srcFolder - destZipFile - Exceptionprotected static ZipOutputStream createZip(String destZipFile) throws FileNotFoundException
FileNotFoundExceptionprotected static void addFileToZip(String path, String srcFile, ZipOutputStream zip) throws Exception
Exceptionprotected static List<String> getAllValuesStartringWith(String source, String value)
source - value - protected static String getValueFromPattern(String str, String pattern)
str - pattern - regular expression patternprotected static List<String> getValuesFromPattern(String str, String pattern)
str - pattern - regular expression patternprotected static String getRootDir()
public static void slackNotificationWithFile(String title, String comment, String filePath)
public static String zipDir(String sourceDir, String destFilePath)
sourceDir: - root path + dirdestFilePath: - usage: root + dir + outputFilePathprotected static ArrayList<File> getFileListByType(String directoryPath, String type)
protected static ArrayList<File> getFileListByType(String directoryPath, String type, boolean includeSubDir)
protected static ArrayList<File> getFileList(String directoryPath, boolean includeSubDir)
directoryPath - protected static ArrayList<File> getFileList(String directoryPath, ArrayList<File> files)
directoryPath - protected static ArrayList<File> getFileList(String directoryPath)
directoryPath - protected static String getFullPath(String path)
path - protected static File getFile(String directoryPath)
directoryPath - protected static File getFileByName(String path, String filename)
path - filename - protected static File getFileByName(String path, String filename, boolean includeSubDir)
path - filename - protected static List<File> getFileListWithSubfolders(String directoryName, List<File> files)
protected static List<File> getFileListWithSubfolders(String directoryName, String type, List<File> files)
protected static String readFileContent(String absolutePath)
absolutePath - protected static String getFileContent(String absolutePath)
absolutePath - protected static String getFileContent(String absolutePath, boolean verifyFileExists)
absolutePath - protected static File createFileFromPath(String absolutePath)
path - protected static void writeFile(String value, String directory, String filename, String type)
value - value in filedirectory - directory from rootfilename - name of the filetype - type of fileprotected static void writeFile(String value, String absolutePath)
value - absolutePath - protected static void deleteFile(String absolutePath)
absolutePath - protected static void appendToFile(String value, String absolutePath)
value - absolutePath - protected static void appendToFile(String value, String directory, String filename, String type)
value - directory - filename - type - protected static void captureReportScreenshot()
public static File captureElementPicture(EnhancedBy element)
element - The elementExceptionpublic static File captureElementPicture(EnhancedBy element, int index)
element - The elementExceptionprotected static void highLightWebElement(EnhancedBy by, int index)
by - index - protected static boolean isMac()
protected static boolean isWindows()
protected static boolean isUnix()
protected static boolean isUUID(String value)
value - protected static boolean isBoolean(String value)
value - protected static boolean isNumeric(String str)
str - protected static Object executeJs(String script, Object... args)
script - protected static List<String> executeJsWithListReturn(String script, Object... args)
script - protected static String executeJsWithStringReturn(String script, Object... args)
script - protected static int getIntFromString(String value, boolean isFailOnNoInt)
value - isFailOnNoInt - protected static int getFirstNumber(String value)
protected static double getDoubleFromString(String value, boolean isFailOnNoInt)
value - isFailOnNoInt - protected static boolean isStringContainOnlyNumber(String value)
value - protected static boolean isStringContainNumber(String value)
value - protected static String removeSurroundingQuotes(String value)
value - protected static URL convertToUrl(String url)
url - public static boolean isUrlAbleToConnect(URL source, Proxy proxy)
source - public static boolean isProxyRequired(URL url)
url - public static boolean setProxyAutoDetection(URL source)
source - public static String getMavenArtifactId()
protected static boolean isFileContainString(String value, File file)
value - file - protected static boolean isLineInFileStartWithString(String value, File file)
value - file - protected static List<String> getLinesInFileStartingWith(String value, File file)
value - file - protected static List<String> getLinesInFileContainingWith(String value, File file)
value - file - protected static void printPageSource()
protected static String getPageSource()
protected static String convertListToString(ArrayList<String> list, String separator)
Copyright © 2021. All rights reserved.