junkew Posted November 4, 2016 Share Posted November 4, 2016 (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 November 4, 2016 by junkew mLipok 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
orbs Posted November 4, 2016 Share Posted November 4, 2016 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 More sharing options...
junkew Posted November 4, 2016 Author Share Posted November 4, 2016 thx this works like a charm expandcollapse popup$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 Muhammad_Awais_Sharif, mLipok and AutoBert 3 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
mLipok Posted November 6, 2016 Share Posted November 6, 2016 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 Code * for 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 API * ErrorLog.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 TaskScheduler * IE 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 stuff * OnHungApp handler * Avoid "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" , 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 More sharing options...
junkew Posted November 7, 2016 Author Share Posted November 7, 2016 2. run the executable it will start commandprompt and tell you the ip and port number FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
mLipok Posted December 29, 2016 Share Posted December 29, 2016 (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: expandcollapse popup;~ 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 December 30, 2016 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 Code * for 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 API * ErrorLog.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 TaskScheduler * IE 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 stuff * OnHungApp handler * Avoid "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" , 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 More sharing options...
junkew Posted December 30, 2016 Author Share Posted December 30, 2016 (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 December 30, 2016 by junkew mLipok 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
mLipok Posted December 30, 2016 Share Posted December 30, 2016 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 Code * for 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 API * ErrorLog.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 TaskScheduler * IE 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 stuff * OnHungApp handler * Avoid "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" , 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 More sharing options...
junkew Posted June 22, 2017 Author Share Posted June 22, 2017 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) Leads me to the conclusion I should improve the UIAWrappers over time to include webdriver logic https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/ FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now