Jump to content

RESTwhich UDF to use webdriver of EDGE


junkew
 Share

Recommended Posts

 

With selenium 3 and webdriver around by major browsers I was playing around with some REST services

Now I am wondering whats best to start with to do it from AutoIT.

WinHTTP.au3 or maybe other suggestions?

Examples

1. Installed Microsoft EDGE webdriver

2. run it  Listening on http://localhost:17556/

3. Validating it by GET: 
http://localhost:17556/status

RAW: 

GET /status HTTP/1.1
Host: localhost:17556
Cache-Control: no-cache
JSON Response: {"sessionId":"","status":0,"value":{"build":{"version":"10.0.14393.0"},"os":{"arch":"x86","name":"Windows 10","version":"10.0"}}}

4. Start a new Edge Session with POST http://localhost:17556/session

POST /session HTTP/1.1
Host: localhost:17556
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 218239ae-821e-3a48-29bd-1898606b1529

{
    "desiredCapabilities": {

    },
    "requiredCapabilities": {}
}

JSON response

{"sessionId":"CD8C9B0D-FEAF-4A93-BF0D-E43C00BDDA8C","status":0,"value":{"browserName":"MicrosoftEdge","browserVersion":"38.14393.0.0","platformName":"windows","platformVersion":"10","takesElementScreenshot":true,"takesScreenshot":true,"acceptSslCerts":true,"applicationCacheEnabled":true,"locationContextEnabled":true,"webStorageEnabled":true,"pageLoadStrategy":"normal"}}

5. Call a lot of other nice stuff thru webdriver (available for even mobile phone browsers)

https://w3c.github.io/webdriver/webdriver-spec.html

 

Edited by junkew
Link to comment
Share on other sites

communication with REST API is usually very simple to establish. i've been using HTTP object directly, my first ref. was this:

however, what you probably do want a UDF for, is the composing of the request and parsing the response. if it's XML or JSON, you may want to check relevant UDF for those.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

thx this works like a charm

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
$URL="http://localhost:17556/"

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

;~ GET /status HTTP/1.1
;~ Host: localhost:17556
;~ Cache-Control: no-cache

$restCMD="/status"

$oHTTP.Open("GET", $URL & $restCMD, true)
;~ $oHTTP.setRequestHeader ("Cache-Control:","no-cache")
;~ $oHTTP.SetRequestHeader("Content-Type", "xml")
$oHTTP.Send("")
sleep(2000) ;~just wait a little

$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

;~ $objHTTP.open ("POST", "url", False)
;~ $objHTTP.setRequestHeader ("Content-Type", "text/xml;charset=UTF-8")
;~ $objHTTP.setRequestHeader("Content-Length",StringLen($YourXMLText))
;~ $objHTTP.setRequestHeader("Connection","If is needed")
;~ $objHTTP.setRequestHeader("User-Agent","If is needed")
;~ $objHTTP.send ($YourXMLText)


ConsoleWrite($oStatusCode & @CRLF)
ConsoleWrite($oReceived & @CRLF)

If $oStatusCode = 200 Then
    ;Process the response $oReceived
    ;ConsoleWrite(@CRLF & "Response" & @CRLF & $oReceived & @CRLF)
Else
    MsgBox(16, "Error " & $oStatusCode, $oReceived, 7)
EndIf


; This is my custom defined error handler
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
Endfunc

 

Link to comment
Share on other sites

On 4.11.2016 at 9:36 PM, junkew said:

1. Installed Microsoft EDGE webdriver

2. run it  Listening on http://localhost:17556/

3. Validating it by GET: 
http://localhost:17556/status

1. Done.
2. How to ?
3. not working.

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

  • 1 month later...

Some documentation:

https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/dev-guide/tools/webdriver/

https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/webdriver-commands/

https://blogs.windows.com/msedgedev/2015/07/23/bringing-automated-testing-to-microsoft-edge-through-webdriver/#KolXPHQuI7LhwvPe.97

https://www.w3.org/TR/webdriver/

EDIT:

And little modified @junkew example:

;~ https://www.autoitscript.com/forum/topic/185401-restwhich-udf-to-use-webdriver-of-edge/?do=findComment&comment=1331629

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Initialize a COM error handler

_Example()
Func _Example()
    Local $URL = "http://localhost:5555/"
    Local $restCMD = "/status"
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

    #cs
        GET /status HTTP/1.1
        Host: localhost:17556
        Cache-Control: no-cache
    #ce

    $oHTTP.Open("GET", $URL & $restCMD, True)
;~  $oHTTP.setRequestHeader ("Cache-Control:","no-cache")
;~  $oHTTP.SetRequestHeader("Content-Type", "xml")
    $oHTTP.Send("")

    ; wait until response is ready
    $oHTTP.WaitForResponse(5)

    Local $iStatusCode = $oHTTP.Status
    Local $sResponseText = $oHTTP.ResponseText

;~  $objHTTP.open ("POST", "url", False)
;~  $objHTTP.setRequestHeader ("Content-Type", "text/xml;charset=UTF-8")
;~  $objHTTP.setRequestHeader("Content-Length",StringLen($YourXMLText))
;~  $objHTTP.setRequestHeader("Connection","If is needed")
;~  $objHTTP.setRequestHeader("User-Agent","If is needed")
;~  $objHTTP.send ($YourXMLText)

    ConsoleWrite('$iStatusCode = ' & $iStatusCode & @CRLF)
    ConsoleWrite('$sResponseText = ' & $sResponseText & @CRLF)

    If $iStatusCode = 200 Then
        ;Process the response $sResponseText
        ;ConsoleWrite(@CRLF & "Response" & @CRLF & $sResponseText & @CRLF)
    Else
        MsgBox(16, "Error " & $iStatusCode, $sResponseText, 7)
    EndIf

EndFunc   ;==>_Example

; This is my custom defined error handler
Func MyErrFunc()
    MsgBox(0, "AutoItCOM Test", _
            "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
EndFunc   ;==>MyErrFunc

 

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

And microsoft seems to wrap the windows controls (win32 and univerals app controls) also in a webdriver concept (I assume using UI Automation framework)

https://github.com/Microsoft/WinAppDriver

This can be overkill but on the other hand could be nice to remotely control a computer by running te winappdriver in a citrix or any centralized server way (offcourse http reachable then).

Edited by junkew
Link to comment
Share on other sites

:D

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

  • 5 months later...

Last few weeks I investigated a little more on Webdriver and selenium concepts. (from within AutoIt and VBA and probably near future HP LeanFT)

Althought it works nice when you remotely have to talk to different machines
I also compared with UIAutomation (UIA.UDF) and different browsers like Opera, Edge, IE, Chrome, Firefox
In general with UI automation you can reach all standard controls (as used by enduser) easier.
So for testautomation on machines you are in control of (mainly citrix testfarms on Windows) its easier to do stuff with UIA wrappers. When dealing with browsers remotely on non windows platforms its easier to use webdriver.
When you want to reach all details of DOM then webdriver is easier then getting information thru adrressbar (With trick on typing javascript bookmarklets in the addressbar)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...