Jump to content

wd_capabilities.au3 - support topic - early BETA version - Work In Progress


mLipok
 Share

Recommended Posts

As for now this UDF' has only 300 lines and is workable.
I am sure I can shorten it even more.
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

43 minutes ago, Danp2 said:

I wonder if you could build this with the JSON UDF that is already part of the Webdriver UDF?

I even try to do it some time later earlier, but I give up.
Currently I back to this project and start to think as a parsing string to get knowledge about JSON and WebDriver ... to organize it in my head.

I can again try to move to JSON UDF.
Maybe in the comming week.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

so ... you ask about version which use JSON.au3 ....

this is first version:

#include <WinAPICom.au3>
#include "..\wd_helper.au3"

Global $Obj
Global $CURRENT_MATCH_IDX = -1
Global Enum _
        $_WD_CAPS__MATCH__Type, _
        $_WD_CAPS__MATCH__FirstIdx, _
        $_WD_CAPS__MATCH__CAPS_IDX, _
        $_WD_CAPS__MATCH__Specyfic, _
        $_WD_CAPS__MATCH__OPTS_IDX, _
        $_WD_CAPS__MATCH__ARGS_IDX, _
        $_WD_CAPS__MATCH__PREFS_IDX, _
        $_WD_CAPS__MATCH__LOG_IDX, _
        $_WD_CAPS__MATCH__ENV_IDX, _
        $_WD_CAPS__MATCH__COUNTER

Global $_WD_CAPS__API[0][$_WD_CAPS__MATCH__COUNTER]

_Example()
Exit

#Region - examples
Func _Example()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
;~  _Example_Danp2()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)

    If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Do you want to test with running browsers ?") Then
        Local $b_Headless = ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", "Do you want to test with headless mode ?"))
        _Example_Chrome(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    Else ; only show $s_Desired_Capabilities in console
        _Example_Chrome(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    EndIf
EndFunc   ;==>_Example

Func _Example_Chrome($b_Run_Browser, $b_Headless = False)
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('always', 'chrome')
    _WD_Capabilities_Capability('browserName', 'chrome')
;~  _WD_Capabilities_Option('w3c', True)
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    _WD_Capabilities_Argument('start-maximized')
    _WD_Capabilities_Argument('disable-infobars')
    _WD_Capabilities_Argument('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default')
    _WD_Capabilities_Preference('download.default_directory', @ScriptDir)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_Chrome

Func _Example_FireFox($b_Run_Browser, $b_Headless = False)
    #forceref $b_Run_Browser, $b_Headless
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('always', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    #TODO timeouts
;~  _WD_Capabilities_Capability('timeouts', '{"implicit": 4, "script": 300, "pageLoad": 30000}')
    #TODO proxy
;~  _WD_Capabilities_Capability('proxy', '{"proxyType": 4, "script": 300, "pageLoad": 30000}')
    #TODO 'binary'
;~  _WD_Capabilities_Option('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    Local $s_My_Profile_Dir = 'c:\Users\' & @UserName & '\AppData\Local\Mozilla\Firefox\Profiles\TESTING.default'
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)

    _WD_Capabilities_Preference('dom.ipc.processCount', 8)
    _WD_Capabilities_Preference('javascript.options.showInConsole', False)
    _WD_Capabilities_Preference('browser.toolbars.bookmarks.visibility', 'always') ; check    about:config
    _WD_Capabilities_Preference('app.update.download.attempts', 0) ; check    about:config
    _WD_Capabilities_Preference('browser.safebrowsing.downloads.enabled', False) ; check    about:config

    _WD_Capabilities_Log('level', 'trace')

    _WD_Capabilities_Env('MOZ_LOG', 'nsHttp:5')
    _WD_Capabilities_Env('MOZ_LOG_FILE', $s_My_Profile_Dir & '\log')

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_FireFox

Func _Example_Danp2()
    Local $s_My_Profile_Dir = @ScriptDir & '\WD_Testing_Profile'
;~  _WD_Capabilities_Startup()
;~  _WD_Capabilities_CreateObject('always', 'firefox')
;~  _WD_Capabilities_Capability('browserName', 'firefox')
;~  _WD_Capabilities_Capability('acceptInsecureCerts', True)
;~  _WD_Capabilities_Argument('-profile')
;~  _WD_Capabilities_Argument($s_My_Profile_Dir)
;~  Local $s_Desired_Capabilities = _WD_Capabilities_Build('firefox')

    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('always', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    Return

    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_Danp2
#EndRegion - examples

#Region - UDF Functions

Func _WD_Capabilities_Startup()
    $Obj = ''
EndFunc   ;==>_WD_Capabilities_Startup

Func _WD_Capabilities_CreateObject($s_MatchType, $s_Browser_type = '') ; $s_MatchType = 'always' Or 'first'
    #Region - parameters validation
    If $s_MatchType <> 'always' And $s_MatchType <> 'first' Then _
            Return SetError(1)

    Local $s_SpecificOption_KeyName = ''
    If StringInStr($s_Browser_type, 'chrome') Then
        $s_SpecificOption_KeyName = 'goog:chromeOptions'
    ElseIf StringInStr($s_Browser_type, 'firefox') Then
        $s_SpecificOption_KeyName = 'moz:firefoxOptions'
    ElseIf StringInStr($s_Browser_type, 'edge') Then
        $s_SpecificOption_KeyName = 'ms:edgeOptions'
    Else
        Return SetError(1)
    EndIf
    #EndRegion - parameters validation

    #Region - reindexing API
    Local $i_API_Recent_Size = UBound($_WD_CAPS__API)

    Local $i_API_New_Size = $i_API_Recent_Size + 1
    ReDim $_WD_CAPS__API[$i_API_New_Size][$_WD_CAPS__MATCH__COUNTER]
    Local $i_API_New_IDX = $i_API_New_Size - 1
    #EndRegion - reindexing API

    #Region - new "MATCH" Initialization
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Type] = $s_MatchType & 'Match'
    If $s_MatchType = 'first' Then
        Local Static $i_FirstMatch_Counter = -1
        $i_FirstMatch_Counter += 1
        $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__FirstIdx] = $i_FirstMatch_Counter
    EndIf
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__CAPS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Specyfic] = $s_SpecificOption_KeyName
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__OPTS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ARGS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__PREFS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__LOG_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ENV_IDX] = -1
    $CURRENT_MATCH_IDX = $i_API_New_IDX ; set API Size as current API IDX
    #EndRegion - new "MATCH" Initialization

    Return $CURRENT_MATCH_IDX ; return current API IDX
EndFunc   ;==>_WD_Capabilities_CreateObject

