code refactoring, file name cleanups, added ability to use portable version of chrome to Selenium functions
parent
9d250a1c10
commit
621127eaf0
@ -0,0 +1,87 @@
|
||||
; Notes/Extra Info/#Includes
|
||||
;------------------------------------------------
|
||||
; Chrome Related Functions
|
||||
|
||||
|
||||
|
||||
GetChromeFilepath(){
|
||||
; ChromeFilepath is global variable
|
||||
; Establish Variable with Filepath to be used throughout the script
|
||||
|
||||
ChromePortableFilepath = %A_ScriptDir%\Lib\chrome-win64\chrome.exe
|
||||
|
||||
if(FileExist(ChromePortableFilepath)){
|
||||
ChromeFilepath := ChromePortableFilepath
|
||||
}
|
||||
else {
|
||||
if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"))
|
||||
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
|
||||
|
||||
if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe"))
|
||||
ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
|
||||
}
|
||||
}
|
||||
|
||||
GetChromeVersion(){
|
||||
; https://stackoverflow.com/questions/52457766/how-can-i-get-google-chromes-version-number
|
||||
; Command = powershell `$ChromePath = 'C:\Program Files\Google\Chrome\Application\chrome.exe' `; [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion
|
||||
|
||||
; command = powershell $(Get-Package -Name 'Google Chrome').Version
|
||||
; ChromeVersion := RunCMD(command)
|
||||
; ChromeVersion := StrSplit(ChromeVersion, "`r")[1] ; remove newline character if it exists
|
||||
|
||||
if(ChromeFilepath = ""){
|
||||
GetChromeFilepath()
|
||||
}
|
||||
|
||||
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
||||
Chromeversion := RunCMD(GetChromeVersionCommand)
|
||||
ChromeVersion := StrReplace(ChromeVersion, "`r")[1] ; replace any newline characters that powershell returns
|
||||
return ChromeVersion
|
||||
}
|
||||
|
||||
|
||||
GetURLofLatestChromedriver(ChromeVersion){
|
||||
|
||||
; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints
|
||||
json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json")
|
||||
|
||||
; requires #include of json.ahk in parent script
|
||||
parsed := JSON.Load(json_str)
|
||||
|
||||
ChromelabsJsonEntriesCount := parsed.versions.count()
|
||||
|
||||
if(ChromelabsJsonEntriesCount = ""){
|
||||
return "Failed to parse chromedriver json. "
|
||||
}
|
||||
|
||||
loop % ChromelabsJsonEntriesCount {
|
||||
|
||||
if(A_index = ChromelabsJsonEntriesCount){
|
||||
Message = "Failed to find %ChromeVersion% in the ChromeLabs Json"
|
||||
return Message
|
||||
}
|
||||
|
||||
if(ChromeVersion = parsed.versions[A_Index].version){
|
||||
|
||||
VersionIndex := A_Index
|
||||
|
||||
; loop through the platforms to get download URL
|
||||
loop % parsed.versions[VersionIndex].downloads.chromedriver.count() {
|
||||
|
||||
; 64 bit version
|
||||
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64")
|
||||
chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
|
||||
|
||||
; 32 bit version
|
||||
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win32")
|
||||
chromedriverDLURL32 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
; Msgbox % "chromedriverDLURL32: " chromedriverDLURL32
|
||||
; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64
|
||||
return chromedriverDLURL32
|
||||
}
|
Loading…
Reference in New Issue