junkew

RESTwhich UDF to use webdriver of EDGE

5 posts in this topic

#1 ·  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

Share this post


Link to post
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.

Share this post


Link to post
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

 

2 people like this

Share this post


Link to post
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.


NEW:     ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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 *

"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."

 

Share this post


Link to post
Share on other sites

2. run the executable it will start commandprompt and tell you the ip and port number

Share this post


Link to post
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