Func _WD_Capabilities_Capability($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__CAPS_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($Obj, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Capability

Func _WD_Capabilities_Option($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__OPTS_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($Obj, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Option

Func _WD_Capabilities_Argument($key, $value = '')
;~  If $key = '-profile' Then $value = StringReplace($value, '\', '/')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ARGS_IDX)
    If $value Then $key &= '=' & $value
    Json_Put($Obj, $s_Notation, $key)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Argument

Func _WD_Capabilities_Preference($key, $value = '')
;~  If $key = '-profile' Then $value = StringReplace($value, '\', '/')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__PREFS_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($Obj, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Preference

Func _WD_Capabilities_Log($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__LOG_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($Obj, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Log

Func _WD_Capabilities_Env($key, $value = '')
;~  If $key = 'MOZ_LOG_FILE' Then $value = StringReplace($value, '\', '\\')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ENV_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($Obj, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Env

Func __WD_Capabilities_JSON_Notation($i_BUILDER_TYPE)
    Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Type] & ']'
    If $s_CurrentMatch_Type = '[firstMatch]' Then
        $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__FirstIdx] = +1
        $s_CurrentMatch_Type &= '["' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__FirstIdx] & '"]'
    EndIf

    Local $s_SpecificOption_KeyName = '["' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Specyfic] & '"]'

    Local $s_Notation = ''
    Switch $i_BUILDER_TYPE
        Case $_WD_CAPS__MATCH__CAPS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__PREFS_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type
        Case $_WD_CAPS__MATCH__OPTS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__OPTS_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName
        Case $_WD_CAPS__MATCH__ARGS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS_IDX] += 1
            Local $i_Current_Arg = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS_IDX]
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[args][' & $i_Current_Arg & ']'
        Case $_WD_CAPS__MATCH__PREFS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__PREFS_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[prefs]'
        Case $_WD_CAPS__MATCH__LOG_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__LOG_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[log]'
        Case $_WD_CAPS__MATCH__ENV_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ENV_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[env]'
    EndSwitch
;~  ConsoleWrite("- " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF)
    Return $s_Notation
EndFunc   ;==>__WD_Capabilities_JSON_Notation

#EndRegion - UDF Functions

#Region - Helper

Func _WD_Capabilities_GetPretty()
    Local $Data2 = Json_Encode($Obj)
    Local $Data1 = Json_Decode($Data2)
    Local $Json2 = Json_Encode($Data1, $Json_UNQUOTED_STRING)
;~  ConsoleWrite("- " & $Json2 & @CRLF)
    Local $Data3 = Json_Decode($Json2)

    Local $Json3 = Json_Encode($Data3, $Json_PRETTY_PRINT, "    ", ",\n", ",\n", ":")
    Return $Json3
EndFunc   ;==>_WD_Capabilities_GetPretty

Func _WD_Capabilities_ToConsole($s_Comment)
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON START: ' & $s_Comment & @LF)
    ConsoleWrite(_WD_Capabilities_GetPretty())
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON END: ' & $s_Comment & @LF & @LF)
EndFunc   ;==>_WD_Capabilities_ToConsole
#EndRegion - Helper

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

now take a look on _Example_Danp2()
There is used "firstMatch"  twice !

#include <WinAPICom.au3>
#include "..\wd_helper.au3"

Global $_WD_CAPS__OBJECT
Global $CURRENT_MATCH_IDX = -1
Global Enum _
        $_WD_CAPS__MATCH__Type, _
        $_WD_CAPS__MATCH__FirstIdx, _
        $_WD_CAPS__MATCH__CAPS_IDX, _
        $_WD_CAPS__MATCH__Specyfic, _
        $_WD_CAPS__MATCH__OPTS_IDX, _
        $_WD_CAPS__MATCH__ARGS_IDX, _
        $_WD_CAPS__MATCH__PREFS_IDX, _
        $_WD_CAPS__MATCH__LOG_IDX, _
        $_WD_CAPS__MATCH__ENV_IDX, _
        $_WD_CAPS__MATCH__COUNTER

Global $_WD_CAPS__API[0][$_WD_CAPS__MATCH__COUNTER]

_Example()
Exit

#Region - examples
Func _Example()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    _Example_Danp2()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    Return

    If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Do you want to test with running browsers ?") Then
        Local $b_Headless = ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", "Do you want to test with headless mode ?"))
        _Example_Chrome(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    Else ; only show $s_Desired_Capabilities in console
        _Example_Chrome(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    EndIf
EndFunc   ;==>_Example

Func _Example_Chrome($b_Run_Browser, $b_Headless = False)
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'chrome')
    _WD_Capabilities_Capability('browserName', 'chrome')
;~  _WD_Capabilities_Option('w3c', True)
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    _WD_Capabilities_Argument('start-maximized')
    _WD_Capabilities_Argument('disable-infobars')
    _WD_Capabilities_Argument('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default')
    _WD_Capabilities_Preference('download.default_directory', @ScriptDir)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_Chrome

Func _Example_FireFox($b_Run_Browser, $b_Headless = False)
    #forceref $b_Run_Browser, $b_Headless
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    #TODO timeouts
;~  _WD_Capabilities_Capability('timeouts', '{"implicit": 4, "script": 300, "pageLoad": 30000}')
    #TODO proxy
;~  _WD_Capabilities_Capability('proxy', '{"proxyType": 4, "script": 300, "pageLoad": 30000}')
    #TODO 'binary'
;~  _WD_Capabilities_Option('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    Local $s_My_Profile_Dir = 'c:\Users\' & @UserName & '\AppData\Local\Mozilla\Firefox\Profiles\TESTING.default'
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)

    _WD_Capabilities_Preference('dom.ipc.processCount', 8)
    _WD_Capabilities_Preference('javascript.options.showInConsole', False)
    _WD_Capabilities_Preference('browser.toolbars.bookmarks.visibility', 'always') ; check    about:config
    _WD_Capabilities_Preference('app.update.download.attempts', 0) ; check    about:config
    _WD_Capabilities_Preference('browser.safebrowsing.downloads.enabled', False) ; check    about:config

    _WD_Capabilities_Log('level', 'trace')

    _WD_Capabilities_Env('MOZ_LOG', 'nsHttp:5')
    _WD_Capabilities_Env('MOZ_LOG_FILE', $s_My_Profile_Dir & '\log')

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_FireFox

Func _Example_Danp2()
    Local $s_My_Profile_Dir = @ScriptDir & '\WD_Testing_Profile'

    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)

    _WD_Capabilities_CreateObject('firstMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)

    _WD_Capabilities_CreateObject('firstMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    Return

    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_Danp2
#EndRegion - examples

#Region - UDF Functions

Func _WD_Capabilities_Startup()
    $_WD_CAPS__OBJECT = ''
EndFunc   ;==>_WD_Capabilities_Startup

Func _WD_Capabilities_CreateObject($s_MatchType, $s_Browser_type = '') ; $s_MatchType = 'alwaysMatch' Or 'firstMatch'
    #Region - parameters validation
    If $s_MatchType <> 'alwaysMatch' And $s_MatchType <> 'firstMatch' Then _
            Return SetError(1)

    Local $s_SpecificOption_KeyName = ''
    If StringInStr($s_Browser_type, 'chrome') Then
        $s_SpecificOption_KeyName = 'goog:chromeOptions'
    ElseIf StringInStr($s_Browser_type, 'firefox') Then
        $s_SpecificOption_KeyName = 'moz:firefoxOptions'
    ElseIf StringInStr($s_Browser_type, 'edge') Then
        $s_SpecificOption_KeyName = 'ms:edgeOptions'
    Else
        Return SetError(1)
    EndIf
    #EndRegion - parameters validation

    #Region - reindexing API
    Local $i_API_Recent_Size = UBound($_WD_CAPS__API)

    Local $i_API_New_Size = $i_API_Recent_Size + 1
    ReDim $_WD_CAPS__API[$i_API_New_Size][$_WD_CAPS__MATCH__COUNTER]
    Local $i_API_New_IDX = $i_API_New_Size - 1
    #EndRegion - reindexing API

    #Region - new "MATCH" Initialization
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Type] = $s_MatchType
    If $s_MatchType = 'firstMatch' Then
        Local Static $i_FirstMatch_Counter = -1
        $i_FirstMatch_Counter += 1
        $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__FirstIdx] = $i_FirstMatch_Counter
    EndIf
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__CAPS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Specyfic] = $s_SpecificOption_KeyName
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__OPTS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ARGS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__PREFS_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__LOG_IDX] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ENV_IDX] = -1
    $CURRENT_MATCH_IDX = $i_API_New_IDX ; set API Size as current API IDX
    #EndRegion - new "MATCH" Initialization

    Return $CURRENT_MATCH_IDX ; return current API IDX
EndFunc   ;==>_WD_Capabilities_CreateObject

Func _WD_Capabilities_Capability($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__CAPS_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Capability

Func _WD_Capabilities_Option($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__OPTS_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Option

Func _WD_Capabilities_Argument($key, $value = '')
;~  If $key = '-profile' Then $value = StringReplace($value, '\', '/')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ARGS_IDX)
    If $value Then $key &= '=' & $value
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $key)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Argument

Func _WD_Capabilities_Preference($key, $value = '')
;~  If $key = '-profile' Then $value = StringReplace($value, '\', '/')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__PREFS_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Preference

Func _WD_Capabilities_Log($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__LOG_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Log

Func _WD_Capabilities_Env($key, $value = '')
;~  If $key = 'MOZ_LOG_FILE' Then $value = StringReplace($value, '\', '\\')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ENV_IDX)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
    ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Env

Func __WD_Capabilities_JSON_Notation($i_BUILDER_TYPE)
    Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Type] & ']'
    If $s_CurrentMatch_Type = '[firstMatch]' Then
        $s_CurrentMatch_Type &= '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__FirstIdx] & ']'
    EndIf

    Local $s_SpecificOption_KeyName = '["' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Specyfic] & '"]'

    Local $s_Notation = ''
    Switch $i_BUILDER_TYPE
        Case $_WD_CAPS__MATCH__CAPS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__PREFS_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type
        Case $_WD_CAPS__MATCH__OPTS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__OPTS_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName
        Case $_WD_CAPS__MATCH__ARGS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS_IDX] += 1
            Local $i_Current_Arg = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS_IDX]
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[args][' & $i_Current_Arg & ']'
        Case $_WD_CAPS__MATCH__PREFS_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__PREFS_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[prefs]'
        Case $_WD_CAPS__MATCH__LOG_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__LOG_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[log]'
        Case $_WD_CAPS__MATCH__ENV_IDX
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ENV_IDX] += 1
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOption_KeyName & '[env]'
    EndSwitch
