Jump to content

Recommended Posts

Posted (edited)

 

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
Posted

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:

  Reveal hidden contents

 

Posted

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

 

Posted
  On 11/4/2016 at 8: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

Expand  

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:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 1 month later...
Posted (edited)

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

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
Posted

: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:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 5 months later...
Posted

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)

 

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
  • Recently Browsing   0 members

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