#include #include $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_Setings ; Description ...: Setting for startup like chrome or ff and port to be runningon ; Syntax ........: Browser_Setings($driver_port, $driver_location) ; Parameters ....: $driver_port - Port open on driver default is 9515 for chrome and 4444 for mozilla ff ; $driver_location - Path Along with command parameters(if required) to driver(ie chromedriver.exe for chrome and geckodriver.exe for mozilla firefox) ; Return values .: Process id for driver running ; Author ........: Vinit Furia ; Modified ......:09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_Setings($driver_port, $driver_location) Global $port = $driver_port Local $pid = Run($driver_location,"",@SW_HIDE) Global $baseurl = "http://127.0.0.1:" & $port Return ($pid) EndFunc ;==>Browser_Setings ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_create_session ; Description ...:Creates a new session for browser ; Syntax ........: Browser_create_session() ; Parameters ....: ; Return values .: Sessionid to be used in all further requests can be said as handle to chrome window ; Author ........: Vinit furia ; Modified ......: 09/07/2017 ; Remarks .......: Desired Capabilities can be changed as per requirements in main udf itself ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_create_session() Local $retriveddata = _Browserpost($baseurl & "/session", '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"browserName":"firefox","acceptInsecureCerts":true}}') $session = StringRegExp($retriveddata, '"sessionId":"(.*?)",', 3) Return $session[0] EndFunc ;==>Browser_create_session ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_openurl ; Description ...:Navigate to url ; Syntax ........: Browser_openurl($session, $url) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $url - Url to navigate to ; Return values .: no check values are currently enabled ; Author ........: Vinit Furia ; Modified ......:09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_openurl($session, $url) _Browserpost($baseurl & "/session/" & $session & "/url", '{"url":"' & $url & '"}') EndFunc ;==>Browser_openurl Func _BrowserGET($url) $oHTTP.Open("GET", $url, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=utf-8") $oHTTP.Send() ;~ MsgBox(0, 0, $oHTTP.Responsetext) Filewrite("log.txt",$oHTTP.responsetext&@CRLF&@CRLF) Return $oHTTP.responsetext EndFunc ;==>_BrowserGET Func _Browserpost($url, $postdata) $oHTTP.Open("POST", $url, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=utf-8") $oHTTP.Send($postdata) ;~ MsgBox(0, 0, $oHTTP.Responsetext) Filewrite("log.txt",$oHTTP.responsetext&@CRLF&@CRLF) Return $oHTTP.responsetext EndFunc ;==>_Browserpost Func browser_status($session) $status = _Browserpost($baseurl & "/session/" & $session & "/execute/sync", '{"script":"return document.readyState","args":[]}') Return $status EndFunc ;==>browser_status Func browser_Script($session,$script) $status = _Browserpost($baseurl & "/session/" & $session & "/execute/sync", '{"script":"'&$script&'","args":[]}') Return $status EndFunc ;==>browser_status ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_getelement ; Description ...:Get Element id/handle for any element ; Syntax ........: browser_getelement($session, $Attribute_type, $attributevalue) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $Attribute_type - Types currently available are (id,css selector,link text,partial link text,tag name,xpath)(all Are Case Sensitive ; $attributevalue - value to find element based on attribute_type ; Return values .: Element id to be used for further functions ; Author ........: Vinit Furia ; Modified ......:09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_getelement($session, $Attribute_type, $attributevalue) $handle = _Browserpost($baseurl & "/session/" & $session & "/element", '{"using":"' & $Attribute_type & '","value":"' & $attributevalue & '"}') Local $json = _JSONDecode($handle) Local $elementid = _JSONGet($json, "value") msgbox(0,0,$elementid[1][1]) Return $elementid[1][1] EndFunc ;==>browser_getelement ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_setelement ; Description ...:Sets Value for specififed element ; Syntax ........: browser_setelement($session, $elementid, $value) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $elementid - elementid genereated from browser_getelement() ; $value - Value to change in element as specified above ; Return values .: None ; Author ........: Vinit Furia ; Modified ......:09/07/2017 ; Remarks .......:I didnt had time to implement any checking for tracing errors m sorry for this ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_setelement($session, $elementid, $value) ;~ _Browserpost($baseurl & "/session/" & $session & "/element/" & $elementid & "/value", '{"value":["' & $value & '"]}') _Browserpost($baseurl & "/session/" & $session & "/element/" & $elementid & "/value", '{"text":"'&$value&'","value":["' & $value & '"]}') EndFunc ;==>browser_setelement ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_getsource ; Description ...: Fetches Html Source For Page ; Syntax ........: Browser_getsource($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: source code or say html content ; Author ........: Vinit Furia ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_getsource($session) $source = _BrowserGET($baseurl & "/session/" & $session & "/source") Local $json = _JSONDecode($source) Local $source = _JSONGet($json, "value") Return $source EndFunc ;==>Browser_getsource ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_getcookie ; Description ...: Gets All Cookies ; Syntax ........: Browser_getcookie($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: A json string getting all cookie and other information,you can parse as per your requirement ; Author ........: Vinit Furia ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_getcookie($session) $source = _BrowserGET($baseurl & "/session/" & $session & "/cookie") Return $source EndFunc ;==>Browser_getcookie ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_getscreenshot ; Description ...: Gets Screenshot of page ; Syntax ........: browser_getscreenshot($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: a blob of containing screenshot data.Directly Save it to file with extension to jpg ; Author ........: Vinit Furia ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_getscreenshot($session) $source = _BrowserGET($baseurl & "/session/" & $session & "/screenshot") Local $json = _JSONDecode($source) $source = _JSONGet($json, "value") Return $source EndFunc ;==>browser_getscreenshot ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_actions_click ; Description ...: Basic Click action ; Syntax ........: browser_actions_click($session, $elementid) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $elementid - elementid genereated from browser_getelement() ; Return values .: None ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: Couldnt Implement check functions ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_actions_click($session, $elementid) _Browserpost($baseurl & "/session/" & $session & "/element/" & $elementid & "/click", "{}") EndFunc ;==>browser_actions_click ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_action_back ; Description ...: ; Syntax ........: Browser_action_back($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: None ; Author ........: Vinit Furia ; Modified ......:09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_action_back($session) _Browserpost($baseurl & "/session/" & $session & "/back", "{}") EndFunc ;==>Browser_action_back ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_action_forward ; Description ...: Basic Forward Function of browser ; Syntax ........: Browser_action_forward($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: None ; Author ........: Vinit Furia ; Modified ......:09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_action_forward($session) _Browserpost($baseurl & "/session/" & $session & "/forward", "{}") EndFunc ;==>Browser_action_forward ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_action_refresh ; Description ...: A Basic Refresh for page ; Syntax ........: Browser_action_refresh($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: None ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_action_refresh($session) _Browserpost($baseurl & "/session/" & $session & "/refresh", "{}") EndFunc ;==>Browser_action_refresh ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_get_currentUrl ; Description ...: Gets Currently opened url name ; Syntax ........: browser_get_currentUrl($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: Url opened ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_get_currentUrl($session) $source = _BrowserGET($baseurl & "/session/" & $session & "/url") $json = _JSONDecode($source) $result = _JSONGet($json, "value") Return $result EndFunc ;==>browser_get_currentUrl ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_get_title ; Description ...: Gets Title Of Window ; Syntax ........: browser_get_title($session) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; Return values .: Title of document ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_get_title($session) $source = _BrowserGET($baseurl & "/session/" & $session & "/title") $json = _JSONDecode($source) $result = _JSONGet($json, "value") Return $result EndFunc ;==>browser_get_title ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_get_Elementvalue ; Description ...: Fetches value of element based on element id ; Syntax ........: browser_get_Elementvalue($session, $elementid) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $elementid - elementid genereated from browser_getelement() ; Return values .: Value To Element ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_get_Elementvalue($session, $elementid) $source = _BrowserGET($baseurl & "/session/" & $session & "/element/" & $elementid & "/text") $json = _JSONDecode($source) $result = _JSONGet($json, "value") Return $result EndFunc ;==>browser_get_Elementvalue ; #FUNCTION# ==================================================================================================================== ; Name ..........: Browser_Setings_close ; Description ...: ; Syntax ........: Browser_Setings_close($pid) ; Parameters ....: $pid - Handle From browser Setting just to close driver ; Return values .: None ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func Browser_Setings_close($pid) ProcessClose($pid) EndFunc ;==>Browser_Setings_close ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_waitforurl ; Description ...: Wait Until Url isnt opened ; Syntax ........: browser_waitforurl($session, $url) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $url - url to wait for ; Return values .: None ; Author ........: Vinit Furia ; Modified ......: 09/07/2017 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_waitforurl($session, $url) Do Sleep(100) Until browser_get_currentUrl($session) = $url EndFunc ;==>browser_waitforurl ; #FUNCTION# ==================================================================================================================== ; Name ..........: browser_waitforTitle ; Description ...: ; Syntax ........: browser_waitforTitle($session, $Title) ; Parameters ....: $session - Sessionid genereated from Browser_create_session() ; $Title - Title text To Wait For ; Return values .: None ; Author ........: Vinit Furia ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func browser_waitforTitle($session, $Title) Do Sleep(100) Until browser_get_title($session) = $title EndFunc ;==>browser_waitforurl Func _JSONGet($json, $path, $seperator = ".") Local $seperatorPos, $current, $next, $l $seperatorPos = StringInStr($path, $seperator) If $seperatorPos > 0 Then $current = StringLeft($path, $seperatorPos - 1) $next = StringTrimLeft($path, $seperatorPos + StringLen($seperator) - 1) Else $current = $path $next = "" EndIf If _JSONIsObject($json) Then $l = UBound($json, 1) For $i = 0 To $l - 1 If $json[$i][0] == $current Then If $next == "" Then Return $json[$i][1] Else Return _JSONGet($json[$i][1], $next, $seperator) EndIf EndIf Next ElseIf IsArray($json) And UBound($json, 0) == 1 And UBound($json, 1) > $current Then If $next == "" Then Return $json[$current] Else Return _JSONGet($json[$current], $next, $seperator) EndIf EndIf Return $_JSONNull EndFunc ;==>_JSONGet