;~  ConsoleWrite("- " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF)
    Return $s_Notation
EndFunc   ;==>__WD_Capabilities_JSON_Notation

#EndRegion - UDF Functions

#Region - Helper

Func _WD_Capabilities_GetPretty()
    Local $Data2 = Json_Encode($_WD_CAPS__OBJECT)
    Local $Data1 = Json_Decode($Data2)
    Local $Json2 = Json_Encode($Data1, $Json_UNQUOTED_STRING)
;~  ConsoleWrite("- " & $Json2 & @CRLF)
    Local $Data3 = Json_Decode($Json2)

    Local $Json3 = Json_Encode($Data3, $Json_PRETTY_PRINT, "    ", ",\n", ",\n", ":")
    Return $Json3
EndFunc   ;==>_WD_Capabilities_GetPretty

Func _WD_Capabilities_ToConsole($s_Comment)
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON START: ' & $s_Comment & @LF)
    ConsoleWrite(_WD_Capabilities_GetPretty())
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON END: ' & $s_Comment & @LF & @LF)
EndFunc   ;==>_WD_Capabilities_ToConsole
#EndRegion - Helper

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

using:

 

Func _Example_Danp2()
    Local $s_My_Profile_Dir = @ScriptDir & '\WD_Testing_Profile'

    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)

    _WD_Capabilities_CreateObject('firstMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()
    ....
    ....
    ....
EndFunc

I get such JSON:
 

{
    "capabilities":{
        "alwaysMatch":{
            "browserName":"firefox",
            "acceptInsecureCerts":true,
            "moz:firefoxOptions":{
                "args":[
                    "-profile",
                    "Z:\\!!!_SVN_AU3\\UDF_Forum\\Other_Members\\Test\\WD_Testing_Profile"
                ]
            }
        },
        "firstMatch":[
            {
                "browserName":"test",
                "acceptInsecureCerts":true
            }
        ]
    }
}

and such result:

Quote

__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid argument","message":"firstMatch key shadowed a value in alwaysMatch","sta...
__WD_Post ==> Invalid argument: {"value":{"error":"invalid argument","message":"firstMatch key shadowed a value in alwaysMatch","stacktrace":""}}
_WD_CreateSession: {"value":{"error":"invalid argument","message":"firstMatch key shadowed a value in alwaysMatch","stacktrace":""}}
 

Do you have any thoughts in this regard?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

25 minutes ago, mLipok said:

Do you have any thoughts in this regard?

You can't have the following in AlwaysMatch if you are also going to place it in FirstMatch --

"browserName":"firefox",
"acceptInsecureCerts":true

With the FirstMatch section calling for "browserName":"test", it can never combine with the AlwaysMatch settings of "browserName":"firefox". I haven't tested this, but I hope you will get the idea --

Func _Example_Danp2()
    Local $s_My_Profile_Dir = @ScriptDir & '\WD_Testing_Profile'

    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', '')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    
    _WD_Capabilities_CreateObject('firstMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($s_My_Profile_Dir)
 
     _WD_Capabilities_CreateObject('firstMatch', 'chrome')
    _WD_Capabilities_Capability('browserName', 'chrome')
    ....
    ....
    ....    
    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Desired_Capabilities = _WD_Capabilities_GetPretty()

EndFunc

 

Link to comment
Share on other sites

I think now this is quite good version, slim, fast, small, workable.

#include <MsgBoxConstants.au3>
#include "..\wd_helper.au3"
Global Enum _
        $_WD_CAPS__MATCH__Type, _
        $_WD_CAPS__MATCH__FirstIdx, _
        $_WD_CAPS__MATCH__CAPS, _
        $_WD_CAPS__MATCH__Specyfic, _
        $_WD_CAPS__MATCH__OPTS, _
        $_WD_CAPS__MATCH__ARGS, _
        $_WD_CAPS__MATCH__PREFS, _
        $_WD_CAPS__MATCH__LOG, _
        $_WD_CAPS__MATCH__ENV, _
        $_WD_CAPS__MATCH__COUNTER
Global $_WD_CAPS__API[0][$_WD_CAPS__MATCH__COUNTER]
Global $_WD_CAPS__OBJECT
Global $CURRENT_MATCH_IDX = -1

#Region - _wd_Capabilities.au3 UDF - examples
Global Const $_FIREFOX_DRIVER = @ScriptDir & '\..\geckodriver.exe' ; CHANGE TO PROPER FILE FULL PATH
Global Const $_CHROME_DRIVER = @ScriptDir & '\..\chromedriver.exe' ; CHANGE TO PROPER FILE FULL PATH

Global Const $_FIREFOX_PROFILE = @LocalAppDataDir & '\Mozilla\Firefox\Profiles\WD_Testing_Profile' ; CHANGE TO PROPER DIRECTORY PATH
Global Const $_CHROME_PRFILE = @LocalAppDataDir & '\Google\Chrome\User Data\Default' ; CHANGE TO PROPER DIRECTORY PATH

_Example()
Exit

Func _Example()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    _Example_Danp2()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)

    If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Do you want to test with running browsers ?") Then
        Local $b_Headless = ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", "Do you want to test with headless mode ?"))
        _Example_Chrome(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    Else ; only show $s_Capabilities_JSON in console
        _Example_Chrome(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    EndIf
EndFunc   ;==>_Example

Func _Example_Chrome($b_Run_Browser, $b_Headless = False)
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'chrome')
    _WD_Capabilities_Capability('browserName', 'chrome')
;~  _WD_Capabilities_Option('w3c', True)
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    _WD_Capabilities_Argument('start-maximized')
    _WD_Capabilities_Argument('disable-infobars')
    _WD_Capabilities_Argument('user-data-dir', $_CHROME_PRFILE)
    _WD_Capabilities_Preference('download.default_directory', @ScriptDir)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Capabilities_JSON = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', $_CHROME_DRIVER)
    _WD_Option('Port', 9515)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_Chrome

Func _Example_FireFox($b_Run_Browser, $b_Headless = False)
    #forceref $b_Run_Browser, $b_Headless
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    #TODO timeouts
;~  _WD_Capabilities_Capability('timeouts', '{"implicit": 4, "script": 300, "pageLoad": 30000}')
    #TODO proxy
;~  _WD_Capabilities_Capability('proxy', '{"proxyType": 4, "script": 300, "pageLoad": 30000}')
    #TODO 'binary'
;~  _WD_Capabilities_Option('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($_FIREFOX_PROFILE)

    _WD_Capabilities_Preference('dom.ipc.processCount', 8)
    _WD_Capabilities_Preference('javascript.options.showInConsole', False)
    _WD_Capabilities_Preference('browser.toolbars.bookmarks.visibility', 'always') ; check    about:config
    _WD_Capabilities_Preference('app.update.download.attempts', 0) ; check    about:config
    _WD_Capabilities_Preference('browser.safebrowsing.downloads.enabled', False) ; check    about:config

    _WD_Capabilities_Log('level', 'trace')

    _WD_Capabilities_Env('MOZ_LOG', 'nsHttp:5')
    _WD_Capabilities_Env('MOZ_LOG_FILE', @LocalAppDataDir & '\Mozilla\Firefox\Profiles\WD_Testing_Profile\log')

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Capabilities_JSON = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', $_FIREFOX_DRIVER)
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_FireFox

Func _Example_Danp2()
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($_FIREFOX_PROFILE)

    _WD_Capabilities_CreateObject('firstMatch', 'chrome')
    #TODO the next line if uncomented then fires error:   "firstMatch key shadowed a value in alwaysMatch"
;~  _WD_Capabilities_Capability('browserName', 'chrome')
    _WD_Capabilities_Argument('start-maximized')
    _WD_Capabilities_Argument('disable-infobars')
    _WD_Capabilities_Argument('user-data-dir', $_CHROME_PRFILE)
    _WD_Capabilities_Preference('download.default_directory', @ScriptDir)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Capabilities_JSON = _WD_Capabilities_GetPretty()

    _WD_Option('Driver', $_FIREFOX_DRIVER)
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()

    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "END OF _Example_Danp2()")
EndFunc   ;==>_Example_Danp2
#EndRegion - _wd_Capabilities.au3 UDF - examples

#Region - _wd_Capabilities.au3 UDF - core and internal functions

Func _WD_Capabilities_Startup()
    $_WD_CAPS__OBJECT = ''
EndFunc   ;==>_WD_Capabilities_Startup

Func _WD_Capabilities_CreateObject($s_MatchType, $s_Browser_type = '') ; $s_MatchType = 'alwaysMatch' Or 'firstMatch'
    #Region - parameters validation
    If $s_MatchType <> 'alwaysMatch' And $s_MatchType <> 'firstMatch' Then _
            Return SetError(1)

    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'
    Else
        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__MATCH__COUNTER]
    #EndRegion - reindexing API

    #Region - new "MATCH" Initialization
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Type] = $s_MatchType
    If $s_MatchType = 'firstMatch' Then
        Local Static $i_FirstMatch_Counter = -1
        $i_FirstMatch_Counter += 1
        $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__FirstIdx] = $i_FirstMatch_Counter
    EndIf
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__CAPS] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Specyfic] = $s_SpecificOptions_KeyName
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__OPTS] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ARGS] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__PREFS] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__LOG] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ENV] = Null
    $CURRENT_MATCH_IDX = $i_API_New_IDX ; set last API IDX as CURRENT API IDX
    #EndRegion - new "MATCH" Initialization

    Return $CURRENT_MATCH_IDX ; return current API IDX
