#include #include "..\wd_helper.au3" ; https://github.com/Danp2/WebDriver #REMARK this following line I use for testing, while wd_capabilities.au3 UDF is in early Beta version stage #AutoIt3Wrapper_AutoIt3Dir="z:\AutoItPortable\AutoIt_3_3_14_5" #Region - wd_capabilities.au3 UDF - Header - early version #CS Core functions: _WD_CapabilitiesStartup() _WD_CapabilitiesAdd() _WD_CapabilitiesGet() Internal functions: __WD_CapabilitiesInitialize() __WD_CapabilitiesSwitch() __WD_CapabilitiesNotation() Helper Functions: _WD_CapabilitiesDump() _WD_CapabilitiesDisplay() #CE #TODO _WD_CreateSession: {"value":{"error":"session not created","message":"Unable to find a matching set of capabilities","stacktrace":""}} #EndRegion - wd_capabilities.au3 UDF - Header - early version #Region - wd_capabilities.au3 UDF - Global's declarations Global Enum _ $_WD_CAPS__STANDARD__Type, _ $_WD_CAPS__STANDARD__FirstIdx, _ $_WD_CAPS__STANDARD__STRINGORBOOL, _ $_WD_CAPS__STANDARD__PROXY, _ $_WD_CAPS__STANDARD__TIMEOUTS, _ $_WD_CAPS__SPECIFICVENDOR__ObjectName, _ $_WD_CAPS__SPECIFICVENDOR__OPTS, _ $_WD_CAPS__SPECIFICVENDOR__ARGS, _ $_WD_CAPS__SPECIFICVENDOR__PREFS, _ $_WD_CAPS__SPECIFICVENDOR__LOG, _ $_WD_CAPS__SPECIFICVENDOR__ENV, _ $_WD_CAPS__SPECIFICVENDOR__EXCSWITCH, _ $_WD_CAPS__COUNTER Global $_WD_CAPS__API[0][$_WD_CAPS__COUNTER] Global Const $_WD_CAPS__ARRAY_HEADER_NAMES = _ "STANDARD__Type" & "|" & _ "STANDARD__FirstIdx" & "|" & _ "STANDARD__STRINGORBOOL" & "|" & _ "STANDARD__PROXY" & "|" & _ "STANDARD__TIMEOUTS" & "|" & _ "SPECIFICVENDOR__ObjectName" & "|" & _ "SPECIFICVENDOR__OPTS" & "|" & _ "SPECIFICVENDOR__ARGS" & "|" & _ "SPECIFICVENDOR__PREFS" & "|" & _ "SPECIFICVENDOR__LOG" & "|" & _ "SPECIFICVENDOR__ENV" & "|" & _ "SPECIFICVENDOR__EXCSWITCH" & "|" & _ "" Global $_WD_CAPS__OBJECT Global $_WD_CAPS__CURRENTIDX = -1 #EndRegion - wd_capabilities.au3 UDF - Global's declarations #Region - wd_capabilities.au3 UDF - examples Global Const $_EXAMPLE_DRIVER_FIREFOX = @ScriptDir & '\..\geckodriver.exe' ; CHANGE TO PROPER FILE FULL PATH Global Const $_EXAMPLE_DRIVER_CHROME = @ScriptDir & '\..\chromedriver.exe' ; CHANGE TO PROPER FILE FULL PATH Global Const $_EXAMPLE_DRIVER_EDGE = @ScriptDir & '\..\msedgedriver.exe' ; CHANGE TO PROPER FILE FULL PATH Global Const $_EXAMPLE_PROFILE_FIREFOX = @LocalAppDataDir & '\Mozilla\Firefox\Profiles\WD_Testing_Profile' ; CHANGE TO PROPER DIRECTORY PATH Global Const $_EXAMPLE_PROFILE_CHROME = @LocalAppDataDir & '\Google\Chrome\User Data\Default' ; CHANGE TO PROPER DIRECTORY PATH Global Const $_EXAMPLE_PROFILE_EDGE = @LocalAppDataDir & 'TODO_______TODO' ; CHANGE TO PROPER DIRECTORY PATH Global Const $_EXAMPLE_DOWNLOAD_DIR = @UserProfileDir & '\Downloads\WD_Testing_download' ; CHANGE TO PROPER DIRECTORY PATH Global Const $_EXAMPLE_OPTION_RUN_BROWSER = ( _ $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, 'Question', _ 'Do you want to test with running browsers ?' & @CRLF & _ '' & @CRLF & _ ' [YES] = Run browser' & @CRLF & _ ' [NO] = only put $s_Capabilities_JSON to console') _ ) Global Const $_EXAMPLE_OPTION_CHOOSEN_DRIVER = (($_EXAMPLE_OPTION_RUN_BROWSER) ? (_WD_Capabilities_Example_ChooseDriver()) : ('')) Global Const $_EXAMPLE_OPTION_HEADLESS = ($_EXAMPLE_OPTION_RUN_BROWSER And _ ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, 'Question', _ 'Do you want to test with headless mode ?' & @CRLF & _ '' & @CRLF & _ ' [YES] = Run browser in headless mode' & @CRLF & _ ' [NO] = Run browser in "visible" mode') _ ) _ ) Global Const $_EXAMPLE_OPTION_PROXY = _ ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, 'Question', _ 'Do you want to test with connection buffered via Proxy server ?' & @CRLF & _ '' & @CRLF & _ ' [YES] = use Proxy' & @CRLF & _ ' [NO] = direct coonection') _ ) Global Const $_EXAMPLE_OPTION_ALLCAPS = _ ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, 'Question', _ 'Do you want to test with Capabilities for all "firstMatch" ?' & @CRLF & _ '' & @CRLF & _ ' [YES] = test "firstMatch" Capabilites for all browser toogether' & @CRLF & _ ' [NO] = test only "firstMatch" desired for specified browser') _ ) _WD_Capabilities_Example() Exit Func _WD_Capabilities_Example() _WD_CapabilitiesStartup() ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) #Region - _WD_Capabilities_Example() ... "alwaysMatch" section _WD_CapabilitiesAdd('alwaysMatch') _WD_CapabilitiesAdd('acceptInsecureCerts', True) _WD_CapabilitiesAdd('timeouts', 'script', 300) ; https://www.w3.org/TR/webdriver/#timeouts _WD_CapabilitiesAdd('timeouts', 'pageLoad', 30000) ; https://www.w3.org/TR/webdriver/#timeouts _WD_CapabilitiesAdd('timeouts', 'implicit', 4) ; https://www.w3.org/TR/webdriver/#timeouts If $_EXAMPLE_OPTION_PROXY Then _WD_CapabilitiesAdd('proxy', 'proxyType', 'manual') _WD_CapabilitiesAdd('proxy', 'proxyAutoconfigUrl', '127.0.0.1') ; change '127.0.0.1' to your own 'proxyAutoconfigUrl' host _WD_CapabilitiesAdd('proxy', 'ftpProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'ftpProxy' host _WD_CapabilitiesAdd('proxy', 'httpProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'httpProxy' host _WD_CapabilitiesAdd('proxy', 'noProxy', 'www.w3.org') ; an example url which should not to bo opened via proxy server _WD_CapabilitiesAdd('proxy', 'noProxy', 'www.autoitscript.com') ; an example url which should not to bo opened via proxy server _WD_CapabilitiesAdd('proxy', 'noProxy', 'www.google.com') ; an example url which should not to bo opened via proxy server _WD_CapabilitiesAdd('proxy', 'noProxy', 'www.google.pl') ; an example url which should not to bo opened via proxy server _WD_CapabilitiesAdd('proxy', 'sslProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'sslProxy' host _WD_CapabilitiesAdd('proxy', 'socksProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'socksProxy' host _WD_CapabilitiesAdd('proxy', 'socksVersion', 1) EndIf #TODO check why 'WIN10' have issue when using FireFox - with the commented following line ;~ _WD_CapabilitiesAdd('platformName', 'WIN10') ; https://stackoverflow.com/a/45621125/5314940 _WD_CapabilitiesDump(@ScriptLineNumber) #EndRegion - _WD_Capabilities_Example() ... "alwaysMatch" section #Region - _WD_Capabilities_Example() ... "firstMatch" section for Microsoft Edge If $_EXAMPLE_OPTION_ALLCAPS Or $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_EDGE Then ; https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) _WD_CapabilitiesAdd('firstMatch', 'edge') _WD_CapabilitiesDump(@ScriptLineNumber) #TODO CHECK .... "invalid argument: entry 0 of 'firstMatch' is invalid\nfrom invalid argument: unrecognized capability: browsername" ;~ _WD_CapabilitiesAdd('browsername', 'edge') #TODO CHECK .... How to use 'WIN10' ;~ _WD_CapabilitiesAdd('platformName', 'WIN10') _WD_CapabilitiesAdd('w3c', True) #TODO CHECK .... How to use 'maxInstances' ;~ _WD_CapabilitiesAdd('maxInstances', 1) ; https://stackoverflow.com/a/45621125/5314940 If $_EXAMPLE_OPTION_HEADLESS Then _ _WD_CapabilitiesAdd('args', '--headless') _WD_CapabilitiesAdd('prefs', 'plugins.always_open_pdf_externally', True) ; https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/?do=findComment&comment=1482786 _WD_CapabilitiesAdd('prefs', 'edge.sleeping_tabs.enabled', False) ; https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/?do=findComment&comment=1482798 _WD_CapabilitiesDump(@ScriptLineNumber) EndIf #EndRegion - _WD_Capabilities_Example() ... "firstMatch" section for Microsoft Edge #Region - _WD_Capabilities_Example() ... "firstMatch" section for Microsoft Google Chrome If $_EXAMPLE_OPTION_ALLCAPS Or $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_CHROME Then ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) _WD_CapabilitiesAdd('firstMatch', 'chrome') #TODO ADD REMARK about: "firstMatch key shadowed a value in alwaysMatch" _WD_CapabilitiesAdd('browserName', 'chrome') ;~ _WD_CapabilitiesAdd('platformName', 'WIN10') _WD_CapabilitiesAdd('w3c', True) #TODO check how to use 'binary' # _WD_CapabilitiesAdd('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe') If $_EXAMPLE_OPTION_HEADLESS Then _ _WD_CapabilitiesAdd('args', '--headless') _WD_CapabilitiesAdd('args', 'start-maximized') _WD_CapabilitiesAdd('args', 'disable-infobars') _WD_CapabilitiesAdd('args', 'user-data-dir', $_EXAMPLE_PROFILE_CHROME) _WD_CapabilitiesAdd('args', '--profile-directory', Default) _WD_CapabilitiesAdd('excludeSwitches', 'disable-popup-blocking') ; https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation') _WD_CapabilitiesAdd('excludeSwitches', 'load-extension') _WD_CapabilitiesDump(@ScriptLineNumber) EndIf #EndRegion - _WD_Capabilities_Example() ... "firstMatch" section for Microsoft Google Chrome #Region - _WD_Capabilities_Example() ... "firstMatch" section for FireFox If $_EXAMPLE_OPTION_ALLCAPS Or $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_FIREFOX Then ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) _WD_CapabilitiesAdd('firstMatch', 'firefox') _WD_CapabilitiesAdd('browserName', 'firefox') If $_EXAMPLE_OPTION_HEADLESS Then _ _WD_CapabilitiesAdd('args', '--headless') _WD_CapabilitiesAdd('args', '-profile') _WD_CapabilitiesAdd('args', $_EXAMPLE_PROFILE_FIREFOX) _WD_CapabilitiesAdd('prefs', 'download.default_directory', @ScriptDir) _WD_CapabilitiesAdd('prefs', 'dom.ipc.processCount', 8) _WD_CapabilitiesAdd('prefs', 'javascript.options.showInConsole', False) _WD_CapabilitiesAdd('prefs', 'browser.toolbars.bookmarks.visibility', 'always') ; check about:config _WD_CapabilitiesAdd('prefs', 'app.update.download.attempts', 0) ; check about:config _WD_CapabilitiesAdd('prefs', 'browser.safebrowsing.downloads.enabled', False) ; check about:config _WD_CapabilitiesAdd('prefs', 'browser.safebrowsing.downloads.enabled', False) ; check about:config ; https://tarunlalwani.com/post/change-profile-settings-at-runtime-firefox-selenium/ # 0 means to download to the desktop, 1 means to download to the default "Downloads" directory, 2 means to use the directory _WD_CapabilitiesAdd('prefs', 'browser.download.folderList', 2) _WD_CapabilitiesAdd('prefs', 'browser.download.manager.showWhenStarting', False) _WD_CapabilitiesAdd('prefs', 'browser.download.dir', $_EXAMPLE_DOWNLOAD_DIR) _WD_CapabilitiesAdd('prefs', 'browser.helperApps.neverAsk.saveToDisk', 'application/x-gzip') _WD_CapabilitiesAdd('prefs', 'browser.helperApps.neverAsk.saveToDisk', 'application/zip') _WD_CapabilitiesAdd('log', 'level', 'trace') _WD_CapabilitiesAdd('env', 'MOZ_LOG', 'nsHttp:5') _WD_CapabilitiesAdd('env', 'MOZ_LOG_FILE', $_EXAMPLE_PROFILE_FIREFOX & '\log') _WD_CapabilitiesDump(@ScriptLineNumber) EndIf #EndRegion - _WD_Capabilities_Example() ... "firstMatch" section for FireFox _WD_CapabilitiesDisplay(@ScriptLineNumber) If Not $_EXAMPLE_OPTION_RUN_BROWSER Then Return _WD_Option('Driver', $_EXAMPLE_OPTION_CHOOSEN_DRIVER) If $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_FIREFOX Then _WD_Option('Port', 4444) If $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_CHROME Then _WD_Option('Port', 9515) If $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_EDGE Then _WD_Option('Port', 9515) _WD_Startup() Local $s_Capabilities_JSON = _WD_CapabilitiesGet() ;~ Local $s_Capabilities_JSON = _WD_CapabilitiesGet() ConsoleWrite("! $s_Capabilities_JSON = " & $s_Capabilities_JSON & @CRLF) Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON) If Not @Compiled Then MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()") _WD_DeleteSession($WD_SESSION) _WD_Shutdown() EndFunc ;==>_WD_Capabilities_Example Func _WD_Capabilities_Example_ChooseDriver() Local $_CHOOSEN_DRIVER = '' If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _ "Do you want to use FireFox browser") Then $_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_FIREFOX ElseIf $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _ "Do you want to use Google Chrome browser") Then $_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_CHROME ElseIf $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _ "Do you want to use Miscrosoft Edge browser") Then $_CHOOSEN_DRIVER = $_EXAMPLE_DRIVER_EDGE EndIf If Not FileExists($_CHOOSEN_DRIVER) Then MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONERROR, "! Error occurred", _ "WebDriver file:" & @CRLF & _ $_CHOOSEN_DRIVER & @CRLF & _ "Not exist !" & @CRLF & _ "") Exit EndIf ConsoleWrite("> USING: " & $_CHOOSEN_DRIVER & @CRLF) Return $_CHOOSEN_DRIVER EndFunc ;==>_WD_Capabilities_Example_ChooseDriver #EndRegion - wd_capabilities.au3 UDF - examples #Region - wd_capabilities.au3 UDF - core functions ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_CapabilitiesStartup ; Description ...: Clear Object and API $_WD_CAPS__API start creating new JSON string for WebDriver Capabilities ; Syntax ........: _WD_CapabilitiesStartup() ; Parameters ....: None ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WD_CapabilitiesStartup() $_WD_CAPS__OBJECT = '' ReDim $_WD_CAPS__API[0][$_WD_CAPS__COUNTER] EndFunc ;==>_WD_CapabilitiesStartup ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_CapabilitiesAdd ; Description ...: Add capablitities to JSON string ; Syntax ........: _WD_CapabilitiesAdd($key[, $value1 = ''[, $value2 = '']]) ; Parameters ....: $key - an unknown value. ; $value1 - [optional] a variant value. Default is ''. ; $value2 - [optional] a variant value. Default is ''. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WD_CapabilitiesAdd($key, $value1 = '', $value2 = '') If $value1 = Default Then $value1 = 'default' If $value2 = Default Then $value2 = 'default' If StringInStr('alwaysMatch|firstMatch', $key) Then $_WD_CAPS__CURRENTIDX = __WD_CapabilitiesInitialize($key, $value1) Return SetError(@error, @extended, $_WD_CAPS__CURRENTIDX) EndIf #TODO use $value2 for "noProxy" https://www.w3.org/TR/webdriver/#dfn-page-load-strategy Local $s_Notation = '' If $key = 'excludeSwitches' Then ; for adding "excludeSwitches" capability in specific/vendor capabilities : ........ $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__SPECIFICVENDOR__EXCSWITCH) ElseIf $key = 'timeouts' Then ; for adding "proxy" capability in standard capability : https://www.w3.org/TR/webdriver/#capabilities $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__STANDARD__TIMEOUTS) $s_Notation &= '[' & $value1 & ']' ; here is specified keyName in {timeouts} JSON OBJECT __WD_CapabilitiesSwitch($key, $value1, $value2) ; as the notation was modified now parameters should be switched ElseIf $key = 'proxy' Then ; for adding "proxy" capability in standard capabilities : https://www.w3.org/TR/webdriver/#dfn-proxy-configuration $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__STANDARD__PROXY) If $value1 = 'noProxy' Then ; for add string to "noProxy" JSON ARRAY in standard capabilities : https://www.w3.org/TR/webdriver/#dfn-proxy-configuration $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__STANDARD__PROXY] += 1 ; default is -1 so first should be 0 Local $i_Current_noProxy = $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__STANDARD__PROXY] $s_Notation &= '[noProxy][' & $i_Current_noProxy & ']' ; here is specified which one of [noProxy] JSON ARRAY element should be used Else $s_Notation &= '[' & $value1 & ']' ; here is specified keyName in {proxy} JSON OBJECT EndIf __WD_CapabilitiesSwitch($key, $value1, $value2) ; as the notation was modified now parameters should be switched ;~ If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) ElseIf $key = 'w3c' Or $key = 'maxInstances' Then ; for adding "w3c" capability in specific/vendor capabilities : ........ $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__SPECIFICVENDOR__OPTS) $s_Notation &= '[' & $key & ']' ;~ If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) ElseIf $key = 'args' Then ; for adding "args" capability in specific/vendor capabilities : ........ $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__SPECIFICVENDOR__ARGS) __WD_CapabilitiesSwitch($key, $value1, $value2) ; as the notation was modified now parameters should be switched If $value1 Then $value1 = $key & '=' & $value1 Else $value1 = $key EndIf If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & ' = ' & $value1 & @CRLF) ElseIf $key = 'prefs' Then ; for adding "prefs" capability in specific/vendor capabilities : ........ $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__SPECIFICVENDOR__PREFS) __WD_CapabilitiesSwitch($key, $value1, $value2) ; as the notation was modified now parameters should be switched $s_Notation &= '[' & $key & ']' ;~ If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) ElseIf $key = 'log' Then ; for adding "log" capability in specific/vendor capabilities : ........ $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__SPECIFICVENDOR__LOG) __WD_CapabilitiesSwitch($key, $value1, $value2) ; as the notation was modified now parameters should be switched $s_Notation &= '[' & $key & ']' ;~ If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) ElseIf $key = 'env' Then ; for adding "env" capability in specific/vendor capabilities : ........ $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__SPECIFICVENDOR__ENV) __WD_CapabilitiesSwitch($key, $value1, $value2) ; as the notation was modified now parameters should be switched $s_Notation &= '[' & $key & ']' ;~ If Not @Compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) ElseIf $value2 = '' Then ; for string/boolean value type in standard capability : https://www.w3.org/TR/webdriver/#capabilities $s_Notation = __WD_CapabilitiesNotation($_WD_CAPS__STANDARD__STRINGORBOOL) $s_Notation &= '[' & $key & ']' Else ; not supported option Return SetError(1) EndIf If @error Then Return SetError(@error, @extended, $s_Notation) Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value1) ;~ If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF) EndFunc ;==>_WD_CapabilitiesAdd ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_CapabilitiesGet ; Description ...: Get the JSON string ; Syntax ........: _WD_CapabilitiesGet() ; Parameters ....: None ; Return values .: JSON string ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WD_CapabilitiesGet() Local $Data2 = Json_Encode($_WD_CAPS__OBJECT) Local $Data1 = Json_Decode($Data2) Local $Json2 = Json_Encode($Data1, $Json_UNQUOTED_STRING) Local $Data3 = Json_Decode($Json2) Local $Json3 = Json_Encode($Data3, $Json_PRETTY_PRINT, " ", ",\n", ",\n", ":") Return $Json3 EndFunc ;==>_WD_CapabilitiesGet #EndRegion - wd_capabilities.au3 UDF - core functions #Region - wd_capabilities.au3 UDF - internal functions ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_CapabilitiesInitialize ; Description ...: Initialize $_WD_CAPS__API and presets for 'alwaysMatch' Or 'firstMatch' ; Syntax ........: __WD_CapabilitiesInitialize($s_MatchType[, $s_Browser_type = '']) ; Parameters ....: $s_MatchType - a string value. 'alwaysMatch' Or 'firstMatch' ; $s_Browser_type - [optional] a string value. Default is ''. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_CapabilitiesInitialize($s_MatchType, $s_Browser_type = '') ; $s_MatchType = 'alwaysMatch' Or 'firstMatch' #Region - parameters validation ;~ ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) If Not StringInStr('alwaysMatch|firstMatch', $s_MatchType) Then _ Return SetError(1) ;~ ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) ;~ MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "$s_Browser_type = " & $s_Browser_type & @CRLF & "$s_MatchType = " & $s_MatchType) Local $s_SpecificOptions_KeyName = '' If StringInStr($s_Browser_type, 'chrome') Then $s_SpecificOptions_KeyName = 'goog:chromeOptions' ElseIf StringInStr($s_Browser_type, 'firefox') Then $s_SpecificOptions_KeyName = 'moz:firefoxOptions' ElseIf StringInStr($s_Browser_type, 'edge') Then $s_SpecificOptions_KeyName = 'ms:edgeOptions' ElseIf $s_MatchType = 'alwaysMatch' And $s_Browser_type = '' Then $s_SpecificOptions_KeyName = '' ElseIf $s_MatchType = 'firstMatch' And $s_Browser_type = '' Then Return SetError(2) EndIf #EndRegion - parameters validation #Region - reindexing API Local $i_API_Recent_Size = UBound($_WD_CAPS__API), $i_API_New_Size = $i_API_Recent_Size + 1, $i_API_New_IDX = $i_API_New_Size - 1 ReDim $_WD_CAPS__API[$i_API_New_Size][$_WD_CAPS__COUNTER] ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) #EndRegion - reindexing API #Region - new "MATCH" Initialization $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__STANDARD__Type] = $s_MatchType Local Static $i_FirstMatch_Counter = -1 If $s_MatchType = 'firstMatch' Then $i_FirstMatch_Counter += 1 ; default is -1 so first should be 0 $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__STANDARD__FirstIdx] = $i_FirstMatch_Counter EndIf $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__STANDARD__STRINGORBOOL] = Null $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__STANDARD__PROXY] = -1 ; used for indexing ...... "noProxy" : [JSON ARRRAY] $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__ObjectName] = $s_SpecificOptions_KeyName $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__OPTS] = Null $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__ARGS] = -1 ; used for indexing ...... "args" : [JSON ARRRAY] $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__PREFS] = Null $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__LOG] = Null $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__ENV] = Null $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__SPECIFICVENDOR__EXCSWITCH] = -1 ; used for indexing ...... "excludeSwitches" : [JSON ARRRAY] $_WD_CAPS__CURRENTIDX = $i_API_New_IDX ; set last API IDX as CURRENT API IDX #EndRegion - new "MATCH" Initialization ;~ ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF) Return $_WD_CAPS__CURRENTIDX ; return current API IDX #Region - FOR TESTING ONLY Local $s_Information = _ "$s_Browser_type = " & $s_Browser_type & @CRLF & _ "$s_MatchType = " & $s_MatchType & @CRLF & _ "$s_SpecificOptions_KeyName = " & $s_SpecificOptions_KeyName & @CRLF & _ "$i_FirstMatch_Counter = " & $i_FirstMatch_Counter & @CRLF & _ "$_WD_CAPS__CURRENTIDX = " & $_WD_CAPS__CURRENTIDX & @CRLF & _ '' If Not @Compiled Then MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, $s_Information) #EndRegion - FOR TESTING ONLY EndFunc ;==>__WD_CapabilitiesInitialize ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_CapabilitiesSwitch ; Description ...: switching parameters position to the left ; Syntax ........: __WD_CapabilitiesSwitch(Byref $key, Byref $value1, Byref $value2) ; Parameters ....: $key - [in/out] an unknown value. ; $value1 - [in/out] a variant value. ; $value2 - [in/out] a variant value. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_CapabilitiesSwitch(ByRef $key, ByRef $value1, ByRef $value2) $key = $value1 $value1 = $value2 $value2 = '' EndFunc ;==>__WD_CapabilitiesSwitch ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_CapabilitiesNotation ; Description ...: get desired notation prefix for specitfied JSON object ; Syntax ........: __WD_CapabilitiesNotation($i_BUILDER_TYPE) ; Parameters ....: $i_BUILDER_TYPE - an integer value. one of $_WD_CAPS__** enums ; Return values .: None ; Author ........: notation prefix in Json.au3 format ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_CapabilitiesNotation($i_BUILDER_TYPE) ;~ MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "$_WD_CAPS__CURRENTIDX = " & $_WD_CAPS__CURRENTIDX & ' Ubound = ' & UBound($_WD_CAPS__API)) Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__STANDARD__Type] & ']' If $s_CurrentMatch_Type = '[firstMatch]' Then $s_CurrentMatch_Type &= '[' & $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__STANDARD__FirstIdx] & ']' EndIf Local $s_SpecificOptions_KeyName = $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__SPECIFICVENDOR__ObjectName] If $s_SpecificOptions_KeyName Then $s_SpecificOptions_KeyName = '["' & $s_SpecificOptions_KeyName & '"]' If $s_SpecificOptions_KeyName = '' And $i_BUILDER_TYPE >= $_WD_CAPS__SPECIFICVENDOR__ARGS Then _ Return SetError(1, 0, '') ; ARGS, PREFS, LOG, ENV and any further are possible only when Specific/Vendor Capability was specified Local $s_Notation = '' Switch $i_BUILDER_TYPE Case $_WD_CAPS__STANDARD__STRINGORBOOL $s_Notation = '[capabilities]' & $s_CurrentMatch_Type Case $_WD_CAPS__STANDARD__PROXY $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & '[proxy]' ; here is specified the name for {proxy} JSON OBJECT Case $_WD_CAPS__STANDARD__TIMEOUTS $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & '[timeouts]' ; here is specified the name for {timeout} JSON OBJECT Case $_WD_CAPS__SPECIFICVENDOR__OPTS $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName ; here is specified the name for {SPECIFIC VENDOR NAME} JSON OBJECT Case $_WD_CAPS__SPECIFICVENDOR__ARGS $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__SPECIFICVENDOR__ARGS] += 1 ; default is -1 so first should be 0 Local $i_Current_Arg = $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__SPECIFICVENDOR__ARGS] $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[args][' & $i_Current_Arg & ']' ; here is specified which one of [args] JSON ARRAY element should be used Case $_WD_CAPS__SPECIFICVENDOR__PREFS $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[prefs]' ; here is specified the name for {prefs} JSON OBJECT Case $_WD_CAPS__SPECIFICVENDOR__LOG $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[log]' ; here is specified the name for {log} JSON OBJECT Case $_WD_CAPS__SPECIFICVENDOR__ENV $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[env]' ; here is specified the name for {env} JSON OBJECT Case $_WD_CAPS__SPECIFICVENDOR__EXCSWITCH $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__SPECIFICVENDOR__EXCSWITCH] += 1 ; default is -1 so first should be 0 Local $i_Current_ExcSwitch = $_WD_CAPS__API[$_WD_CAPS__CURRENTIDX][$_WD_CAPS__SPECIFICVENDOR__EXCSWITCH] $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[excludeSwitches][' & $i_Current_ExcSwitch & ']' ; here is specified which one of [excluedSwitches] JSON ARRAY element should be used EndSwitch ;~ If Not @compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF) Return $s_Notation EndFunc ;==>__WD_CapabilitiesNotation #EndRegion - wd_capabilities.au3 UDF - internal functions #Region - wd_capabilities.au3 UDF - helper functions ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_CapabilitiesDump ; Description ...: Dump $_WD_CAPS__API and JSON string to console ; Syntax ........: _WD_CapabilitiesDump($s_Comment) ; Parameters ....: $s_Comment - a string value. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WD_CapabilitiesDump($s_Comment) If @Compiled Then Return ; because of GDRP reason do not throw nothing to console when compiled script ConsoleWrite(@LF & '! _WD_Capabilities: API START: ' & $s_Comment & @LF) ConsoleWrite("- $_WD_CAPS__API: Rows= " & UBound($_WD_CAPS__API, 1) & @CRLF) ConsoleWrite("- $_WD_CAPS__API: Cols= " & UBound($_WD_CAPS__API, 2) & @CRLF) ConsoleWrite(_ArrayToString($_WD_CAPS__API) & @LF) ConsoleWrite(@LF & '! _WD_Capabilities: API END: ' & $s_Comment & @LF & @LF) ConsoleWrite(@LF & '! _WD_Capabilities: JSON START: ' & $s_Comment & @LF) ConsoleWrite(_WD_CapabilitiesGet()) ConsoleWrite(@LF & '! _WD_Capabilities: JSON END: ' & $s_Comment & @LF & @LF) EndFunc ;==>_WD_CapabilitiesDump ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_CapabilitiesDisplay ; Description ...: Display the current content of $_WD_CAPS__API ; Syntax ........: _WD_CapabilitiesDisplay($s_Comment) ; Parameters ....: $s_Comment - a string value. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WD_CapabilitiesDisplay($s_Comment) Local $s_Title = $s_Comment & ' $_WD_CAPS__API Rows= ' & UBound($_WD_CAPS__API, 1) & ' Cols= ' & UBound($_WD_CAPS__API, 2) & @LF _ArrayDisplay($_WD_CAPS__API, $s_Title, "", Default, Default, $_WD_CAPS__ARRAY_HEADER_NAMES) EndFunc ;==>_WD_CapabilitiesDisplay #EndRegion - wd_capabilities.au3 UDF - helper functions