EndFunc   ;==>_WD_Capabilities_CreateObject

Func _WD_Capabilities_Capability($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__CAPS)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Capability

Func _WD_Capabilities_Option($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__OPTS)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Option

Func _WD_Capabilities_Argument($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ARGS)
    If $value Then $key &= '=' & $value
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $key)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Argument

Func _WD_Capabilities_Preference($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__PREFS)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Preference

Func _WD_Capabilities_Log($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__LOG)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Log

Func _WD_Capabilities_Env($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ENV)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Env

Func __WD_Capabilities_JSON_Notation($i_BUILDER_TYPE)
    Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Type] & ']'
    If $s_CurrentMatch_Type = '[firstMatch]' Then
        $s_CurrentMatch_Type &= '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__FirstIdx] & ']'
    EndIf

    Local $s_SpecificOptions_KeyName = '["' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Specyfic] & '"]'

    Local $s_Notation = ''
    Switch $i_BUILDER_TYPE
        Case $_WD_CAPS__MATCH__CAPS
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type
        Case $_WD_CAPS__MATCH__OPTS
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName
        Case $_WD_CAPS__MATCH__ARGS
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS] += 1
            Local $i_Current_Arg = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS]
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[args][' & $i_Current_Arg & ']'
        Case $_WD_CAPS__MATCH__PREFS
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[prefs]'
        Case $_WD_CAPS__MATCH__LOG
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[log]'
        Case $_WD_CAPS__MATCH__ENV
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[env]'
    EndSwitch
;~  If Not @compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF)
    Return $s_Notation
EndFunc   ;==>__WD_Capabilities_JSON_Notation

#EndRegion - _wd_Capabilities.au3 UDF - core and internal functions

#Region - _wd_Capabilities.au3 UDF - helper functions
Func _WD_Capabilities_GetPretty()
    Local $Data2 = Json_Encode($_WD_CAPS__OBJECT)
    Local $Data1 = Json_Decode($Data2)
    Local $Json2 = Json_Encode($Data1, $Json_UNQUOTED_STRING)
;~  ConsoleWrite("- " & $Json2 & @CRLF)
    Local $Data3 = Json_Decode($Json2)

    Local $Json3 = Json_Encode($Data3, $Json_PRETTY_PRINT, "    ", ",\n", ",\n", ":")
    Return $Json3
EndFunc   ;==>_WD_Capabilities_GetPretty

Func _WD_Capabilities_ToConsole($s_Comment)
    If @Compiled Then Return ; because of GDRP reason do not throw nothing to console when compiled script
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON START: ' & $s_Comment & @LF)
    ConsoleWrite(_WD_Capabilities_GetPretty())
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON END: ' & $s_Comment & @LF & @LF)
EndFunc   ;==>_WD_Capabilities_ToConsole
#EndRegion - _wd_Capabilities.au3 UDF - helper functions

Of course, there are still some things to do that have been marked as #TODO
but....

If no one raises any concerns by the end of the weeks, the early beta phase can be considered complete.
Then I will bring the project to GitHub and can start documenting it through the function headers.
Before I do it, however, I will add an example for MS Edge.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

This is causing a runtime error for me --

_WD_Capabilities_Startup()
   _WD_Capabilities_CreateObject('alwaysMatch')
   _WD_Capabilities_Capability('acceptInsecureCerts', True)

Console output --

@@ Debug(117) : $i_BUILDER_TYPE = 2
@@ Debug(118) : $_WD_CAPS__MATCH__Type = 0
@@ Debug(119) : $CURRENT_MATCH_IDX = -1
"C:\Users\DanPollak\Dropbox\webdriver\wd_capabilities.au3" (121) : ==> Variable subscript badly formatted.:
Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Type] & ']'
Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[^ ERROR
->09:02:31 AutoIt3.exe ended.rc:1

 

Link to comment
Share on other sites

On 9/3/2021 at 1:53 PM, Danp2 said:

How would you build something like this? 

  • {"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}

 

ah... still the same issue:
I forgot about a case when you do not want to specify any Specific/Vendor capabilities
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

new version under spoiler:

Spoiler

 

#include <MsgBoxConstants.au3>
#Region - https://github.com/Danp2/WebDriver
#include "..\wd_helper.au3" ; https : / / github.com / Danp2 / WebDriver
#TODO - ; https://github.com/Danp2/WebDriver
; https://github.com/Danp2/WebDriver

#cs https://github.com/Danp2/WebDriver
https://github.com/Danp2/WebDriver
#CE https://github.com/Danp2/WebDriver

#EndRegion - https://github.com/Danp2/WebDriver

Global Enum _
        $_WD_CAPS__MATCH__Type, _
        $_WD_CAPS__MATCH__FirstIdx, _
        $_WD_CAPS__MATCH__CAPS, _
        $_WD_CAPS__MATCH__Specyfic, _
        $_WD_CAPS__MATCH__OPTS, _
        $_WD_CAPS__MATCH__ARGS, _
        $_WD_CAPS__MATCH__PREFS, _
        $_WD_CAPS__MATCH__LOG, _
        $_WD_CAPS__MATCH__ENV, _
        $_WD_CAPS__MATCH__COUNTER
Global $_WD_CAPS__API[0][$_WD_CAPS__MATCH__COUNTER]
Global $_WD_CAPS__OBJECT
Global $CURRENT_MATCH_IDX = -1

#Region - _wd_Capabilities.au3 UDF - examples
Global Const $_FIREFOX_DRIVER = @ScriptDir & '\..\geckodriver.exe' ; CHANGE TO PROPER FILE FULL PATH
Global Const $_CHROME_DRIVER = @ScriptDir & '\..\chromedriver.exe' ; CHANGE TO PROPER FILE FULL PATH

Global Const $_FIREFOX_PROFILE = @LocalAppDataDir & '\Mozilla\Firefox\Profiles' ; CHANGE TO PROPER DIRECTORY PATH
Global Const $_CHROME_PROFILE = @LocalAppDataDir & '\Google\Chrome\User Data\Default' ; CHANGE TO PROPER DIRECTORY PATH
Global Const $_DOWNLOAD_DIR = @UserProfileDir & '\Downloads\WD_Testing_download' ; CHANGE TO PROPER DIRECTORY PATH

_Example()
Exit

Func _Example()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    _Example_Danp2()
    ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)

    If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Do you want to test with running browsers ?") Then
        Local $b_Headless = ($IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", "Do you want to test with headless mode ?"))
        _Example_Chrome(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(True, $b_Headless)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    Else ; only show $s_Capabilities_JSON in console
        _Example_Chrome(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
        _Example_FireFox(False)
        ConsoleWrite("! " & @ScriptLineNumber & " ===============" & @CRLF)
    EndIf
EndFunc   ;==>_Example

Func _Example_Chrome($b_Run_Browser, $b_Headless = False)
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'chrome')
    _WD_Capabilities_Capability('browserName', 'chrome')
;~  _WD_Capabilities_Option('w3c', True)
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    _WD_Capabilities_Argument('start-maximized')
    _WD_Capabilities_Argument('disable-infobars')
    _WD_Capabilities_Argument('user-data-dir', $_CHROME_PROFILE)
    _WD_Capabilities_Preference('download.default_directory', $_DOWNLOAD_DIR)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Capabilities_JSON = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', $_CHROME_DRIVER)
    _WD_Option('Port', 9515)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_Chrome

Func _Example_FireFox($b_Run_Browser, $b_Headless = False)
    #forceref $b_Run_Browser, $b_Headless
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    #TODO timeouts
;~  _WD_Capabilities_Capability('timeouts', '{"implicit": 4, "script": 300, "pageLoad": 30000}')
    #TODO proxy
;~  _WD_Capabilities_Capability('proxy', '{"proxyType": 4, "script": 300, "pageLoad": 30000}')
    #TODO 'binary'
;~  _WD_Capabilities_Option('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    If $b_Headless Then _
            _WD_Capabilities_Argument('--headless')
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($_FIREFOX_PROFILE)

    _WD_Capabilities_Preference('dom.ipc.processCount', 8)
    _WD_Capabilities_Preference('javascript.options.showInConsole', False)
    _WD_Capabilities_Preference('browser.toolbars.bookmarks.visibility', 'always') ; check    about:config
    _WD_Capabilities_Preference('app.update.download.attempts', 0) ; check    about:config
    _WD_Capabilities_Preference('browser.safebrowsing.downloads.enabled', False) ; check    about:config
    _WD_Capabilities_Preference('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_Capabilities_Preference('browser.download.folderList', 2)
    _WD_Capabilities_Preference('browser.download.manager.showWhenStarting', False)
    _WD_Capabilities_Preference('browser.download.dir', $_DOWNLOAD_DIR)
    _WD_Capabilities_Preference('browser.helperApps.neverAsk.saveToDisk', 'application/x-gzip')
    _WD_Capabilities_Preference('browser.helperApps.neverAsk.saveToDisk', 'application/zip')

    _WD_Capabilities_Log('level', 'trace')

    _WD_Capabilities_Env('MOZ_LOG', 'nsHttp:5')
    _WD_Capabilities_Env('MOZ_LOG_FILE', $_FIREFOX_PROFILE & '\log')

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Capabilities_JSON = _WD_Capabilities_GetPretty()
    If Not $b_Run_Browser Then Return

    _WD_Option('Driver', $_FIREFOX_DRIVER)
    _WD_Option('Port', 4444)
    _WD_Startup()
    Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Example_FireFox

Func _Example_Danp2()
    _WD_Capabilities_Startup()
    _WD_Capabilities_CreateObject('alwaysMatch')
    _WD_Capabilities_Capability('acceptInsecureCerts', True)
    _WD_Capabilities_ToConsole(@ScriptLineNumber)

    _WD_Capabilities_CreateObject('firstMatch', 'chrome')
    #TODO the next line if uncomented then fires error:   "firstMatch key shadowed a value in alwaysMatch"
    _WD_Capabilities_Capability('browserName', 'chrome')
    _WD_Capabilities_Argument('start-maximized')
    _WD_Capabilities_Argument('disable-infobars')
    _WD_Capabilities_Argument('user-data-dir', $_CHROME_PROFILE)
    _WD_Capabilities_Argument('--profile-directory', Default)
    _WD_Capabilities_Preference('download.default_directory', @ScriptDir)
    _WD_Capabilities_ToConsole(@ScriptLineNumber)

    _WD_Capabilities_CreateObject('firstMatch', 'firefox')
    _WD_Capabilities_Capability('browserName', 'firefox')
    _WD_Capabilities_Argument('-profile')
    _WD_Capabilities_Argument($_FIREFOX_PROFILE)

    _WD_Capabilities_ToConsole(@ScriptLineNumber)
    Local $s_Capabilities_JSON = _WD_Capabilities_GetPretty()

    Local $_CHOOSEN_DRIVER = ''
    If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Which browser do you wan to use ?" & @CRLF & @CRLF & _
            "[YES] = FireFox    [NO] = Chrome") Then
        $_CHOOSEN_DRIVER = $_FIREFOX_DRIVER
    Else
        $_CHOOSEN_DRIVER = $_CHROME_DRIVER
    EndIf
    ConsoleWrite("> USING: " & $_CHOOSEN_DRIVER & @CRLF)
    If Not FileExists($_CHOOSEN_DRIVER) Then
        MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONERROR, "! Error occurred", _
                "WebDriver file not exist" & @CRLF & _
                "")
        Exit
    EndIf
    _WD_Option('Driver', $_CHOOSEN_DRIVER)
    If $_CHOOSEN_DRIVER = $_FIREFOX_DRIVER Then _WD_Option('Port', 4444)
    If $_CHOOSEN_DRIVER = $_CHROME_DRIVER Then _WD_Option('Port', 9515)
    _WD_Startup()

    Local $WD_SESSION = _WD_CreateSession($s_Capabilities_JSON)
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "Waiting before _WD_Shutdown()")
    _WD_DeleteSession($WD_SESSION)
    _WD_Shutdown()

    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "END OF _Example_Danp2()")
EndFunc   ;==>_Example_Danp2
#EndRegion - _wd_Capabilities.au3 UDF - examples

#Region - _wd_Capabilities.au3 UDF - core and internal functions

Func _WD_Capabilities_Startup()
    $_WD_CAPS__OBJECT = ''
EndFunc   ;==>_WD_Capabilities_Startup

Func _WD_Capabilities_CreateObject($s_MatchType, $s_Browser_type = '') ; $s_MatchType = 'alwaysMatch' Or 'firstMatch'
    #Region - parameters validation
    If $s_MatchType <> 'alwaysMatch' And $s_MatchType <> 'firstMatch' Then _
            Return SetError(1)

    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_Browser_type = '' Then
        $s_SpecificOptions_KeyName = ''
    Else
        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__MATCH__COUNTER]
    #EndRegion - reindexing API

    #Region - new "MATCH" Initialization
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Type] = $s_MatchType
    If $s_MatchType = 'firstMatch' Then
        Local Static $i_FirstMatch_Counter = -1
        $i_FirstMatch_Counter += 1
        $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__FirstIdx] = $i_FirstMatch_Counter
    EndIf
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__CAPS] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__Specyfic] = $s_SpecificOptions_KeyName
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__OPTS] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ARGS] = -1
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__PREFS] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__LOG] = Null
    $_WD_CAPS__API[$i_API_New_IDX][$_WD_CAPS__MATCH__ENV] = Null
    $CURRENT_MATCH_IDX = $i_API_New_IDX ; set last API IDX as CURRENT API IDX
    #EndRegion - new "MATCH" Initialization

    Return $CURRENT_MATCH_IDX ; return current API IDX
EndFunc   ;==>_WD_Capabilities_CreateObject

Func _WD_Capabilities_Capability($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__CAPS)
    If @error Then Return SetError(@error, @extended, $s_Notation)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Capability

Func _WD_Capabilities_Option($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__OPTS)
    If @error Then Return SetError(@error, @extended, $s_Notation)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Option

Func _WD_Capabilities_Argument($key, $value = '')
    If $value = Default Then $value = 'Default'
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ARGS)
    If @error Then Return SetError(@error, @extended, $s_Notation)
    If $value Then $key &= '=' & $value
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $key)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Argument

Func _WD_Capabilities_Preference($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__PREFS)
    If @error Then Return SetError(@error, @extended, $s_Notation)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Preference

Func _WD_Capabilities_Log($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__LOG)
    If @error Then Return SetError(@error, @extended, $s_Notation)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Log

Func _WD_Capabilities_Env($key, $value = '')
    Local $s_Notation = __WD_Capabilities_JSON_Notation($_WD_CAPS__MATCH__ENV)
    If @error Then Return SetError(@error, @extended, $s_Notation)
    $s_Notation &= '[' & $key & ']'
    Json_Put($_WD_CAPS__OBJECT, $s_Notation, $value)
;~  If Not @compiled Then ConsoleWrite("> $s_Notation - " & $s_Notation & @CRLF)
EndFunc   ;==>_WD_Capabilities_Env

Func __WD_Capabilities_JSON_Notation($i_BUILDER_TYPE)
    Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Type] & ']'
    If $s_CurrentMatch_Type = '[firstMatch]' Then
        $s_CurrentMatch_Type &= '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__FirstIdx] & ']'
    EndIf

    Local $s_SpecificOptions_KeyName = '["' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__Specyfic] & '"]'
    If $s_SpecificOptions_KeyName = '' And $i_BUILDER_TYPE >= $_WD_CAPS__MATCH__ARGS Then _
            Return SetError(1, 0, '') ; ARGS, PREFS, LOG, ENV are possible only when Specific/Vendor Capability was specified

    Local $s_Notation = ''
    Switch $i_BUILDER_TYPE
        Case $_WD_CAPS__MATCH__CAPS
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type
        Case $_WD_CAPS__MATCH__OPTS
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName
        Case $_WD_CAPS__MATCH__ARGS
            $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS] += 1
            Local $i_Current_Arg = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS__MATCH__ARGS]
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[args][' & $i_Current_Arg & ']'
        Case $_WD_CAPS__MATCH__PREFS
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[prefs]'
        Case $_WD_CAPS__MATCH__LOG
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[log]'
        Case $_WD_CAPS__MATCH__ENV
            $s_Notation = '[capabilities]' & $s_CurrentMatch_Type & $s_SpecificOptions_KeyName & '[env]'
    EndSwitch
;~  If Not @compiled Then ConsoleWrite("- IFNC: " & @ScriptLineNumber & ' $s_Notation =' & $s_Notation & @CRLF)
    Return $s_Notation
EndFunc   ;==>__WD_Capabilities_JSON_Notation

#EndRegion - _wd_Capabilities.au3 UDF - core and internal functions

#Region - _wd_Capabilities.au3 UDF - helper functions
Func _WD_Capabilities_GetPretty()
    Local $Data2 = Json_Encode($_WD_CAPS__OBJECT)
    Local $Data1 = Json_Decode($Data2)
    Local $Json2 = Json_Encode($Data1, $Json_UNQUOTED_STRING)
;~  ConsoleWrite("- " & $Json2 & @CRLF)
    Local $Data3 = Json_Decode($Json2)

    Local $Json3 = Json_Encode($Data3, $Json_PRETTY_PRINT, "    ", ",\n", ",\n", ":")
    Return $Json3
EndFunc   ;==>_WD_Capabilities_GetPretty

Func _WD_Capabilities_ToConsole($s_Comment)
    If @Compiled Then Return ; because of GDRP reason do not throw nothing to console when compiled script
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON START: ' & $s_Comment & @LF)
    ConsoleWrite(_WD_Capabilities_GetPretty())
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON END: ' & $s_Comment & @LF & @LF)
EndFunc   ;==>_WD_Capabilities_ToConsole
#EndRegion - _wd_Capabilities.au3 UDF - helper functions

 

 

Currently function:   _Example_Danp2()
Creates such Capabilities JSON string

{
    "capabilities":{
        "alwaysMatch":{
            "acceptInsecureCerts":true
        },
        "firstMatch":[
            {
                "browserName":"chrome",
                "goog:chromeOptions":{
                    "args":[
                        "start-maximized",
                        "disable-infobars",
                        "user-data-dir=C:\\Users\\Szef\\AppData\\Local\\Google\\Chrome\\User Data\\Default",
                        "--profile-directory=Default"
                    ],
                    "prefs":{
                        "download.default_directory":"Z:\\!!!_SVN_AU3\\UDF_Forum\\Other_Members\\Test"
                    }
                }
            },
            {
                "browserName":"firefox",
                "moz:firefoxOptions":{
                    "args":[
                        "-profile",
                        "C:\\Users\\Szef\\AppData\\Local\\Mozilla\\Firefox\\Profiles"
                    ]
                }
            }
        ]
    }
}

using this particular JSON string I was able to add new feature:
 

....
    ....
    ....
    Local $_CHOOSEN_DRIVER = ''
    If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Wchich browser do you wan to use ?" & @CRLF & @CRLF & _
            "[YES] = FireFox    [NO] = Chrome") Then
        $_CHOOSEN_DRIVER = $_FIREFOX_DRIVER
    Else
        $_CHOOSEN_DRIVER = $_CHROME_DRIVER
    EndIf
    ....
    ....
    ....
    _WD_Option('Driver', $_CHOOSEN_DRIVER)
    If $_CHOOSEN_DRIVER = $_FIREFOX_DRIVER Then _WD_Option('Port', 4444)
    If $_CHOOSEN_DRIVER = $_CHROME_DRIVER Then _WD_Option('Port', 9515)
    _WD_Startup()
    ....
    ....

This shows how to use different Browsers with the same Capabilities JSON string.

:)

 

Edited by mLipok
typo + wording

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I am thinking of changing the function name _WD_Capabilities_CreateObject() to _WD_Capabilities_CreateGroup()  as or just _WD_Capabilities_Group() eventually _WD_Capabilities_Type()

Because IMHO Capabilites must be grouped in one of two group of capabilites settings "alwaysMatch" or "firstMatch".
"alwaysMatch" may contain only one JSON Capabilities object
"alwaysMatch" contains JSON ARRAY which can contain many JSON Capabilities object

This is the way how currently I understand the Capabilities.
Please correct me if I'm wrong.

 

Edited by mLipok
wording

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Reading here:

https://www.w3.org/TR/webdriver/#dfn-table-of-standard-capabilities

About "timeouts" and "proxy" capability settings I propose to do something like this:
 

; https://www.w3.org/TR/webdriver/#dfn-proxy-configuration
    _WD_Capabilities_CapabilityProxy('proxyType', ...)
    _WD_Capabilities_CapabilityProxy('proxyAutoconfigUrl', ...)
    _WD_Capabilities_CapabilityProxy('ftpProxy', ...)
    _WD_Capabilities_CapabilityProxy('noProxy', "...|...|...|...")
    _WD_Capabilities_CapabilityProxy('sslProxy', ...)
    _WD_Capabilities_CapabilityProxy('socksProxy', ...)
    _WD_Capabilities_CapabilityProxy('socksVersion', ...)

and 

; https://www.w3.org/TR/webdriver/#timeouts
    _WD_Capabilities_Capability('timeouts', 'implicit|4|script|300|pageLoad|30000')

What you think about ?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

As to using excludeswitches or any prefs with list of strings I prospose

    _WD_Capabilities_Capability('excludeSwitches', 'disable-popup-blocking')
    _WD_Capabilities_Capability('excludeSwitches', 'enable-automation')
    _WD_Capabilities_Capability('excludeSwitches', 'load-extension')


References:
https://chromedriver.chromium.org/capabilities
https://stackoverflow.com/a/58694548/5314940
 

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

new version in the following spoiler:
 

Spoiler


#include <MsgBoxConstants.au3>
#include "..\wd_helper.au3"
; for wd_helper.au3 take a look: 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 - UDF Header - early version
#cs
    Core functions:
    _WD_Capabilities_Startup()
    _WD_Capabilities_Add()
    _WD_Capabilities_GetJson()

    Yep, there is no more need to use _WD_Capabilities_Argument()  _WD_Capabilities_Preference() etc.....

    Internal functions:
    __WD_Capabilities_CreateObject()
    __WD_Capabilities_Switch_Parameters()
    __WD_Capabilities_JSON_Notation()

    Helper Functions:
    _WD_Capabilities_GetPrettyJson()
    _WD_Capabilities_JsonToConsole()
    _WD_Capabilities_ApiToConsole()
    _WD_Capabilities_ApiDisplay()
#CE
#TODO _WD_CreateSession: {"value":{"error":"session not created","message":"Unable to find a matching set of capabilities","stacktrace":""}}

#EndRegion - _wd_Capabilities.au3 UDF - 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_STANDARD__COUNTER
Global $_WD_CAPS__API[0][$_WD_CAPS_STANDARD__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 $CURRENT_MATCH_IDX = -1
#EndRegion - _wd_Capabilities.au3 UDF - Global's declarations

#Region - _wd_Capabilities.au3 UDF - examples
Global Const $_FIREFOX_DRIVER = @ScriptDir & '\..\geckodriver.exe' ; CHANGE TO PROPER FILE FULL PATH
Global Const $_CHROME_DRIVER = @ScriptDir & '\..\chromedriver.exe' ; CHANGE TO PROPER FILE FULL PATH
Global Const $_EDGE_DRIVER = @ScriptDir & '\..\msedgedriver.exe' ; CHANGE TO PROPER FILE FULL PATH

Global Const $_FIREFOX_PROFILE = @LocalAppDataDir & '\Mozilla\Firefox\Profiles\WD_Testing_Profile' ; CHANGE TO PROPER DIRECTORY PATH
Global Const $_CHROME_PROFILE = @LocalAppDataDir & '\Google\Chrome\User Data\Default' ; CHANGE TO PROPER DIRECTORY PATH
Global Const $_EDGE_PROFILE = @LocalAppDataDir & 'TODO_______TODO' ; CHANGE TO PROPER DIRECTORY PATH

Global Const $_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_Capabilities_Startup()
    ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF)
    #Region -   _WD_Capabilities_Example() ... "alwaysMatch" section
    _WD_Capabilities_Add('alwaysMatch')
    _WD_Capabilities_Add('acceptInsecureCerts', True)
    _WD_Capabilities_Add('timeouts', 'implicit', 4)
    _WD_Capabilities_Add('timeouts', 'script', 300)
    _WD_Capabilities_Add('timeouts', 'pageLoad', 30000)
    If $_EXAMPLE_OPTION_PROXY Then
        _WD_Capabilities_Add('proxy', 'proxyType', 'manual')
        _WD_Capabilities_Add('proxy', 'proxyAutoconfigUrl', '127.0.0.1') ; change '127.0.0.1' to your own 'proxyAutoconfigUrl' host
        _WD_Capabilities_Add('proxy', 'ftpProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'ftpProxy' host
        _WD_Capabilities_Add('proxy', 'httpProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'httpProxy' host
        _WD_Capabilities_Add('proxy', 'noProxy', 'www.w3.org') ; an example url which should not to bo opened via proxy server
        _WD_Capabilities_Add('proxy', 'noProxy', 'www.autoitscript.com') ; an example url which should not to bo opened via proxy server
        _WD_Capabilities_Add('proxy', 'noProxy', 'www.google.com') ; an example url which should not to bo opened via proxy server
        _WD_Capabilities_Add('proxy', 'noProxy', 'www.google.pl') ; an example url which should not to bo opened via proxy server
        _WD_Capabilities_Add('proxy', 'sslProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'sslProxy' host
        _WD_Capabilities_Add('proxy', 'socksProxy', '127.0.0.1') ; change '127.0.0.1' to your own 'socksProxy' host
        _WD_Capabilities_Add('proxy', 'socksVersion', 1)
    EndIf
    #TODO check why 'WIN10' have issue when using FireFox
;~  _WD_Capabilities_Add('platformName', 'WIN10') ; https://stackoverflow.com/a/45621125/5314940
    _WD_Capabilities_JsonToConsole(@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 = $_EDGE_DRIVER Then
        ; https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options
        ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF)
        _WD_Capabilities_Add('firstMatch', 'edge')
        _WD_Capabilities_JsonToConsole(@ScriptLineNumber)
        #TODO CHECK .... "invalid argument: entry 0 of 'firstMatch' is invalid\nfrom invalid argument: unrecognized capability: browsername"
;~      _WD_Capabilities_Add('browsername', 'edge')
        #TODO CHECK .... How to use 'WIN10'
;~      _WD_Capabilities_Add('platformName', 'WIN10')
        _WD_Capabilities_Add('w3c', True)
        #TODO CHECK .... How to use 'maxInstances'
;~      _WD_Capabilities_Add('maxInstances', 1) ; https://stackoverflow.com/a/45621125/5314940
        If $_EXAMPLE_OPTION_HEADLESS Then _
                _WD_Capabilities_Add('args', '--headless')
        _WD_Capabilities_Add('prefs', 'plugins.always_open_pdf_externally', True) ; https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/?do=findComment&comment=1482786
        _WD_Capabilities_Add('prefs', 'edge.sleeping_tabs.enabled', False) ; https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/?do=findComment&comment=1482798
        _WD_Capabilities_JsonToConsole(@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 = $_CHROME_DRIVER Then
        ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF)
        _WD_Capabilities_Add('firstMatch', 'chrome')
        #TODO ADD REMARK about:   "firstMatch key shadowed a value in alwaysMatch"
        _WD_Capabilities_Add('browserName', 'chrome')
;~      _WD_Capabilities_Add('platformName', 'WIN10')
        _WD_Capabilities_Add('w3c', True)
        #TODO check how to use 'binary'
        # _WD_Capabilities_Add('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe')
        If $_EXAMPLE_OPTION_HEADLESS Then _
                _WD_Capabilities_Add('args', '--headless')
        _WD_Capabilities_Add('args', 'start-maximized')
        _WD_Capabilities_Add('args', 'disable-infobars')
        _WD_Capabilities_Add('args', 'user-data-dir', $_CHROME_PROFILE)
        _WD_Capabilities_Add('args', '--profile-directory', Default)
        _WD_Capabilities_Add('excludeSwitches', 'disable-popup-blocking') ; https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification
        _WD_Capabilities_Add('excludeSwitches', 'enable-automation')
        _WD_Capabilities_Add('excludeSwitches', 'load-extension')
        _WD_Capabilities_JsonToConsole(@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 = $_FIREFOX_DRIVER Then
        ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF)
        _WD_Capabilities_Add('firstMatch', 'firefox')
        _WD_Capabilities_Add('browserName', 'firefox')

        If $_EXAMPLE_OPTION_HEADLESS Then _
                _WD_Capabilities_Add('args', '--headless')
        _WD_Capabilities_Add('args', '-profile')
        _WD_Capabilities_Add('args', $_FIREFOX_PROFILE)
        _WD_Capabilities_Add('prefs', 'download.default_directory', @ScriptDir)
        _WD_Capabilities_Add('prefs', 'dom.ipc.processCount', 8)
        _WD_Capabilities_Add('prefs', 'javascript.options.showInConsole', False)
        _WD_Capabilities_Add('prefs', 'browser.toolbars.bookmarks.visibility', 'always') ; check    about:config
        _WD_Capabilities_Add('prefs', 'app.update.download.attempts', 0) ; check    about:config
        _WD_Capabilities_Add('prefs', 'browser.safebrowsing.downloads.enabled', False) ; check    about:config
        _WD_Capabilities_Add('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_Capabilities_Add('prefs', 'browser.download.folderList', 2)
        _WD_Capabilities_Add('prefs', 'browser.download.manager.showWhenStarting', False)
        _WD_Capabilities_Add('prefs', 'browser.download.dir', $_DOWNLOAD_DIR)
        _WD_Capabilities_Add('prefs', 'browser.helperApps.neverAsk.saveToDisk', 'application/x-gzip')
        _WD_Capabilities_Add('prefs', 'browser.helperApps.neverAsk.saveToDisk', 'application/zip')

        _WD_Capabilities_Add('log', 'level', 'trace')

        _WD_Capabilities_Add('env', 'MOZ_LOG', 'nsHttp:5')
        _WD_Capabilities_Add('env', 'MOZ_LOG_FILE', $_FIREFOX_PROFILE & '\log')
        _WD_Capabilities_JsonToConsole(@ScriptLineNumber)
    EndIf
    #EndRegion -    _WD_Capabilities_Example() ... "firstMatch" section for FireFox

    _WD_Capabilities_ApiToConsole(@ScriptLineNumber)
    _WD_Capabilities_ApiDisplay(@ScriptLineNumber)

    If Not $_EXAMPLE_OPTION_RUN_BROWSER Then Return

    _WD_Option('Driver', $_EXAMPLE_OPTION_CHOOSEN_DRIVER)
    If $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_FIREFOX_DRIVER Then _WD_Option('Port', 4444)
    If $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_CHROME_DRIVER Then _WD_Option('Port', 9515)
    If $_EXAMPLE_OPTION_CHOOSEN_DRIVER = $_EDGE_DRIVER Then _WD_Option('Port', 9515)
    _WD_Startup()

    Local $s_Capabilities_JSON = _WD_Capabilities_GetPrettyJson()
    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 = $_FIREFOX_DRIVER
    ElseIf $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Do you want to use Google Chrome browser") Then
        $_CHOOSEN_DRIVER = $_CHROME_DRIVER
    ElseIf $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
            "Do you want to use Miscrosoft Edge browser") Then
        $_CHOOSEN_DRIVER = $_EDGE_DRIVER
    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

Func _WD_Capabilities_Startup()
    $_WD_CAPS__OBJECT = ''
EndFunc   ;==>_WD_Capabilities_Startup

Func _WD_Capabilities_Add($key, $value1 = '', $value2 = '')
    If $value1 = Default Then $value1 = 'default'
    If $value2 = Default Then $value2 = 'default'
    If StringInStr('alwaysMatch|firstMatch', $key) Then
        $CURRENT_MATCH_IDX = __WD_Capabilities_CreateObject($key, $value1)
        Return SetError(@error, @extended, $CURRENT_MATCH_IDX)
    EndIf
    #TODO use $value2 for "noProxy"  https://www.w3.org/TR/webdriver/#dfn-page-load-strategy
    #TODO use $value2 for https://www.w3.org/TR/webdriver/#timeouts
    Local $s_Notation = ''
    If $key = 'excludeSwitches' Then ; for adding "excludeSwitches" capability in specific/vendor capabilities : ........
        $s_Notation = __WD_Capabilities_JSON_Notation($_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_Capabilities_JSON_Notation($_WD_CAPS_STANDARD__TIMEOUTS)
        $s_Notation &= '[' & $value1 & ']' ; here is specified keyName in {timeouts} JSON OBJECT
        __WD_Capabilities_Switch_Parameters($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_Capabilities_JSON_Notation($_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[$CURRENT_MATCH_IDX][$_WD_CAPS_STANDARD__PROXY] += 1 ; default is -1 so first should be 0
            Local $i_Current_noProxy = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_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_Capabilities_Switch_Parameters($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_Capabilities_JSON_Notation($_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_Capabilities_JSON_Notation($_WD_CAPS_SPECIFICVENDOR__ARGS)
        __WD_Capabilities_Switch_Parameters($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_Capabilities_JSON_Notation($_WD_CAPS_SPECIFICVENDOR__PREFS)
        __WD_Capabilities_Switch_Parameters($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_Capabilities_JSON_Notation($_WD_CAPS_SPECIFICVENDOR__LOG)
        __WD_Capabilities_Switch_Parameters($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_Capabilities_JSON_Notation($_WD_CAPS_SPECIFICVENDOR__ENV)
        __WD_Capabilities_Switch_Parameters($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_Capabilities_JSON_Notation($_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_Capabilities_Add

Func _WD_Capabilities_GetJson()
    Local $Data2 = Json_Encode($_WD_CAPS__OBJECT)
    Local $Data1 = Json_Decode($Data2)
    Local $Json2 = Json_Encode($Data1, $Json_UNQUOTED_STRING)
    Return $Json2
EndFunc   ;==>_WD_Capabilities_GetJson
#EndRegion - _wd_Capabilities.au3 UDF - core functions

#Region - _wd_Capabilities.au3 UDF - internal functions
Func __WD_Capabilities_CreateObject($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_STANDARD__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]
    $CURRENT_MATCH_IDX = $i_API_New_IDX ; set last API IDX as CURRENT API IDX
    #EndRegion - new "MATCH" Initialization
    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 & _
            "$CURRENT_MATCH_IDX = " & $CURRENT_MATCH_IDX & @CRLF & _
            ''
    #forceref $s_Information
;~  If Not @compiled Then MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, $s_Information)

;~  ConsoleWrite("! @ScriptLineNumber = " & @ScriptLineNumber & @CRLF)
    Return $CURRENT_MATCH_IDX ; return current API IDX
EndFunc   ;==>__WD_Capabilities_CreateObject

Func __WD_Capabilities_Switch_Parameters(ByRef $key, ByRef $value1, ByRef $value2)
    $key = $value1
    $value1 = $value2
    $value2 = ''
EndFunc   ;==>__WD_Capabilities_Switch_Parameters

Func __WD_Capabilities_JSON_Notation($i_BUILDER_TYPE)
;~  MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, "Information #" & @ScriptLineNumber, "$CURRENT_MATCH_IDX = " & $CURRENT_MATCH_IDX &  ' Ubound = ' & UBound($_WD_CAPS__API))
    Local $s_CurrentMatch_Type = '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS_STANDARD__Type] & ']'
    If $s_CurrentMatch_Type = '[firstMatch]' Then
        $s_CurrentMatch_Type &= '[' & $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_WD_CAPS_STANDARD__FirstIdx] & ']'
    EndIf

    Local $s_SpecificOptions_KeyName = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_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[$CURRENT_MATCH_IDX][$_WD_CAPS_SPECIFICVENDOR__ARGS] += 1 ; default is -1 so first should be 0
            Local $i_Current_Arg = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_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[$CURRENT_MATCH_IDX][$_WD_CAPS_SPECIFICVENDOR__EXCSWITCH] += 1 ; default is -1 so first should be 0
            Local $i_Current_ExcSwitch = $_WD_CAPS__API[$CURRENT_MATCH_IDX][$_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_Capabilities_JSON_Notation
#EndRegion - _wd_Capabilities.au3 UDF - internal functions

#Region - _wd_Capabilities.au3 UDF - helper functions
Func _WD_Capabilities_GetPrettyJson()
    Local $Json2 = _WD_Capabilities_GetJson()
    Local $Data3 = Json_Decode($Json2)
    Local $Json3 = Json_Encode($Data3, $Json_PRETTY_PRINT, "    ", ",\n", ",\n", ":")
    Return $Json3
EndFunc   ;==>_WD_Capabilities_GetPrettyJson

Func _WD_Capabilities_JsonToConsole($s_Comment)
    If @Compiled Then Return ; because of GDRP reason do not throw nothing to console when compiled script
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON START: ' & $s_Comment & @LF)
    ConsoleWrite(_WD_Capabilities_GetPrettyJson())
    ConsoleWrite(@LF & '! _WD_Capabilities: JSON END: ' & $s_Comment & @LF & @LF)
EndFunc   ;==>_WD_Capabilities_JsonToConsole

Func _WD_Capabilities_ApiToConsole($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("- Ubound Rows " & UBound($_WD_CAPS__API, 1) & @CRLF)
    ConsoleWrite("- Ubound Cols " & UBound($_WD_CAPS__API, 2) & @CRLF)
    ConsoleWrite(_ArrayToString($_WD_CAPS__API) & @LF)
    ConsoleWrite(@LF & '! _WD_Capabilities: API END: ' & $s_Comment & @LF & @LF)
EndFunc   ;==>_WD_Capabilities_ApiToConsole

Func _WD_Capabilities_ApiDisplay($s_Comment)
    If @Compiled Then Return ; because of GDRP reason do not throw nothing to console when compiled script
    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_Capabilities_ApiDisplay
#EndRegion - _wd_Capabilities.au3 UDF - helper functions


 

Here is function list

Core functions:
    _WD_Capabilities_Startup()
    _WD_Capabilities_Add()
    _WD_Capabilities_GetJson()

    Yep, there is no more need to use _WD_Capabilities_Argument()  _WD_Capabilities_Preference() etc.....

    Internal functions:
    __WD_Capabilities_CreateObject()
    __WD_Capabilities_Switch_Parameters()
    __WD_Capabilities_JSON_Notation()

    Helper Functions:
    _WD_Capabilities_GetPrettyJson()
    _WD_Capabilities_JsonToConsole()
    _WD_Capabilities_ApiToConsole()
    _WD_Capabilities_ApiDisplay()

 

What I add?


Support for:

  • MS Edge
  • 'timeouts'
  • 'proxy'
  • 'excludeSwitches'

There is also one better configurable example.

Take a look and have fun.
I am waiting for your feedback.

btw.
We are getting closer to the first version without beta stage.
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

On the way to the official release:
https://github.com/mlipok/_wd_capabilities.au3

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

On 9/8/2021 at 9:53 AM, mLipok said:

Here is function list

Here are a few small suggestions --

  • Standardize capitalization of acronyms. Is it "JSON" or "Json"? My recommendation is all caps, including "API" instead of "Api"
  • Develop a consistent naming convention. You have a tendency to throw in extra underscores in some instances. For example, __WD_Capabilities_Switch_Parameters should be __WD_Capabilities_SwitchParameters so that it matches the format of __WD_Capabilities_CreateObject.
  • Removing the underscore after _WD_Capabilities would better match the naming convention used in the main WD UDF 😉
Link to comment
Share on other sites

On 9/14/2021 at 2:13 PM, Danp2 said:
  • Standardize capitalization of acronyms. Is it "JSON" or "Json"? My recommendation is all caps, including "API" instead of "Api"
  • Develop a consistent naming convention. You have a tendency to throw in extra underscores in some instances. For example, __WD_Capabilities_Switch_Parameters should be __WD_Capabilities_SwitchParameters so that it matches the format of __WD_Capabilities_CreateObject.

Done.

On 9/14/2021 at 2:13 PM, Danp2 said:

Removing the underscore after _WD_Capabilities would better match the naming convention used in the main WD UDF

My approach is like Objective programing:
      wd.capabilities.startup  >>> _WD_Capabilities_Startup

In my current version I'm working on , there are:

Func _WD_Capabilities_Startup()
Func _WD_Capabilities_Add($key, $value1 = '', $value2 = '')
Func _WD_Capabilities_GetJSON()
Func _WD_Capabilities_GetPrettyJSON()
Func _WD_Capabilities_JSONToConsole($s_Comment)
Func _WD_Capabilities_APIToConsole($s_Comment)
Func _WD_Capabilities_APIDisplay($s_Comment)

Func __WD_Capabilities_CreateObject($s_MatchType, $s_Browser_type = '') ; $s_MatchType = 'alwaysMatch' Or 'firstMatch'
Func __WD_Capabilities_SwitchParameters(ByRef $key, ByRef $value1, ByRef $value2)
Func __WD_Capabilities_JSONNotation($i_BUILDER_TYPE)


This is intentionally naming convention to separate this functions as a specific subgroup of function in relation to _WD_ ***** functions, because they are only used to initialize parameters called "Capabilities" in WebDrive terminology. Also for this reason, they are in seeparate UDF.

Considering my explanations, does this somehow hinder the consistency of the entire WebDrive UDF package?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

I want to understand you well, so I will ask the question:
What you mean saying:

Quote

However, my opinion on the final underscore hasn't changed.

especially "final underscore" .

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...